Passed
Pull Request — master (#203)
by Jan
04:05
created

tests_oval_graph.test_commands.test_command_bad_arf   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 51.47 %

Importance

Changes 0
Metric Value
wmc 4
eloc 55
dl 35
loc 68
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() 17 17 1
A test_bad_command_json_to_graph() 0 6 1
A test_command_with_bad_arf_file_with_verbose() 18 18 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
JSON_TO_GRAPH_COMMAND = ['python3',
6
                         '-m',
7
                         'oval_graph.command_line',
8
                         'json-to-graph',
9
                         'tests_oval_graph/global_test_data/ssg-fedora-ds-arf.xml',
10
                         '.'
11
                         ]
12
13
14 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...
15
def test_command_with_bad_arf_file_with_verbose(command_name):
16
    command = [
17
        'python3',
18
        '-m',
19
        'oval_graph.command_line',
20
        command_name,
21
        '-v',
22
        'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml',
23
        '.'
24
    ]
25
    out = subprocess.check_output(
26
        command,
27
        stderr=subprocess.STDOUT)
28
    out_string = out.decode('utf-8')
29
    assert out_string.find("Traceback") > -1
30
    assert out_string.find("Warning:") > -1
31
    assert out_string.find("Error:") > -1
32
33
34 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...
35
def test_command_with_bad_arf_file(command_name):
36
    command = [
37
        'python3',
38
        '-m',
39
        'oval_graph.command_line',
40
        command_name,
41
        'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml',
42
        '.'
43
    ]
44
    out = subprocess.check_output(
45
        command,
46
        stderr=subprocess.STDOUT)
47
    out_string = out.decode('utf-8')
48
    assert out_string.find("Traceback") == -1
49
    assert out_string.find("Warning:") > -1
50
    assert out_string.find("Error:") > -1
51
52
53
def test_bad_command_json_to_graph_with_verbose():
54
    command = [*JSON_TO_GRAPH_COMMAND, '-v']
55
    out = subprocess.check_output(command,
56
                                  stderr=subprocess.STDOUT)
57
    out_string = out.decode('utf-8')
58
    assert out_string.find("Traceback") > -1
59
    assert out_string.find("Error:") > -1
60
61
62
def test_bad_command_json_to_graph():
63
    out = subprocess.check_output(JSON_TO_GRAPH_COMMAND,
64
                                  stderr=subprocess.STDOUT)
65
    out_string = out.decode('utf-8')
66
    assert out_string.find("Traceback") == -1
67
    assert out_string.find("Error:") > -1
68