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

test_command_arf_to_json   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 133
dl 0
loc 159
rs 10
c 0
b 0
f 0
wmc 15

9 Methods

Rating   Name   Duplication   Size   Complexity  
A tests.test_command_arf_to_json.test_command_parameter_all_and_show_failed_rules() 0 15 2
A tests.test_command_arf_to_json.test_inquirer_choice_rule() 0 22 2
A tests.test_command_arf_to_json.test_bad_command_arf_to_json() 0 14 1
A tests.test_command_arf_to_json.test_command_arf_to_json() 0 12 2
A tests.test_command_arf_to_json.test_bad_command_arf_to_json_with_verbose() 0 15 1
A tests.test_command_arf_to_json.run_commad_and_save_output_to_file() 0 5 2
A tests.test_command_arf_to_json.test_command_with_parameter_out() 0 24 2
A tests.test_command_arf_to_json.test_command_parameter_all() 0 14 2
A tests.test_command_arf_to_json.test_command_arf_to_json_is_tty() 0 11 1
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
0 ignored issues
show
Unused Code introduced by
The import os seems to be unused.
Loading history...
3
import time
4
import json
5
import pytest
6
from readchar import key
7
8
import tests.any_test_help
9
10
11
def run_commad_and_save_output_to_file(parameters):
0 ignored issues
show
Coding Style Naming introduced by
Function name "run_commad_and_save_output_to_file" 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...
12
    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...
13
    with open(src, 'w+') as output:
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
14
        subprocess.check_call(parameters, stdout=output)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
15
    return src
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
16
17
18
def test_command_arf_to_json():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
19
    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...
20
    out = subprocess.check_output(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
21
                                   '-m',
22
                                   'oval_graph.command_line',
23
                                   'arf-to-json',
24
                                   'tests/test_data/ssg-fedora-ds-arf.xml',
25
                                   '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...
26
                                   ])
27
    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...
28
        f.writelines(out.decode('utf-8'))
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
29
    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...
30
31
32
def test_command_arf_to_json_is_tty():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
33
    src = run_commad_and_save_output_to_file(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
34
        [
35
            'python3',
36
            '-m',
37
            'oval_graph.command_line',
38
            'arf-to-json',
39
            'tests/test_data/ssg-fedora-ds-arf.xml',
40
            'xccdf_org.ssgproject.content_rule_package_abrt_removed'
41
        ])
42
    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...
43
44
45
def test_inquirer_choice_rule():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
46
    pexpect = pytest.importorskip("pexpect")
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
47
    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...
48
    sut = pexpect.spawn('python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
49
                        ['-m',
50
                         'oval_graph.command_line',
51
                         'arf-to-json',
52
                         'tests/test_data/ssg-fedora-ds-arf.xml',
53
                         r'_package_\w+_removed'
54
                         ])
55
    sut.expect(r'\w+')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
56
    sut.send(key.DOWN)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
57
    sut.send(key.SPACE)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
58
    sut.send(key.SPACE)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
59
    sut.send(key.UP)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
60
    sut.send(key.SPACE)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
61
    sut.send(key.ENTER)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
62
    sut.wait()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
63
    out = sut.readlines()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
64
    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...
65
        f.writelines(row.decode("utf-8") for row in out[24:])
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
66
    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...
67
68
69
def test_command_parameter_all():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
70
    src = run_commad_and_save_output_to_file(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
71
        [
72
            'python3',
73
            '-m',
74
            'oval_graph.command_line',
75
            'arf-to-json',
76
            '--all',
77
            'tests/test_data/ssg-fedora-ds-arf.xml',
78
            '.'
79
        ])
80
    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...
81
        rules = json.load(f)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
82
    assert len(rules.keys()) == 184
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
83
84
85
def test_command_parameter_all_and_show_failed_rules():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_command_parameter_all_and_show_failed_rules" 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...
86
    src = run_commad_and_save_output_to_file(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
87
        [
88
            'python3',
89
            '-m',
90
            'oval_graph.command_line',
91
            'arf-to-json',
92
            '--all',
93
            '--show-failed-rules',
94
            'tests/test_data/ssg-fedora-ds-arf.xml',
95
            r'_package_\w+_removed'
96
        ])
97
    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...
98
        rules = json.load(f)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
99
    assert len(rules.keys()) == 1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
100
101
102
def test_command_with_parameter_out():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
103
    src = run_commad_and_save_output_to_file(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
104
        [
105
            'python3',
106
            '-m',
107
            'oval_graph.command_line',
108
            'arf-to-json',
109
            '--all',
110
            'tests/test_data/ssg-fedora-ds-arf.xml',
111
            r'_package_\w+_removed'
112
        ])
113
    time.sleep(5)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
114
    subprocess.check_call(['python3',
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
115
                           '-m',
116
                           'oval_graph.command_line',
117
                           'arf-to-json',
118
                           '--all',
119
                           'tests/test_data/ssg-fedora-ds-arf.xml',
120
                           r'_package_\w+_removed',
121
                           '-o' + src
122
                           ])
123
    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...
124
        rules = json.load(f)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
125
    assert len(rules.keys()) == 4
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
126
127
128
def test_bad_command_arf_to_json_with_verbose():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_bad_command_arf_to_json_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...
129
    out = subprocess.check_output(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
130
        [
131
            'python3',
132
            '-m',
133
            'oval_graph.command_line',
134
            'arf-to-json',
135
            '-v',
136
            'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (92/80).

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

Loading history...
137
            '.'],
138
        stderr=subprocess.STDOUT)
139
    out_string = out.decode('utf-8')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
140
    assert out_string.find("Traceback") > -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
141
    assert out_string.find("Warning:") > -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
142
    assert out_string.find("Error:") > -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
143
144
145
def test_bad_command_arf_to_json():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
146
    out = subprocess.check_output(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
147
        [
148
            'python3',
149
            '-m',
150
            'oval_graph.command_line',
151
            'arf-to-graph',
152
            'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (92/80).

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

Loading history...
153
            '.'],
154
        stderr=subprocess.STDOUT)
155
    out_string = out.decode('utf-8')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Unused Code introduced by
The variable out_string seems to be unused.
Loading history...
156
    assert out.decode('utf-8').find("Traceback") == -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
157
    assert out.decode('utf-8').find("Warning:") > -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
158
    assert out.decode('utf-8').find("Error:") > -1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
159