Passed
Push — master ( 8b9f7f...914492 )
by Marek
02:15
created

test_parse_affected.main()   B

Complexity

Conditions 6

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 22
nop 0
dl 0
loc 34
rs 8.4186
c 0
b 0
f 0
1
#!/usr/bin/env python
2
3
import os
4
import sys
5
6
import ssg.constants
7
import ssg.oval
8
import ssg.rules
9
import ssg.utils
10
import ssg.yaml
11
12
13
def main():
14
    """
15
    Walk through all known products in the ssg root specified in sys.argv[1],
16
    and ensure that all ovals in all rule directories are parsable under
17
    ssg.oval.parse_affected(...).
18
    """
19
20
    if len(sys.argv) != 2:
21
        print("Error! Must supply only path to root of ssg directory",
22
              file=sys.stderr)
23
        sys.exit(1)
24
25
    ssg_root = sys.argv[1]
26
27
    guide_dirs = set()
28
    for product in ssg.constants.product_directories:
29
        product_dir = os.path.join(ssg_root, product)
30
        product_yaml_path = os.path.join(product_dir, "product.yml")
31
        product_yaml = ssg.yaml.open_raw(product_yaml_path)
32
33
        guide_dir = os.path.join(product_dir, product_yaml['benchmark_root'])
34
        if guide_dir in guide_dirs:
35
            continue
36
37
        for rule_dir in ssg.rules.find_rule_dirs(guide_dir):
38
            for oval in ssg.rules.get_rule_dir_ovals(rule_dir):
39
                oval_contents = ssg.utils.read_file_list(oval)
40
                results = ssg.oval.parse_affected(oval_contents)
41
42
                assert len(results) == 3
43
                assert isinstance(results[0], int)
44
                assert isinstance(results[1], int)
45
46
        guide_dirs.add(guide_dir)
47
48
49
if __name__ == "__main__":
50
    main()
51