MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / check_yaml_scan

Function check_yaml_scan

tests/formattedcode/test_output_yaml.py:80–122  ·  view source on GitHub ↗

Check the scan `result_file` YAML results against the `expected_file` expected YAML results. If `regen` is True the expected_file WILL BE overwritten with the new scan results from `results_file`. This is convenient for updating tests expectations. But use with caution.

(
    expected_file,
    result_file,
    regen=REGEN_TEST_FIXTURES,
    remove_file_date=True,
    check_headers=False,
    remove_uuid=True,
)

Source from the content-addressed store, hash-verified

78
79
80def check_yaml_scan(
81 expected_file,
82 result_file,
83 regen=REGEN_TEST_FIXTURES,
84 remove_file_date=True,
85 check_headers=False,
86 remove_uuid=True,
87):
88 """
89 Check the scan `result_file` YAML results against the `expected_file`
90 expected YAML results.
91
92 If `regen` is True the expected_file WILL BE overwritten with the new scan
93 results from `results_file`. This is convenient for updating tests
94 expectations. But use with caution.
95 """
96 results = load_yaml_results(
97 location=result_file,
98 remove_file_date=remove_file_date,
99 ) or {}
100 if remove_uuid:
101 results = remove_uuid_from_scan(results)
102
103 if regen:
104 with open(expected_file, 'w') as reg:
105 reg.write(saneyaml.dump(results))
106
107 expected = load_yaml_results(
108 location=expected_file,
109 remove_file_date=remove_file_date,
110 )
111 if remove_uuid:
112 expected = remove_uuid_from_scan(expected)
113
114 if not check_headers:
115 results.pop('headers', None)
116 expected.pop('headers', None)
117
118 # NOTE we redump the YAML as a string for a more efficient display of the
119 # failures comparison/diff
120 expected = saneyaml.dump(expected)
121 results = saneyaml.dump(results)
122 assert results == expected
123
124
125def load_yaml_results(location, remove_file_date=True):

Calls 5

remove_uuid_from_scanFunction · 0.90
load_yaml_resultsFunction · 0.85
writeMethod · 0.45
dumpMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected