Repository: spdx/tools-python

Issue:
Tag-value writer: pacakges should precede contained files 
According to the [spec](https://spdx.github.io/spdx-spec/v2.3/composition-of-an-SPDX-document/#5.2.3):

> Files are assumed to be associated with the package information that immediately precedes it, if a package exists.

[The implemented logic](https://github.com/spdx/tools-python/blob/788e8d4aec940a3c2b2f16bd731564ee1a8da5d8/src/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py#L84) in the tag-value writer checks against strings and not `RelationshipType` which leads to output where contained files do not follow the related package. 

Comments:

Patch:
diff --git a/src/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py b/src/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py
index 4bf7c71..8468719 100644
--- a/src/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py
+++ b/src/spdx/writer/tagvalue/tagvalue_writer_helper_functions.py
@@ -14,7 +14,7 @@ from spdx.model.actor import Actor
 from spdx.model.file import File
 from license_expression import LicenseExpression
 from spdx.model.package import Package
-from spdx.model.relationship import Relationship
+from spdx.model.relationship import Relationship, RelationshipType
 from spdx.model.snippet import Snippet
 from spdx.model.spdx_no_assertion import SpdxNoAssertion
 from spdx.model.spdx_none import SpdxNone
@@ -81,19 +81,19 @@ def scan_relationships(relationships: List[Relationship], packages: List[Package
     files_by_spdx_id = {file.spdx_id: file for file in files}
     packages_spdx_ids = [package.spdx_id for package in packages]
     for relationship in relationships:
-        if relationship.relationship_type == "CONTAINS" and \
+        if relationship.relationship_type == RelationshipType.CONTAINS and \
             relationship.spdx_element_id in packages_spdx_ids and \
-            relationship.related_spdx_element in files_by_spdx_id.keys():
+            relationship.related_spdx_element_id in files_by_spdx_id.keys():
             contained_files_by_package_id.setdefault(relationship.spdx_element_id, []).append(
-                files_by_spdx_id[relationship.related_spdx_element])
-            if relationship.has_comment:
+                files_by_spdx_id[relationship.related_spdx_element_id])
+            if relationship.comment:
                 relationships_to_write.append(relationship)
-        elif relationship.relationship_type == "CONTAINED_BY" and \
-            relationship.related_spdx_element in packages_spdx_ids and \
+        elif relationship.relationship_type == RelationshipType.CONTAINED_BY and \
+            relationship.related_spdx_element_id in packages_spdx_ids and \
             relationship.spdx_element_id in files_by_spdx_id:
-            contained_files_by_package_id.setdefault(relationship.related_spdx_element, []).append(
+            contained_files_by_package_id.setdefault(relationship.related_spdx_element_id, []).append(
                 files_by_spdx_id[relationship.spdx_element_id])
-            if relationship.has_comment:
+            if relationship.comment:
                 relationships_to_write.append(relationship)
         else:
             relationships_to_write.append(relationship)


Test patch:
diff --git a/tests/spdx/writer/tagvalue/test_tagvalue_writer_helper_functions.py b/tests/spdx/writer/tagvalue/test_tagvalue_writer_helper_functions.py
new file mode 100644
index 0000000..300a3fd
--- /dev/null
+++ b/tests/spdx/writer/tagvalue/test_tagvalue_writer_helper_functions.py
@@ -0,0 +1,33 @@
+# Copyright (c) 2023 spdx contributors
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#   http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from spdx.model.relationship import RelationshipType
+from spdx.writer.tagvalue.tagvalue_writer_helper_functions import scan_relationships
+from tests.spdx.fixtures import package_fixture, file_fixture, relationship_fixture
+
+
+def test_scan_relationships():
+    first_package_spdx_id = "SPDXRef-Package1"
+    second_package_spdx_id = "SPDXRef-Package2"
+    packages = [package_fixture(spdx_id=first_package_spdx_id), package_fixture(spdx_id=second_package_spdx_id)]
+    file_spdx_id = "SPDXRef-File"
+    files = [file_fixture(spdx_id=file_spdx_id)]
+    relationships = [
+        relationship_fixture(spdx_element_id=first_package_spdx_id, relationship_type=RelationshipType.CONTAINS,
+                             related_spdx_element_id=file_spdx_id, comment=None),
+        relationship_fixture(spdx_element_id=second_package_spdx_id, relationship_type=RelationshipType.CONTAINS,
+                             related_spdx_element_id=file_spdx_id, comment=None)
+    ]
+
+    relationships_to_write, contained_files_by_package_id = scan_relationships(relationships, packages, files)
+
+    assert relationships_to_write == []
+    assert contained_files_by_package_id == {first_package_spdx_id: files,
+                                             second_package_spdx_id: files}