|
4 | 4 |
|
5 | 5 | from copy import deepcopy
|
6 | 6 |
|
7 |
| -import pytest |
8 |
| -from pydantic import ValidationError |
9 |
| - |
10 | 7 | from opossum_lib.opossum_model import OpossumPackage, SourceInfo
|
11 | 8 | from opossum_lib.scancode.constants import SCANCODE_SOURCE_NAME
|
12 | 9 | from opossum_lib.scancode.model import (
|
13 | 10 | Copyright,
|
14 |
| - File, |
15 | 11 | FileBasedLicenseDetection,
|
16 | 12 | FileType,
|
17 | 13 | Match,
|
18 |
| - ScanCodeData, |
19 | 14 | )
|
20 | 15 | from opossum_lib.scancode.resource_tree import (
|
21 |
| - ScanCodeFileTree, |
22 | 16 | get_attribution_info,
|
23 |
| - scancode_to_file_tree, |
24 | 17 | )
|
25 | 18 | from tests.test_scancode.model_helpers import _create_file
|
26 | 19 |
|
27 | 20 |
|
28 |
| -class TestRevalidate: |
29 |
| - def test_successfully_revalidate_valid_file_tree(self) -> None: |
30 |
| - dummy_file = _create_file("A", FileType.FILE) |
31 |
| - valid_structure = ScanCodeFileTree( |
32 |
| - file=dummy_file, |
33 |
| - children={ |
34 |
| - "A": ScanCodeFileTree(file=dummy_file), |
35 |
| - "B": ScanCodeFileTree( |
36 |
| - file=dummy_file, children={"C": ScanCodeFileTree(file=dummy_file)} |
37 |
| - ), |
38 |
| - }, |
39 |
| - ) |
40 |
| - valid_structure.revalidate() |
41 |
| - |
42 |
| - def test_fail_to_revalidate_file_tree_invalid_at_toplevel(self) -> None: |
43 |
| - dummy_file = _create_file("A", FileType.FILE) |
44 |
| - invalid_structure = ScanCodeFileTree.model_construct( |
45 |
| - children={ |
46 |
| - "A": ScanCodeFileTree(file=dummy_file), |
47 |
| - "B": ScanCodeFileTree( |
48 |
| - file=dummy_file, children={"C": ScanCodeFileTree(file=dummy_file)} |
49 |
| - ), |
50 |
| - }, |
51 |
| - file=None, # type: ignore |
52 |
| - ) |
53 |
| - with pytest.raises(ValidationError): |
54 |
| - invalid_structure.revalidate() |
55 |
| - |
56 |
| - def test_fail_to_revalidate_file_tree_invalid_only_at_lower_level(self) -> None: |
57 |
| - dummy_file = _create_file("A", FileType.FILE) |
58 |
| - invalid_structure = ScanCodeFileTree( |
59 |
| - file=dummy_file, |
60 |
| - children={ |
61 |
| - "A": ScanCodeFileTree(file=dummy_file), |
62 |
| - "B": ScanCodeFileTree( |
63 |
| - file=dummy_file, |
64 |
| - children={"C": ScanCodeFileTree.model_construct(None)}, # type: ignore |
65 |
| - ), |
66 |
| - }, |
67 |
| - ) |
68 |
| - with pytest.raises(ValidationError): |
69 |
| - invalid_structure.revalidate() |
70 |
| - |
71 |
| - |
72 |
| -def test_scancode_to_resource_tree_produces_expected_result() -> None: |
73 |
| - files = _create_reference_scancode_files() |
74 |
| - scancode_data = ScanCodeData( |
75 |
| - headers=[], packages=[], dependencies=[], license_detections=[], files=files |
76 |
| - ) |
77 |
| - |
78 |
| - tree = scancode_to_file_tree(scancode_data) |
79 |
| - reference = _create_reference_node_structure() |
80 |
| - |
81 |
| - assert tree == reference |
82 |
| - |
83 |
| - |
84 | 21 | def test_get_attribution_info_directory() -> None:
|
85 | 22 | folder = _create_file("A", FileType.DIRECTORY)
|
86 | 23 | assert get_attribution_info(folder) == []
|
@@ -159,29 +96,3 @@ def test_get_attribution_info_file_multiple() -> None:
|
159 | 96 | attribution_confidence=50,
|
160 | 97 | )
|
161 | 98 | assert set(attributions) == {expected1, expected2}
|
162 |
| - |
163 |
| - |
164 |
| -def _create_reference_scancode_files() -> list[File]: |
165 |
| - return [ |
166 |
| - _create_file("A", FileType.DIRECTORY), |
167 |
| - _create_file("A/B", FileType.DIRECTORY), |
168 |
| - _create_file("A/file1", FileType.FILE), |
169 |
| - _create_file("A/file2.txt", FileType.FILE), |
170 |
| - _create_file("A/B/file3", FileType.FILE), |
171 |
| - ] |
172 |
| - |
173 |
| - |
174 |
| -def _create_reference_node_structure() -> ScanCodeFileTree: |
175 |
| - folder, subfolder, file1, file2, file3 = _create_reference_scancode_files() |
176 |
| - inner = ScanCodeFileTree( |
177 |
| - file=subfolder, children={"file3": ScanCodeFileTree(file=file3)} |
178 |
| - ) |
179 |
| - reference = ScanCodeFileTree( |
180 |
| - file=folder, |
181 |
| - children={ |
182 |
| - "B": inner, |
183 |
| - "file1": ScanCodeFileTree(file=file1), |
184 |
| - "file2.txt": ScanCodeFileTree(file=file2), |
185 |
| - }, |
186 |
| - ) |
187 |
| - return reference |
0 commit comments