Passed
Pull Request — master (#161)
by Jan
04:20
created

tests.test_command_json_to_graph   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 188
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 160
dl 0
loc 188
rs 10
c 0
b 0
f 0
wmc 13

7 Functions

Rating   Name   Duplication   Size   Complexity  
B test_inquirer_choice_rule() 0 41 2
A test_command_json_to_graph_with_verbose() 0 25 2
A test_command_json_to_graph_is_tty() 0 23 2
A test_command_json_to_graph() 0 24 2
A test_bad_command_json_to_graph_with_verbose() 0 13 1
A test_bad_command_json_to_graph() 0 12 1
A test_command_parameter_all() 0 27 3
1
import subprocess
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
introduced by
import missing from __future__ import absolute_import
Loading history...
2
import os
3
import json
4
import pytest
5
import tempfile
0 ignored issues
show
Unused Code introduced by
The import tempfile seems to be unused.
Loading history...
introduced by
standard import "import tempfile" should be placed before "import pytest"
Loading history...
6
from readchar import key
7
8
import tests.any_test_help
9
10
11
@pytest.mark.usefixtures("remove_generated_reports_in_root")
12
def test_command_json_to_graph():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
13
    src = tests.any_test_help.get_random_dir_in_tmp() + '.json'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
14
    out = subprocess.check_output(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
15
                                   '-m',
16
                                   'oval_graph.command_line',
17
                                   'arf-to-json',
18
                                   'tests/test_data/ssg-fedora-ds-arf.xml',
19
                                   'xccdf_org.ssgproject.content_rule_package_abrt_removed'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
20
                                   ])
21
    with open(src, "w+") as f:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Coding Style Naming introduced by
Variable name "f" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
22
        f.writelines(out.decode('utf-8'))
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
23
    subprocess.check_call(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
24
                           '-m',
25
                           'oval_graph.command_line',
26
                           'json-to-graph',
27
                           '-o', '.',
28
                           src,
29
                           'xccdf_org.ssgproject.content_rule_package_abrt_removed'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
30
                           ], cwd='./')
31
    file_src = tests.any_test_help.find_files(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
32
        "graph-of-xccdf_org.ssgproject.content_rule_package_abrt_removed",
33
        '../')
34
    tests.any_test_help.compare_results_html(file_src[0])
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
35
36
37
@pytest.mark.usefixtures("remove_generated_reports_in_root")
38
def test_command_json_to_graph_with_verbose():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_command_json_to_graph_with_verbose" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
39
    src = tests.any_test_help.get_random_dir_in_tmp() + '.json'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
40
    out = subprocess.check_output(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
41
                                   '-m',
42
                                   'oval_graph.command_line',
43
                                   'arf-to-json',
44
                                   'tests/test_data/ssg-fedora-ds-arf.xml',
45
                                   'xccdf_org.ssgproject.content_rule_package_abrt_removed'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
46
                                   ])
47
    with open(src, "w+") as f:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Coding Style Naming introduced by
Variable name "f" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
48
        f.writelines(out.decode('utf-8'))
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
49
    out = subprocess.check_output(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
50
                                   '-m',
51
                                   'oval_graph.command_line',
52
                                   'json-to-graph',
53
                                   '-o', '.',
54
                                   '--verbose',
55
                                   src,
56
                                   'xccdf_org.ssgproject.content_rule_package_abrt_removed'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
57
                                   ],
58
                                  cwd='./',
59
                                  stderr=subprocess.STDOUT)
60
    src = out.decode('utf-8').split('\n')[-2]
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
61
    tests.any_test_help.compare_results_html('.' + src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
62
63
64
def test_command_json_to_graph_is_tty():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_command_json_to_graph_is_tty" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
65
    src = tests.any_test_help.get_random_dir_in_tmp() + '.json'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
66
    with open(src, 'w+')as output:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
67
        subprocess.check_call(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
68
                               '-m',
69
                               'oval_graph.command_line',
70
                               'arf-to-json',
71
                               'tests/test_data/ssg-fedora-ds-arf.xml',
72
                               'xccdf_org.ssgproject.content_rule_package_abrt_removed'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (87/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
73
                               ],
74
                              stdout=output)
75
    out_dir = tests.any_test_help.get_random_dir_in_tmp()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
76
    out = subprocess.check_output(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Unused Code introduced by
The variable out seems to be unused.
Loading history...
77
                                   '-m',
78
                                   'oval_graph.command_line',
79
                                   'json-to-graph',
80
                                   '--out',
81
                                   out_dir,
82
                                   src,
83
                                   'xccdf_org.ssgproject.content_rule_package_abrt_removed'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
84
                                   ])
85
    tests.any_test_help.compare_results_html(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
86
        os.path.join(out_dir, os.listdir(out_dir)[0]))
87
88
89
def test_inquirer_choice_rule():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
90
    pexpect = pytest.importorskip("pexpect")
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
91
    src = tests.any_test_help.get_random_dir_in_tmp() + '.json'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
92
    sut = pexpect.spawn('python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
93
                        ['-m',
94
                         'oval_graph.command_line',
95
                         'arf-to-json',
96
                         'tests/test_data/ssg-fedora-ds-arf.xml',
97
                         r'_package_\w+_removed'
98
                         ])
99
    sut.expect(r'\w+')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
100
    sut.send(key.DOWN)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
101
    sut.send(key.SPACE)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
102
    sut.send(key.UP)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
103
    sut.send(key.SPACE)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
104
    sut.send(key.ENTER)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
105
    sut.wait()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
106
    out = sut.readlines()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
107
108
    with open(src, "w+") as f:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Coding Style Naming introduced by
Variable name "f" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
109
        f.writelines(row.decode("utf-8") for row in out[20:])
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
110
    tests.any_test_help.compare_results_json(src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
111
112
    out_dir = tests.any_test_help.get_random_dir_in_tmp()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
113
    sut = pexpect.spawn('python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
114
                        ['-m',
115
                         'oval_graph.command_line',
116
                         'json-to-graph',
117
                         '-o',
118
                         out_dir,
119
                         src,
120
                         '.'
121
                         ])
122
    sut.expect(r'\w+')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
123
    sut.send(key.DOWN)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
124
    sut.send(key.SPACE)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
125
    sut.send(key.ENTER)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
126
    sut.wait()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
127
    assert len(os.listdir(out_dir)) == 1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
128
    assert ("xccdf_org.ssgproject.content_rule_package_abrt_removed"
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
129
            in os.listdir(out_dir)[0])
130
131
132
def test_command_parameter_all():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
133
    src = tests.any_test_help.get_random_dir_in_tmp() + '.json'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
134
    with open(src, 'w+')as output:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
135
        subprocess.check_call(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
136
                               '-m',
137
                               'oval_graph.command_line',
138
                               'arf-to-json',
139
                               '--all',
140
                               'tests/test_data/ssg-fedora-ds-arf.xml',
141
                               '.'
142
                               ],
143
                              stdout=output)
144
    with open(src, "r") as f:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Coding Style Naming introduced by
Variable name "f" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
145
        rules = json.load(f)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
146
    assert len(rules.keys()) == 184
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
147
    out_dir = tests.any_test_help.get_random_dir_in_tmp()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
148
    subprocess.check_call(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
149
                           '-m',
150
                           'oval_graph.command_line',
151
                           'json-to-graph',
152
                           src,
153
                           '.',
154
                           '--all',
155
                           '-o',
156
                           out_dir
157
                           ])
158
    assert len(os.listdir(out_dir)) == 184
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
159
160
161
def test_bad_command_json_to_graph_with_verbose():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_bad_command_json_to_graph_with_verbose" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
162
    out = subprocess.check_output(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
163
                                   '-m',
164
                                   'oval_graph.command_line',
165
                                   'json-to-graph',
166
                                   '-v',
167
                                   'tests/test_data/ssg-fedora-ds-arf.xml',
168
                                   '.'
169
                                   ],
170
                                  stderr=subprocess.STDOUT)
171
    out_string = out.decode('utf-8')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
172
    assert out_string.find("Traceback") > -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
173
    assert out_string.find("Error:") > -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
174
175
176
def test_bad_command_json_to_graph():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
177
    out = subprocess.check_output(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
178
                                   '-m',
179
                                   'oval_graph.command_line',
180
                                   'json-to-graph',
181
                                   'tests/test_data/ssg-fedora-ds-arf.xml',
182
                                   '.'
183
                                   ],
184
                                  stderr=subprocess.STDOUT)
185
    out_string = out.decode('utf-8')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
186
    assert out_string.find("Traceback") == -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
187
    assert out_string.find("Error:") > -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
188