|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from spdx.document_utils import get_contained_spdx_element_ids, get_contained_spdx_elements, get_element_from_spdx_id |
9 | | -from tests.spdx.fixtures import document_fixture, file_fixture, package_fixture, snippet_fixture |
| 8 | +from spdx.document_utils import ( |
| 9 | + create_document_without_duplicates, |
| 10 | + create_list_without_duplicates, |
| 11 | + get_contained_spdx_element_ids, |
| 12 | + get_contained_spdx_elements, |
| 13 | + get_element_from_spdx_id, |
| 14 | +) |
| 15 | +from spdx.model.file import FileType |
| 16 | +from spdx.model.spdx_no_assertion import SpdxNoAssertion |
| 17 | +from spdx.model.spdx_none import SpdxNone |
| 18 | +from tests.spdx.fixtures import ( |
| 19 | + actor_fixture, |
| 20 | + checksum_fixture, |
| 21 | + creation_info_fixture, |
| 22 | + document_fixture, |
| 23 | + external_document_ref_fixture, |
| 24 | + external_package_ref_fixture, |
| 25 | + extracted_licensing_info_fixture, |
| 26 | + file_fixture, |
| 27 | + package_fixture, |
| 28 | + snippet_fixture, |
| 29 | +) |
10 | 30 |
|
11 | 31 |
|
12 | 32 | @pytest.fixture |
@@ -34,3 +54,74 @@ def test_get_contained_spdx_elements(variables): |
34 | 54 | assert contained_elements[package.spdx_id] == package |
35 | 55 | assert contained_elements[file.spdx_id] == file |
36 | 56 | assert contained_elements[snippet.spdx_id] == snippet |
| 57 | + |
| 58 | + |
| 59 | +def test_create_list_without_duplicates(): |
| 60 | + list_with_duplicates = [1, 2, 3, 5, 1, 67, 9, 67] |
| 61 | + |
| 62 | + list_without_duplicates = create_list_without_duplicates(list_with_duplicates) |
| 63 | + |
| 64 | + assert list_without_duplicates == [1, 2, 3, 5, 67, 9] |
| 65 | + |
| 66 | + |
| 67 | +def test_create_document_without_duplicates(): |
| 68 | + document = document_fixture( |
| 69 | + creation_info=creation_info_fixture( |
| 70 | + creators=[actor_fixture(name="creatorName"), actor_fixture(name="creatorName")], |
| 71 | + external_document_refs=[external_document_ref_fixture(), external_document_ref_fixture()], |
| 72 | + ), |
| 73 | + packages=[ |
| 74 | + package_fixture( |
| 75 | + checksums=[checksum_fixture(), checksum_fixture()], |
| 76 | + license_info_from_files=[SpdxNoAssertion(), SpdxNoAssertion()], |
| 77 | + external_references=[external_package_ref_fixture(), external_package_ref_fixture()], |
| 78 | + attribution_texts=["duplicated text", "duplicated text"], |
| 79 | + ) |
| 80 | + ], |
| 81 | + files=[ |
| 82 | + file_fixture( |
| 83 | + checksums=[checksum_fixture(), checksum_fixture()], |
| 84 | + file_types=[FileType.TEXT, FileType.TEXT], |
| 85 | + license_info_in_file=[SpdxNoAssertion(), SpdxNoAssertion()], |
| 86 | + contributors=["duplicated contributor", "duplicated contributor"], |
| 87 | + attribution_texts=["duplicated text", "duplicated text"], |
| 88 | + ) |
| 89 | + ], |
| 90 | + snippets=[ |
| 91 | + snippet_fixture( |
| 92 | + license_info_in_snippet=[SpdxNone(), SpdxNone()], |
| 93 | + attribution_texts=["duplicated text", "duplicated text"], |
| 94 | + ) |
| 95 | + ], |
| 96 | + extracted_licensing_info=[ |
| 97 | + extracted_licensing_info_fixture(cross_references=["duplicated reference", "duplicated reference"]) |
| 98 | + ], |
| 99 | + ) |
| 100 | + expected_document = document_fixture( |
| 101 | + creation_info=creation_info_fixture( |
| 102 | + creators=[actor_fixture(name="creatorName")], external_document_refs=[external_document_ref_fixture()] |
| 103 | + ), |
| 104 | + packages=[ |
| 105 | + package_fixture( |
| 106 | + checksums=[checksum_fixture()], |
| 107 | + license_info_from_files=[SpdxNoAssertion()], |
| 108 | + external_references=[external_package_ref_fixture()], |
| 109 | + attribution_texts=["duplicated text"], |
| 110 | + ) |
| 111 | + ], |
| 112 | + files=[ |
| 113 | + file_fixture( |
| 114 | + checksums=[checksum_fixture()], |
| 115 | + file_types=[FileType.TEXT], |
| 116 | + license_info_in_file=[SpdxNoAssertion()], |
| 117 | + contributors=["duplicated contributor"], |
| 118 | + attribution_texts=["duplicated text"], |
| 119 | + ) |
| 120 | + ], |
| 121 | + snippets=[snippet_fixture(license_info_in_snippet=[SpdxNone()], attribution_texts=["duplicated text"])], |
| 122 | + extracted_licensing_info=[extracted_licensing_info_fixture(cross_references=["duplicated reference"])], |
| 123 | + ) |
| 124 | + |
| 125 | + document_without_duplicates = create_document_without_duplicates(document) |
| 126 | + |
| 127 | + assert document_without_duplicates == expected_document |
0 commit comments