Skip to content

Commit

Permalink
Fix broken tests and examples
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolaus Weidner <[email protected]>
  • Loading branch information
nicoweidner committed Nov 3, 2022
1 parent aedd02e commit 97fcb17
Show file tree
Hide file tree
Showing 13 changed files with 720 additions and 698 deletions.
3 changes: 2 additions & 1 deletion spdx/parsers/xmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ def __init__(self, builder, logger):
"excludedFilesNames",
"files",
"documentDescribes",
"packages",
}

def parse(self, file):
parsed_xml = xmltodict.parse(
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
177 changes: 87 additions & 90 deletions tests/data/doc_write/json-simple-multi-package.json
Original file line number Diff line number Diff line change
@@ -1,98 +1,95 @@
{
"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": "2022-11-02T21:47:54Z",
"licenseListVersion": "3.6"
},
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "Sample_Document-V2.1",
"documentDescribes": [
"SPDXRef-Package1",
"SPDXRef-Package2",
"SPDXRef-Package3"
],
"packages": [
{
"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"
}
{
"SPDXID": "SPDXRef-Package2",
"name": "some/path2",
"downloadLocation": "NOASSERTION",
"packageVerificationCode": {
"packageVerificationCodeValue": "SOME code"
},
{
"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"
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "Some copyright",
"files": [
{
"File": {
"name": "./some/path/tofile",
"SPDXID": "SPDXRef-File",
"checksums": [
{
"algorithm": "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"
]
},
{
"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": "SHA1",
"checksumValue": "SOME-SHA1"
}
}
]
],
"licenseConcluded": "NOASSERTION",
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"copyrightText": "NOASSERTION",
"sha1": "SOME-SHA1"
}
}
}
]
}
]
}
]
}
103 changes: 56 additions & 47 deletions tests/data/doc_write/json-simple-plus.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
{
"Document": {
"spdxVersion": "SPDX-2.1",
"dataLicense": "CC0-1.0",
"name": "Sample_Document-V2.1",
"SPDXID": "SPDXRef-DOCUMENT",
"documentNamespace": "https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301",
"documentDescribes": [
{
"Package": {
"SPDXID": "SPDXRef-Package",
"name": "some/path",
"downloadLocation": "NOASSERTION",
"copyrightText": "Some copyrught",
"packageVerificationCode": {
"packageVerificationCodeValue": "SOME code"
},
"checksums": [
{
"algorithm": "checksumAlgorithm_sha1",
"checksumValue": "SOME-SHA1"
}
],
"licenseDeclared": "NOASSERTION",
"licenseConcluded": "NOASSERTION",
"files": [
{
"File": {
"name": "./some/path/tofile",
"SPDXID": "SPDXRef-File",
"checksums": [
{
"algorithm": "checksumAlgorithm_sha1",
"checksumValue": "SOME-SHA1"
}
],
"licenseConcluded": "NOASSERTION",
"copyrightText": "NOASSERTION",
"licenseInfoFromFiles": ["LGPL-2.1-or-later"],
"sha1": "SOME-SHA1"
"spdxVersion": "SPDX-2.1",
"documentNamespace": "https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301",
"creationInfo": {
"creators": [
"Tool: ScanCode"
],
"created": "2022-11-02T21:53:59Z",
"licenseListVersion": "3.6"
},
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "Sample_Document-V2.1",
"documentDescribes": [
"SPDXRef-Package"
],
"packages": [
{
"SPDXID": "SPDXRef-Package",
"name": "some/path",
"downloadLocation": "NOASSERTION",
"packageVerificationCode": {
"packageVerificationCodeValue": "SOME code"
},
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "Some copyrught",
"checksums": [
{
"algorithm": "SHA1",
"checksumValue": "SOME-SHA1"
}
],
"files": [
{
"File": {
"name": "./some/path/tofile",
"SPDXID": "SPDXRef-File",
"checksums": [
{
"algorithm": "SHA1",
"checksumValue": "SOME-SHA1"
}
}
],
"licenseInfoFromFiles": ["LGPL-2.1-or-later"],
"sha1": "SOME-SHA1"
],
"licenseConcluded": "NOASSERTION",
"licenseInfoFromFiles": [
"LGPL-2.1-or-later"
],
"copyrightText": "NOASSERTION",
"sha1": "SOME-SHA1"
}
}
}
]
}
}
]
}
]
}
Loading

0 comments on commit 97fcb17

Please sign in to comment.