Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/spdx/parser/jsonlikedict/json_like_dict_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# 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.
import json
from typing import Dict

from spdx.model.document import Document
Expand Down
1 change: 0 additions & 1 deletion src/spdx/validation/creation_info_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from typing import List

from spdx.model.document import CreationInfo
Expand Down
2 changes: 0 additions & 2 deletions tests/parser/jsonlikedict/test_dict_parsing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# 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 datetime import datetime
from unittest import TestCase

import pytest
Expand All @@ -18,7 +17,6 @@
from spdx.parser.error import SPDXParsingError
from spdx.parser.jsonlikedict.dict_parsing_functions import json_str_to_enum_name, \
parse_field_or_no_assertion, parse_field_or_no_assertion_or_none
from spdx.datetime_conversions import datetime_from_str


def test_json_str_to_enum():
Expand Down
200 changes: 137 additions & 63 deletions tests/writer/json/expected_results/expected.json
Original file line number Diff line number Diff line change
@@ -1,101 +1,175 @@
{
"SPDXID": "documentId",
"annotations": [
{
"annotationDate": "2022-12-02T00:00:00Z",
"annotationType": "REVIEW",
"annotator": "Person: reviewerName",
"comment": "reviewComment"
}
],
"comment": "comment",
"SPDXID": "SPDXRef-DOCUMENT",
"comment": "documentComment",
"creationInfo": {
"comment": "creatorComment",
"created": "2022-12-01T00:00:00Z",
"creators": [
"Tool: tools-python ([email protected])"
]
"Person: creatorName ([email protected])"
],
"licenseListVersion": "3.19"
},
"dataLicense": "dataLicense",
"dataLicense": "CC0-1.0",
"documentDescribes": [
"SPDXRef-File"
],
"documentNamespace": "https://some.namespace",
"externalDocumentRefs": [
{
"externalDocumentId": "docRefId",
"spdxDocument": "externalDocumentUri",
"checksum": {
"algorithm": "SHA1",
"checksumValue": "externalRefSha1"
}
"checksumValue": "71c4025dd9897b364f3ebbb42c484ff43d00791c"
},
"externalDocumentId": "DocumentRef-external",
"spdxDocument": "https://namespace.com"
}
],
"hasExtractedLicensingInfos": [
"files": [
{
"extractedText": "licenseText",
"licenseId": "licenseId"
"SPDXID": "SPDXRef-File",
"annotations": [
{
"annotationDate": "2022-12-01T00:00:00Z",
"annotationType": "REVIEW",
"annotator": "Person: annotatorName ([email protected])",
"comment": "annotationComment"
}
],
"attributionTexts": [
"fileAttributionText"
],
"checksums": [
{
"algorithm": "SHA1",
"checksumValue": "71c4025dd9897b364f3ebbb42c484ff43d00791c"
}
],
"comment": "fileComment",
"copyrightText": "copyrightText",
"fileContributors": [
"fileContributor"
],
"fileName": "./fileName.py",
"fileTypes": [
"TEXT"
],
"licenseComments": "licenseComment",
"licenseConcluded": "concludedLicenseExpression",
"licenseInfoInFiles": [
"licenseInfoInFileExpression"
],
"noticeText": "fileNotice"
}
],
"name": "documentName",
"spdxVersion": "spdxVersion",
"documentNamespace": "documentNamespace",
"documentDescribes": [
"packageId",
"fileId"
],
"packages": [
"hasExtractedLicensingInfos": [
{
"SPDXID": "packageId",
"downloadLocation": "NONE",
"filesAnalyzed": true,
"name": "packageName"
"comment": "licenseComment",
"extractedText": "extractedText",
"licenseId": "LicenseRef-1",
"name": "licenseName",
"seeAlsos": [
"https://see.also"
]
}
],
"files": [
"name": "documentName",
"packages": [
{
"SPDXID": "fileId",
"annotations": [
{
"annotationDate": "2022-12-03T00:00:00Z",
"annotationType": "OTHER",
"annotator": "Tool: toolName",
"comment": "otherComment"
}
"SPDXID": "SPDXRef-Package",
"attributionTexts": [
"packageAttributionText"
],
"builtDate": "2022-12-02T00:00:00Z",
"checksums": [
{
"algorithm": "SHA1",
"checksumValue": "fileSha1"
"checksumValue": "71c4025dd9897b364f3ebbb42c484ff43d00791c"
}
],
"comment": "packageComment",
"copyrightText": "packageCopyrightText",
"description": "packageDescription",
"downloadLocation": "https://download.com",
"externalRefs": [
{
"comment": "externalPackageRefComment",
"referenceCategory": "PACKAGE_MANAGER",
"referenceLocator": "org.apache.tomcat:tomcat:9.0.0.M4",
"referenceType": "maven-central"
}
],
"fileName": "fileName"
"filesAnalyzed": true,
"homepage": "https://homepage.com",
"licenseComments": "packageLicenseComment",
"licenseConcluded": "packageLicenseConcluded",
"licenseDeclared": "packageLicenseDeclared",
"licenseInfoFromFiles": [
"licenseInfoFromFile"
],
"name": "packageName",
"originator": "Person: originatorName ([email protected])",
"packageFileName": "./packageFileName",
"packageVerificationCode": {
"packageVerificationCodeExcludedFiles": [
"./exclude.py"
],
"packageVerificationCodeValue": "85ed0817af83a24ad8da68c2b5094de69833983c"
},
"primaryPackagePurpose": "SOURCE",
"releaseDate": "2022-12-01T00:00:00Z",
"sourceInfo": "sourceInfo",
"summary": "packageSummary",
"supplier": "Person: supplierName ([email protected])",
"validUntilDate": "2022-12-03T00:00:00Z",
"versionInfo": "12.2"
}
],
"relationships": [
{
"comment": "relationshipComment",
"relatedSpdxElement": "SPDXRef-File",
"relationshipType": "DESCRIBES",
"spdxElementId": "SPDXRef-DOCUMENT"
}
],
"snippets": [
{
"SPDXID": "snippetId",
"SPDXID": "SPDXRef-Snippet",
"attributionTexts": [
"snippetAttributionText"
],
"comment": "snippetComment",
"copyrightText": "licenseCopyrightText",
"licenseComments": "snippetLicenseComment",
"licenseConcluded": "snippetLicenseConcluded",
"licenseInfoInSnippets": [
"licenseInfoInSnippet"
],
"name": "snippetName",
"ranges": [
{
"startPointer": {
"reference": "snippetFileId",
"offset": 1
"endPointer": {
"offset": 2,
"reference": "SPDXRef-File"
},
"startPointer": {
"offset": 1,
"reference": "SPDXRef-File"
}
},
{
"endPointer": {
"reference": "snippetFileId",
"offset": 2
"lineNumber": 4,
"reference": "SPDXRef-File"
},
"startPointer": {
"lineNumber": 3,
"reference": "SPDXRef-File"
}
}
],
"snippetFromFile": "snippetFileId"
"snippetFromFile": "SPDXRef-File"
}
],
"relationships": [
{
"spdxElementId": "documentId",
"comment": "relationshipComment",
"relatedSpdxElement": "fileId",
"relationshipType": "DESCRIBES"
},
{
"spdxElementId": "relationshipOriginId",
"relatedSpdxElement": "relationShipTargetId",
"relationshipType": "AMENDS"
}
]
"spdxVersion": "SPDX-2.3"
}
37 changes: 2 additions & 35 deletions tests/writer/json/test_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@
# limitations under the License.
import json
import os
from datetime import datetime

import pytest

from spdx.model.actor import Actor, ActorType
from spdx.model.annotation import Annotation, AnnotationType
from spdx.model.checksum import ChecksumAlgorithm, Checksum
from spdx.model.document import CreationInfo, Document
from spdx.model.external_document_ref import ExternalDocumentRef
from spdx.model.extracted_licensing_info import ExtractedLicensingInfo
from spdx.model.file import File
from spdx.model.package import Package
from spdx.model.relationship import RelationshipType, Relationship
from spdx.model.snippet import Snippet
from spdx.model.spdx_none import SpdxNone
from spdx.writer.json.json_writer import write_document
from tests.fixtures import document_fixture

Expand All @@ -37,29 +25,8 @@ def temporary_file_path() -> str:


def test_write_json(temporary_file_path: str):
creation_info = CreationInfo("spdxVersion", "documentId", "documentName", "documentNamespace",
[Actor(ActorType.TOOL, "tools-python", "[email protected]")],
datetime(2022, 12, 1), document_comment="comment", data_license="dataLicense",
external_document_refs=[ExternalDocumentRef("docRefId", "externalDocumentUri",
Checksum(ChecksumAlgorithm.SHA1,
"externalRefSha1"))])
package = Package("packageId", "packageName", SpdxNone())
file = File("fileName", "fileId", [Checksum(ChecksumAlgorithm.SHA1, "fileSha1")])
snippet = Snippet("snippetId", "snippetFileId", (1, 2))
relationships = [
Relationship(creation_info.spdx_id, RelationshipType.DESCRIBES, "packageId"),
Relationship(creation_info.spdx_id, RelationshipType.DESCRIBES, "fileId", "relationshipComment"),
Relationship("relationshipOriginId", RelationshipType.AMENDS, "relationShipTargetId")]
annotations = [
Annotation("documentId", AnnotationType.REVIEW, Actor(ActorType.PERSON, "reviewerName"),
datetime(2022, 12, 2), "reviewComment"),
Annotation("fileId", AnnotationType.OTHER, Actor(ActorType.TOOL, "toolName"), datetime(2022, 12, 3),
"otherComment")]
extracted_licensing_info = [ExtractedLicensingInfo("licenseId", "licenseText")]
document = Document(creation_info, annotations=annotations, extracted_licensing_info=extracted_licensing_info,
relationships=relationships, packages=[package], files=[file], snippets=[snippet])
# TODO: Enable validation once test data is valid, https://github.com/spdx/tools-python/issues/397
write_document(document, temporary_file_path, validate=False)
document = document_fixture()
write_document(document, temporary_file_path, validate=True)

with open(temporary_file_path) as written_file:
written_json = json.load(written_file)
Expand Down
Loading