Skip to content

Commit

Permalink
delete surrounding document-Tag from XML
Browse files Browse the repository at this point in the history
leads to failing tests caused by jsonyamlxml writer since json and yaml expect surrounding document

Signed-off-by: Meret Behrens <[email protected]>
  • Loading branch information
meretp committed Oct 26, 2022
1 parent b9d3a9d commit 31e57d4
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 246 deletions.
2 changes: 0 additions & 2 deletions data/SPDXXmlExample.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<SpdxDocument>
<Document>
<comment>This is a sample spreadsheet</comment>
<name>Sample_Document-V2.1</name>
Expand Down Expand Up @@ -261,4 +260,3 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</extractedText>
<relationshipType>CONTAINS</relationshipType>
</relationships>
</Document>
</SpdxDocument>
2 changes: 1 addition & 1 deletion spdx/parsers/xmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def parse(self, file):
file.read(), strip_whitespace=False, encoding="utf-8"
)
fixed_object = self._set_in_list(parsed_xml, self.LIST_LIKE_FIELDS)
self.document_object = fixed_object.get("SpdxDocument").get("Document")
self.document_object = fixed_object.get("Document")
return super(Parser, self).parse()

def _set_in_list(self, data, keys):
Expand Down
2 changes: 1 addition & 1 deletion spdx/writers/jsonyamlxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def create_document(self):
if self.document.relationships:
self.document_object["relationships"] = self.create_relationship_info()

return {"Document": self.document_object}
return self.document_object


def flatten_document(document_object):
Expand Down
2 changes: 1 addition & 1 deletion spdx/writers/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def write_document(document, out, validate=True):
raise InvalidDocumentError(messages)

writer = XMLWriter(document)
document_object = {"SpdxDocument": writer.create_document()}
document_object = {"Document": writer.create_document()}

