diff --git a/src/spdx_tools/spdx/writer/tagvalue/tagvalue_writer.py b/src/spdx_tools/spdx/writer/tagvalue/tagvalue_writer.py index 6e8de2e94..51cd26504 100644 --- a/src/spdx_tools/spdx/writer/tagvalue/tagvalue_writer.py +++ b/src/spdx_tools/spdx/writer/tagvalue/tagvalue_writer.py @@ -73,11 +73,7 @@ def write_document(document: Document, text_output: TextIO): write_separator(text_output) if package.spdx_id in contained_files_by_package_id: for file in contained_files_by_package_id[package.spdx_id]: - if file.spdx_id in already_written_file_ids: - relationships_to_write.append( - Relationship(package.spdx_id, RelationshipType.CONTAINS, file.spdx_id) - ) - else: + if file.spdx_id not in already_written_file_ids: write_file(file, text_output) write_separator(text_output) if file.spdx_id in file_ids_with_contained_snippets: @@ -89,6 +85,8 @@ def write_document(document: Document, text_output: TextIO): ) already_written_file_ids.append(file.spdx_id) + relationships_to_write.append(Relationship(package.spdx_id, RelationshipType.CONTAINS, file.spdx_id)) + write_optional_heading(document.extracted_licensing_info, "## License Information\n", text_output) write_list_of_elements( document.extracted_licensing_info, write_extracted_licensing_info, text_output, with_separator=True diff --git a/tests/spdx/writer/tagvalue/test_tagvalue_writer.py b/tests/spdx/writer/tagvalue/test_tagvalue_writer.py index 487ee0dca..f6fc4f889 100644 --- a/tests/spdx/writer/tagvalue/test_tagvalue_writer.py +++ b/tests/spdx/writer/tagvalue/test_tagvalue_writer.py @@ -132,6 +132,8 @@ def test_correct_order_of_elements(): call("PackageDownloadLocation: \n"), call("FilesAnalyzed: true\n"), call("\n"), + call('## Relationships\n'), + call('Relationship: SPDXRef-Package-A CONTAINS SPDXRef-File-B\n'), call("\n"), ] ) @@ -215,6 +217,7 @@ def test_same_file_in_multiple_packages(): call("## Relationships\n"), call("Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package-A\n"), call("Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package-B\n"), + call("Relationship: SPDXRef-Package-A CONTAINS SPDXRef-File\n"), call("Relationship: SPDXRef-Package-B CONTAINS SPDXRef-File\n"), call("\n"), ]