Passed
Pull Request — master (#202)
by Jan
03:31
created

tests_oval_graph.test_commands.test_command_bad_arf   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 46.27 %

Importance

Changes 0
Metric Value
wmc 4
eloc 52
dl 31
loc 67
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_bad_command_json_to_graph_with_verbose() 0 7 1
A test_command_with_bad_arf_file() 15 15 1
A test_bad_command_json_to_graph() 0 6 1
A test_command_with_bad_arf_file_with_verbose() 16 16 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
import subprocess
2
3
import pytest
4
5
COMMAND_START = ['python3',
6
                 '-m',
7
                 'oval_graph.command_line'
8
                 ]
9
10
JSON_TO_GRAPH_COMMAND = [*COMMAND_START,
11
                         'json-to-graph',
12
                         'tests_oval_graph/global_test_data/ssg-fedora-ds-arf.xml',
13
                         '.'
14
                         ]
15
16
17 View Code Duplication
@pytest.mark.parametrize("command_name", ['arf-to-graph', 'arf-to-json'])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
18
def test_command_with_bad_arf_file_with_verbose(command_name):
19
    command = [
20
        *COMMAND_START,
21
        command_name,
22
        '-v',
23
        'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml',
24
        '.'
25
    ]
26
    out = subprocess.check_output(
27
        command,
28
        stderr=subprocess.STDOUT)
29
    out_string = out.decode('utf-8')
30
    assert out_string.find("Traceback") > -1
31
    assert out_string.find("Warning:") > -1
32
    assert out_string.find("Error:") > -1
33
34
35 View Code Duplication
@pytest.mark.parametrize("command_name", ['arf-to-graph', 'arf-to-json'])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
36
def test_command_with_bad_arf_file(command_name):
37
    command = [
38
        *COMMAND_START,
39
        command_name,
40
        'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml',
41
        '.'
42
    ]
43
    out = subprocess.check_output(
44
        command,
45
        stderr=subprocess.STDOUT)
46
    out_string = out.decode('utf-8')
47
    assert out_string.find("Traceback") == -1
48
    assert out_string.find("Warning:") > -1
49
    assert out_string.find("Error:") > -1
50
51
52
def test_bad_command_json_to_graph_with_verbose():
53
    command = [*JSON_TO_GRAPH_COMMAND, '-v']
54
    out = subprocess.check_output(command,
55
                                  stderr=subprocess.STDOUT)
56
    out_string = out.decode('utf-8')
57
    assert out_string.find("Traceback") > -1
58
    assert out_string.find("Error:") > -1
59
60
61
def test_bad_command_json_to_graph():
62
    out = subprocess.check_output(JSON_TO_GRAPH_COMMAND,
63
                                  stderr=subprocess.STDOUT)
64
    out_string = out.decode('utf-8')
65
    assert out_string.find("Traceback") == -1
66
    assert out_string.find("Error:") > -1
67