Skip to content

Commit

Permalink
[issue-407, review] precise tests by using RDF.type as predicate and …
Browse files Browse the repository at this point in the history
…not only None as a wildcard

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
  • Loading branch information
meretp committed Feb 1, 2023
1 parent 6416a7c commit ab887e5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
6 changes: 2 additions & 4 deletions tests/spdx/writer/rdf/test_annotation_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# 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 rdflib import Graph, Literal, RDFS, URIRef
from rdflib import Graph, Literal, RDFS, URIRef, RDF

from spdx.datetime_conversions import datetime_to_iso_string
from spdx.writer.rdf.annotation_writer import add_annotation_to_graph
Expand All @@ -25,7 +23,7 @@ def test_add_annotation_to_graph():
add_annotation_to_graph(annotation, graph, "docNamespace", {})

assert (URIRef("docNamespace#SPDXRef-File"), SPDX_NAMESPACE.annotation, None) in graph
assert (None, None, SPDX_NAMESPACE.Annotation) in graph
assert (None, RDF.type, SPDX_NAMESPACE.Annotation) in graph
assert (None, SPDX_NAMESPACE.annotationType, SPDX_NAMESPACE.annotationType_review) in graph
assert (None, SPDX_NAMESPACE.annotationDate, Literal(datetime_to_iso_string(annotation.annotation_date))) in graph
assert (None, SPDX_NAMESPACE.annotator, Literal(annotation.annotator.to_serialized_string())) in graph
Expand Down
4 changes: 2 additions & 2 deletions tests/spdx/writer/rdf/test_checksum_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from rdflib import Graph, URIRef, Literal
from rdflib import Graph, URIRef, Literal, RDF

from spdx.model.checksum import ChecksumAlgorithm
from spdx.writer.rdf.checksum_writer import add_checksum_to_graph, algorithm_to_rdf_string
Expand All @@ -24,7 +24,7 @@ def test_add_checksum_to_graph():
add_checksum_to_graph(checksum, graph, URIRef("parentNode"))

assert (URIRef("parentNode"), SPDX_NAMESPACE.checksum, None) in graph
assert (None, None, SPDX_NAMESPACE.Checksum) in graph
assert (None, RDF.type, SPDX_NAMESPACE.Checksum) in graph
assert (None, SPDX_NAMESPACE.algorithm, SPDX_NAMESPACE.checksumAlgorithm_sha1) in graph
assert (None, SPDX_NAMESPACE.checksumValue, Literal(checksum.value)) in graph

Expand Down
6 changes: 3 additions & 3 deletions tests/spdx/writer/rdf/test_creation_info_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# limitations under the License.
from datetime import datetime

from rdflib import Graph, Literal, RDFS, URIRef
from rdflib import Graph, Literal, RDFS, URIRef, RDF

from spdx.datetime_conversions import datetime_to_iso_string
from spdx.writer.rdf.creation_info_writer import add_creation_info_to_graph
Expand All @@ -24,14 +24,14 @@ def test_add_creation_info_to_graph():

add_creation_info_to_graph(creation_info, graph)

assert (None, None, SPDX_NAMESPACE.SpdxDocument) in graph
assert (None, RDF.type, SPDX_NAMESPACE.SpdxDocument) in graph
assert (URIRef(f"{creation_info.document_namespace}#{creation_info.spdx_id}"), None, None) in graph
assert (None, SPDX_NAMESPACE.dataLicense, URIRef(f"https://spdx.org/licenses/{creation_info.data_license}"))
assert (None, SPDX_NAMESPACE.name, Literal(creation_info.name)) in graph
assert (None, SPDX_NAMESPACE.specVersion, Literal(creation_info.spdx_version)) in graph
assert (None, SPDX_NAMESPACE.creationInfo, None) in graph

assert (None, None, SPDX_NAMESPACE.CreationInfo) in graph
assert (None, RDF.type, SPDX_NAMESPACE.CreationInfo) in graph
assert (None, SPDX_NAMESPACE.created, Literal(datetime_to_iso_string(creation_info.created))) in graph
assert (None, RDFS.comment, Literal(creation_info.creator_comment)) in graph
assert (None, SPDX_NAMESPACE.licenseListVersion, Literal(creation_info.license_list_version)) in graph
Expand Down
6 changes: 3 additions & 3 deletions tests/spdx/writer/rdf/test_external_document_ref_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# 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 rdflib import Graph, URIRef
from rdflib import Graph, URIRef, RDF
from spdx.rdfschema.namespace import SPDX_NAMESPACE

