tests_oval_graph.test_commands.test_command_arf_to_graph   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 58
dl 0
loc 74
rs 10
c 0
b 0
f 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A test_command_parameter_all_and_show_failed_rules() 0 13 1
A test_command_parameter_all() 0 12 1
A test_command_arf_to_graph_with_out_parameter() 0 4 1
A test_command_arf_to_graph_with_verbose() 0 11 1
A get_command_with_random_output_path() 0 5 1
A test_command_arf_to_graph() 0 8 1
1
import subprocess
2
from pathlib import Path
3
from re import search
4
5
import pytest
6
7
from ..test_tools import TestTools
8
from .command_constants import ARF_TO_GRAPH, COMMAND_START, TEST_ARF_XML_PATH
9
10
11
def get_command_with_random_output_path():
12
    path = TestTools.get_random_path_in_tmp()
13
    command = [*ARF_TO_GRAPH]
14
    command[command.index('.')] = str(path)
15
    return command, str(path)
16
17
18
@pytest.mark.usefixtures("remove_generated_reports_in_root")
19
def test_command_arf_to_graph():
20
    subprocess.check_call(ARF_TO_GRAPH,
21
                          cwd='./')
22
    file_src = TestTools.find_files(
23
        "graph-of-xccdf_org.ssgproject.content_rule_package_abrt_removed",
24
        "../")
25
    TestTools.compare_results_html(file_src[0])
26
27
28
@pytest.mark.usefixtures("remove_generated_reports_in_root")
29
def test_command_arf_to_graph_with_verbose():
30
    command = [*ARF_TO_GRAPH, '--verbose']
31
    out = subprocess.check_output(command,
32
                                  cwd='./',
33
                                  stderr=subprocess.STDOUT)
34
    # Reads path to file from verbose output
35
    src_regex = r"\"(.*?)\"$"
36
    src = search(src_regex, out.decode('utf-8')).group(1)
37
    file_src = Path(__file__).parent.parent.parent / src
38
    TestTools.compare_results_html(file_src)
39
40
41
def test_command_arf_to_graph_with_out_parameter():
42
    command, src = get_command_with_random_output_path()
43
    subprocess.check_call(command)
44
    TestTools.compare_results_html(src)
45
46
47
def test_command_parameter_all():
48
    path = TestTools.get_random_path_in_tmp()
49
    command = [*COMMAND_START,
50
               'arf-to-graph',
51
               '--all',
52
               '-o',
53
               str(path),
54
               TEST_ARF_XML_PATH,
55
               '.',
56
               ]
57
    subprocess.check_call(command)
58
    assert len(list(path.glob("**/*.html"))) == 184
59
60
61
def test_command_parameter_all_and_show_failed_rules():
62
    path = TestTools.get_random_path_in_tmp()
63
    command = [*COMMAND_START,
64
               'arf-to-graph',
65
               '--all',
66
               '--show-failed-rules',
67
               '-o',
68
               str(path),
69
               TEST_ARF_XML_PATH,
70
               r'_package_\w+_removed'
71
               ]
72
    subprocess.check_call(command)
73
    assert path.is_file()
74