tests_oval_graph.test_commands.test_command_arf_to_json   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 54
dl 0
loc 73
rs 10
c 0
b 0
f 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A test_command_parameter_all() 0 11 2
A test_command_with_parameter_out() 0 17 2
A test_command_arf_to_json() 0 6 2
A run_commad_and_save_output_to_file() 0 5 2
A test_command_arf_to_json_is_tty() 0 3 1
A test_command_parameter_all_and_show_failed_rules() 0 12 2
1
import json
2
import subprocess
3
import time
4
5
from ..test_tools import TestTools
6
from .command_constants import ARF_TO_JSON, COMMAND_START, TEST_ARF_XML_PATH
7
8
9
def run_commad_and_save_output_to_file(parameters):
10
    path = str(TestTools.get_random_path_in_tmp()) + '.json'
11
    with open(path, 'w+', encoding="utf-8") as output:
12
        subprocess.check_call(parameters, stdout=output)
13
    return path
14
15
16
def test_command_arf_to_json():
17
    path = str(TestTools.get_random_path_in_tmp()) + '.json'
18
    out = subprocess.check_output(ARF_TO_JSON)
19
    with open(path, "w+", encoding="utf-8") as data:
20
        data.writelines(out.decode('utf-8'))
21
    TestTools.compare_results_json(path)
22
23
24
def test_command_arf_to_json_is_tty():
25
    src = run_commad_and_save_output_to_file(ARF_TO_JSON)
26
    TestTools.compare_results_json(src)
27
28
29
def test_command_parameter_all():
30
    command = [*COMMAND_START,
31
               "arf-to-json",
32
               "--all",
33
               TEST_ARF_XML_PATH,
34
               ".",
35
               ]
36
    src = run_commad_and_save_output_to_file(command)
37
    with open(src, "r", encoding="utf-8") as data:
38
        rules = json.load(data)
39
    assert len(rules.keys()) == 184
40
41
42
def test_command_parameter_all_and_show_failed_rules():
43
    command = [*COMMAND_START,
44
               'arf-to-json',
45
               '--all',
46
               '--show-failed-rules',
47
               TEST_ARF_XML_PATH,
48
               r'_package_\w+_removed'
49
               ]
50
    src = run_commad_and_save_output_to_file(command)
51
    with open(src, "r", encoding="utf-8") as data:
52
        rules = json.load(data)
53
    assert len(rules.keys()) == 1
54
55
56
def test_command_with_parameter_out():
57
    command = [*COMMAND_START,
58
               'arf-to-json',
59
               '--all',
60
               TEST_ARF_XML_PATH,
61
               r'_package_\w+_removed'
62
               ]
63
    src = run_commad_and_save_output_to_file(command)
64
65
    time.sleep(5)
66
67
    command.append('-o' + src)
68
    subprocess.check_call(command)
69
70
    with open(src, "r", encoding="utf-8") as data:
71
        rules = json.load(data)
72
    assert len(rules.keys()) == 4
73