from spdx.writer.rdf.external_document_ref_writer import add_external_document_ref_to_graph
Expand All @@ -22,9 +22,9 @@ def test_add_external_document_ref_to_graph():
add_external_document_ref_to_graph(external_document_ref, graph, URIRef("docNode"), "docNamespace")

assert (URIRef("docNode"), SPDX_NAMESPACE.externalDocumentRef, URIRef("docNamespace#DocumentRef-external")) in graph
assert (None, None, SPDX_NAMESPACE.ExternalDocumentRef) in graph
assert (None, RDF.type, SPDX_NAMESPACE.ExternalDocumentRef) in graph
assert (None, SPDX_NAMESPACE.checksum, None) in graph
assert (None, None, SPDX_NAMESPACE.Checksum) in graph
assert (None, RDF.type, SPDX_NAMESPACE.Checksum) in graph
assert (None, SPDX_NAMESPACE.spdxDocument, URIRef(external_document_ref.document_uri)) in graph


Expand Down
4 changes: 2 additions & 2 deletions tests/spdx/writer/rdf/test_extracted_licensing_info_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# 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 rdflib import Graph, Literal, RDFS, URIRef
from rdflib import Graph, Literal, RDFS, URIRef, RDF
from spdx.rdfschema.namespace import SPDX_NAMESPACE

from spdx.writer.rdf.extracted_licensing_info_writer import add_extracted_licensing_info_to_graph
Expand All @@ -22,7 +22,7 @@ def test_add_extracted_licensing_info_to_graph():
add_extracted_licensing_info_to_graph(extracted_licensing_info, graph, URIRef("docNode"), "docNamespace")

assert (URIRef("docNode"), SPDX_NAMESPACE.hasExtractedLicensingInfo, None) in graph
assert (URIRef("docNamespace#LicenseRef-1"), None, SPDX_NAMESPACE.ExtractedLicensingInfo) in graph
assert (URIRef("docNamespace#LicenseRef-1"), RDF.type, SPDX_NAMESPACE.ExtractedLicensingInfo) in graph
assert (None, SPDX_NAMESPACE.licenseId, Literal(extracted_licensing_info.license_id)) in graph
assert (None, SPDX_NAMESPACE.extractedText, Literal(extracted_licensing_info.extracted_text)) in graph
assert (None, RDFS.seeAlso, Literal(extracted_licensing_info.cross_references[0])) in graph
Expand Down
4 changes: 2 additions & 2 deletions tests/spdx/writer/rdf/test_package_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_add_package_verification_code_to_graph():

add_package_verification_code_to_graph(verification_code, graph, URIRef("docNamespace"))

assert (None, None, SPDX_NAMESPACE.PackageVerificationCode) in graph
assert (None, RDF.type, SPDX_NAMESPACE.PackageVerificationCode) in graph
assert (None, SPDX_NAMESPACE.packageVerificationCodeValue,
Literal("85ed0817af83a24ad8da68c2b5094de69833983c")) in graph
assert (None, SPDX_NAMESPACE.packageVerificationCodeExcludedFile, Literal("./exclude.py")) in graph
Expand All @@ -71,7 +71,7 @@ def test_external_package_ref_to_graph():

add_external_package_ref_to_graph(external_reference, graph, URIRef("docNamespace"))

assert (None, None, SPDX_NAMESPACE.ExternalRef) in graph
assert (None, RDF.type, SPDX_NAMESPACE.ExternalRef) in graph
assert (None, SPDX_NAMESPACE.referenceCategory, SPDX_NAMESPACE.referenceCategory_packageManager) in graph
assert (None, SPDX_NAMESPACE.referenceType, URIRef("http://spdx.org/rdf/references/maven-central")) in graph
assert (None, SPDX_NAMESPACE.referenceLocator, Literal("org.apache.tomcat:tomcat:9.0.0.M4")) in graph
Expand Down

0 comments on commit ab887e5

Please sign in to comment.