xmltodict.unparse(document_object, out, encoding="utf-8", pretty=True)
184 changes: 91 additions & 93 deletions tests/data/doc_write/json-simple-multi-package.json
Original file line number Diff line number Diff line change
@@ -1,98 +1,96 @@
{
"Document": {
"spdxVersion": "SPDX-2.1",
"documentNamespace": "https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301",
"creationInfo": {
"creators": [
"Tool: ScanCode"
],
"created": "2021-10-21T17:09:37Z",
"licenseListVersion": "3.6"
"spdxVersion": "SPDX-2.1",
"documentNamespace": "https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301",
"creationInfo": {
"creators": [
"Tool: ScanCode"
],
"created": "2021-10-21T17:09:37Z",
"licenseListVersion": "3.6"
},
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "Sample_Document-V2.1",
"documentDescribes": [
{
"Package": {
"SPDXID": "SPDXRef-Package1",
"name": "some/path1",
"downloadLocation": "NOASSERTION",
"filesAnalyzed": false,
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "Some copyright"
}
},
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "Sample_Document-V2.1",
"documentDescribes": [
{
"Package": {
"SPDXID": "SPDXRef-Package1",
"name": "some/path1",
"downloadLocation": "NOASSERTION",
"filesAnalyzed": false,
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "Some copyright"
}
},
{
"Package": {
"SPDXID": "SPDXRef-Package2",
"name": "some/path2",
"downloadLocation": "NOASSERTION",
"packageVerificationCode": {
"packageVerificationCodeValue": "SOME code"
},
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "Some copyright",
"files": [
{
"File": {
"name": "./some/path/tofile",
"SPDXID": "SPDXRef-File",
"checksums": [
{
"algorithm": "checksumAlgorithm_sha1",
"checksumValue": "SOME-SHA1"
}
],
"licenseConcluded": "NOASSERTION",
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"copyrightText": "NOASSERTION",
"sha1": "SOME-SHA1"
}
{
"Package": {
"SPDXID": "SPDXRef-Package2",
"name": "some/path2",
"downloadLocation": "NOASSERTION",
"packageVerificationCode": {
"packageVerificationCodeValue": "SOME code"
},
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "Some copyright",
"files": [
{
"File": {
"name": "./some/path/tofile",
"SPDXID": "SPDXRef-File",
"checksums": [
{
"algorithm": "checksumAlgorithm_sha1",
"checksumValue": "SOME-SHA1"
}
],
"licenseConcluded": "NOASSERTION",
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"copyrightText": "NOASSERTION",
"sha1": "SOME-SHA1"
}
]
}
},
{
"Package": {
"SPDXID": "SPDXRef-Package3",
"name": "some/path3",
"downloadLocation": "NOASSERTION",
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "Some copyright",
"files": [
{
"File": {
"name": "./some/path/tofile",
"SPDXID": "SPDXRef-File",
"checksums": [
{
"algorithm": "checksumAlgorithm_sha1",
"checksumValue": "SOME-SHA1"
}
],
"licenseConcluded": "NOASSERTION",
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"copyrightText": "NOASSERTION",
"sha1": "SOME-SHA1"
}
}
]
}
},
{
"Package": {
"SPDXID": "SPDXRef-Package3",
"name": "some/path3",
"downloadLocation": "NOASSERTION",
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "Some copyright",
"files": [
{
"File": {
"name": "./some/path/tofile",
"SPDXID": "SPDXRef-File",
"checksums": [
{
"algorithm": "checksumAlgorithm_sha1",
"checksumValue": "SOME-SHA1"
}
],
"licenseConcluded": "NOASSERTION",
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"copyrightText": "NOASSERTION",
"sha1": "SOME-SHA1"
}
]
}
}
]
}
]
}
}
}
]
}
154 changes: 76 additions & 78 deletions tests/data/doc_write/xml-simple-multi-package.xml
Original file line number Diff line number Diff line change
@@ -1,79 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<SpdxDocument>
<Document>
<spdxVersion>SPDX-2.1</spdxVersion>
<documentNamespace>https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301</documentNamespace>
<creationInfo>
<creators>Tool: ScanCode</creators>
<created>2021-10-21T17:02:23Z</created>
<licenseListVersion>3.6</licenseListVersion>
</creationInfo>
<dataLicense>CC0-1.0</dataLicense>
<SPDXID>SPDXRef-DOCUMENT</SPDXID>
<name>Sample_Document-V2.1</name>
<documentDescribes>
<Package>
<SPDXID>SPDXRef-Package1</SPDXID>
<name>some/path1</name>
<downloadLocation>NOASSERTION</downloadLocation>
<filesAnalyzed>false</filesAnalyzed>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseDeclared>NOASSERTION</licenseDeclared>
<copyrightText>Some copyright</copyrightText>
</Package>
</documentDescribes>
<documentDescribes>
<Package>
<SPDXID>SPDXRef-Package2</SPDXID>
<name>some/path2</name>
<downloadLocation>NOASSERTION</downloadLocation>
<packageVerificationCode>
<packageVerificationCodeValue>SOME code</packageVerificationCodeValue>
</packageVerificationCode>
<licenseInfoFromFiles>LGPL-2.1-or-later</licenseInfoFromFiles>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseDeclared>NOASSERTION</licenseDeclared>
<copyrightText>Some copyright</copyrightText>
<files>
<File>
<name>./some/path/tofile</name>
<SPDXID>SPDXRef-File</SPDXID>
<checksums>
<algorithm>checksumAlgorithm_sha1</algorithm>
<checksumValue>SOME-SHA1</checksumValue>
</checksums>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseInfoFromFiles>LGPL-2.1-or-later</licenseInfoFromFiles>
<copyrightText>NOASSERTION</copyrightText>
<sha1>SOME-SHA1</sha1>
</File>
</files>
</Package>
</documentDescribes>
<documentDescribes>
<Package>
<SPDXID>SPDXRef-Package3</SPDXID>
<name>some/path3</name>
<downloadLocation>NOASSERTION</downloadLocation>
<licenseInfoFromFiles>LGPL-2.1-or-later</licenseInfoFromFiles>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseDeclared>NOASSERTION</licenseDeclared>
<copyrightText>Some copyright</copyrightText>
<files>
<File>
<name>./some/path/tofile</name>
<SPDXID>SPDXRef-File</SPDXID>
<checksums>
<algorithm>checksumAlgorithm_sha1</algorithm>
<checksumValue>SOME-SHA1</checksumValue>
</checksums>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseInfoFromFiles>LGPL-2.1-or-later</licenseInfoFromFiles>
<copyrightText>NOASSERTION</copyrightText>
<sha1>SOME-SHA1</sha1>
</File>
</files>
</Package>
</documentDescribes>
</Document>
</SpdxDocument>
<Document>
<spdxVersion>SPDX-2.1</spdxVersion>
<documentNamespace>https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301</documentNamespace>
<creationInfo>
<creators>Tool: ScanCode</creators>
<created>2021-10-21T17:02:23Z</created>
<licenseListVersion>3.6</licenseListVersion>
</creationInfo>
<dataLicense>CC0-1.0</dataLicense>
<SPDXID>SPDXRef-DOCUMENT</SPDXID>
<name>Sample_Document-V2.1</name>
<documentDescribes>
<Package>
<SPDXID>SPDXRef-Package1</SPDXID>
<name>some/path1</name>
<downloadLocation>NOASSERTION</downloadLocation>
<filesAnalyzed>false</filesAnalyzed>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseDeclared>NOASSERTION</licenseDeclared>
<copyrightText>Some copyright</copyrightText>
</Package>
</documentDescribes>
<documentDescribes>
<Package>
<SPDXID>SPDXRef-Package2</SPDXID>
<name>some/path2</name>
<downloadLocation>NOASSERTION</downloadLocation>
<packageVerificationCode>
<packageVerificationCodeValue>SOME code</packageVerificationCodeValue>
</packageVerificationCode>
<licenseInfoFromFiles>LGPL-2.1-or-later</licenseInfoFromFiles>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseDeclared>NOASSERTION</licenseDeclared>
<copyrightText>Some copyright</copyrightText>
<files>
<File>
<name>./some/path/tofile</name>
<SPDXID>SPDXRef-File</SPDXID>
<checksums>
<algorithm>checksumAlgorithm_sha1</algorithm>
<checksumValue>SOME-SHA1</checksumValue>
</checksums>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseInfoFromFiles>LGPL-2.1-or-later</licenseInfoFromFiles>
<copyrightText>NOASSERTION</copyrightText>
<sha1>SOME-SHA1</sha1>
</File>
</files>
</Package>
</documentDescribes>
<documentDescribes>
<Package>
<SPDXID>SPDXRef-Package3</SPDXID>
<name>some/path3</name>
<downloadLocation>NOASSERTION</downloadLocation>
<licenseInfoFromFiles>LGPL-2.1-or-later</licenseInfoFromFiles>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseDeclared>NOASSERTION</licenseDeclared>
<copyrightText>Some copyright</copyrightText>
<files>
<File>
<name>./some/path/tofile</name>
<SPDXID>SPDXRef-File</SPDXID>
<checksums>
<algorithm>checksumAlgorithm_sha1</algorithm>
<checksumValue>SOME-SHA1</checksumValue>
</checksums>
<licenseConcluded>NOASSERTION</licenseConcluded>
<licenseInfoFromFiles>LGPL-2.1-or-later</licenseInfoFromFiles>
<copyrightText>NOASSERTION</copyrightText>
<sha1>SOME-SHA1</sha1>
</File>
</files>
</Package>
</documentDescribes>
</Document>
Loading

0 comments on commit 31e57d4

Please sign in to comment.