Skip to content

Commit c76a098

Browse files
fix tests and formatting
Signed-off-by: Armin Tänzer <armin.taenzer@tngtech.com>
1 parent d37f8ae commit c76a098

9 files changed

Lines changed: 31 additions & 25 deletions

File tree

src/spdx_tools/spdx3/bump_from_spdx2/snippet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2023 spdx contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import List, Tuple, Optional
4+
from typing import List, Optional, Tuple
55

66
from spdx_tools.spdx3.bump_from_spdx2.license_expression import bump_license_expression_or_none_or_no_assertion
77
from spdx_tools.spdx3.bump_from_spdx2.message import print_missing_conversion

src/spdx_tools/spdx3/writer/json_ld/owl_to_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def convert_spdx_owl_to_jsonld_context(spdx_owl: str = "SPDX_OWL.json"):
6363
name = node["@id"].split(":")[-1]
6464
type_id = node["rdfs:range"]["@id"]
6565

66-
if name in context_dict and context_dict[name]["@id"].startswith('core'):
66+
if name in context_dict and context_dict[name]["@id"].startswith("core"):
6767
# if in doubt, prioritize core properties
6868
continue
6969

tests/spdx3/bump/test_file_bump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_bump_file(creation_info):
2727
assert file.spdx_id == expected_new_file_id
2828
assert file.verified_using == [integrity_method]
2929
assert file.concluded_license == ConjunctiveLicenseSet(
30-
[ListedLicense("MIT", "MIT", ""), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "")]
30+
[ListedLicense("MIT", "MIT", "blank"), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "blank")]
3131
)
3232
assert file.copyright_text == spdx2_file.copyright_text
3333
assert file.attribution_text == spdx2_file.attribution_texts[0]

tests/spdx3/bump/test_license_expression_bump.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def test_license_expression_or_none_or_no_assertion(element, expected_class):
4040
@pytest.mark.parametrize(
4141
"license_expression, extracted_licensing_info, expected_element",
4242
[
43-
(get_spdx_licensing().parse("MIT"), [], ListedLicense("MIT", "MIT", "")),
44-
(get_spdx_licensing().parse("LGPL-2.0"), [], ListedLicense("LGPL-2.0-only", "LGPL-2.0-only", "")),
43+
(get_spdx_licensing().parse("MIT"), [], ListedLicense("MIT", "MIT", "blank")),
44+
(get_spdx_licensing().parse("LGPL-2.0"), [], ListedLicense("LGPL-2.0-only", "LGPL-2.0-only", "blank")),
4545
(
4646
get_spdx_licensing().parse("LicenseRef-1"),
4747
[extracted_licensing_info_fixture()],
@@ -51,7 +51,7 @@ def test_license_expression_or_none_or_no_assertion(element, expected_class):
5151
get_spdx_licensing().parse("MIT AND LGPL-2.0"),
5252
[],
5353
ConjunctiveLicenseSet(
54-
[ListedLicense("MIT", "MIT", ""), ListedLicense("LGPL-2.0-only", "LGPL-2.0-only", "")]
54+
[ListedLicense("MIT", "MIT", "blank"), ListedLicense("LGPL-2.0-only", "LGPL-2.0-only", "blank")]
5555
),
5656
),
5757
(
@@ -60,15 +60,16 @@ def test_license_expression_or_none_or_no_assertion(element, expected_class):
6060
DisjunctiveLicenseSet(
6161
[
6262
CustomLicense("LicenseRef-1", "licenseName", "extractedText"),
63-
ListedLicense("LGPL-2.0-only", "LGPL-2.0-only", ""),
63+
ListedLicense("LGPL-2.0-only", "LGPL-2.0-only", "blank"),
6464
]
6565
),
6666
),
6767
(
6868
get_spdx_licensing().parse("LGPL-2.0 WITH 389-exception"),
6969
[],
7070
WithAdditionOperator(
71-
ListedLicense("LGPL-2.0-only", "LGPL-2.0-only", ""), ListedLicenseException("389-exception", "", "")
71+
ListedLicense("LGPL-2.0-only", "LGPL-2.0-only", "blank"),
72+
ListedLicenseException("389-exception", "", ""),
7273
),
7374
),
7475
(
@@ -90,7 +91,7 @@ def test_license_expression_or_none_or_no_assertion(element, expected_class):
9091
],
9192
ConjunctiveLicenseSet(
9293
[
93-
ListedLicense("MIT", "MIT", ""),
94+
ListedLicense("MIT", "MIT", "blank"),
9495
WithAdditionOperator(
9596
CustomLicense("LicenseRef-1", "licenseName", "extractedText"),
9697
CustomLicenseAddition("custom-exception", "exceptionName", "This is a custom exception"),

tests/spdx3/bump/test_package_bump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ def test_bump_package(creation_info, originator, expected_originator, supplier,
6969
assert package.copyright_text == spdx2_package.copyright_text
7070
assert package.attribution_text == spdx2_package.attribution_texts[0]
7171
assert package.concluded_license == ConjunctiveLicenseSet(
72-
[ListedLicense("MIT", "MIT", ""), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "")]
72+
[ListedLicense("MIT", "MIT", "blank"), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "blank")]
7373
)
7474
assert package.declared_license == ConjunctiveLicenseSet(
75-
[ListedLicense("MIT", "MIT", ""), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "")]
75+
[ListedLicense("MIT", "MIT", "blank"), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "blank")]
7676
)
7777

7878

tests/spdx3/bump/test_relationship_bump.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def test_relationship_bump(creation_info):
1919

2020
assert relationship == Relationship(
2121
f"{document_namespace}#SPDXRef-Relationship-1",
22-
spdx2_relationship.spdx_element_id,
22+
f"{document_namespace}#{spdx2_relationship.spdx_element_id}",
2323
RelationshipType.DESCRIBES,
24-
[spdx2_relationship.related_spdx_element_id],
24+
[f"{document_namespace}#{spdx2_relationship.related_spdx_element_id}"],
2525
creation_info=creation_info,
2626
comment=spdx2_relationship.comment,
2727
)
@@ -39,9 +39,12 @@ def test_relationships_bump(creation_info):
3939

4040
assert payload.get_element(f"{document_namespace}#SPDXRef-Relationship-1") == Relationship(
4141
f"{document_namespace}#SPDXRef-Relationship-1",
42-
relationships[0].spdx_element_id,
42+
f"{document_namespace}#{relationships[0].spdx_element_id}",
4343
RelationshipType.DESCRIBES,
44-
[relationships[0].related_spdx_element_id, relationships[1].related_spdx_element_id],
44+
[
45+
f"{document_namespace}#{relationships[0].related_spdx_element_id}",
46+
f"{document_namespace}#{relationships[1].related_spdx_element_id}",
47+
],
4548
creation_info=creation_info,
4649
)
4750

@@ -63,7 +66,7 @@ def test_relationships_bump_with_setting_completeness(creation_info):
6366

6467
assert payload.get_element(f"{document_namespace}#SPDXRef-Relationship-0") == Relationship(
6568
f"{document_namespace}#SPDXRef-Relationship-0",
66-
relationships[0].spdx_element_id,
69+
f"{document_namespace}#{relationships[0].spdx_element_id}",
6770
RelationshipType.DESCRIBES,
6871
[],
6972
creation_info=creation_info,
@@ -72,15 +75,15 @@ def test_relationships_bump_with_setting_completeness(creation_info):
7275
)
7376
assert payload.get_element(f"{document_namespace}#SPDXRef-Relationship-1") == Relationship(
7477
f"{document_namespace}#SPDXRef-Relationship-1",
75-
relationships[1].spdx_element_id,
78+
f"{document_namespace}#{relationships[1].spdx_element_id}",
7679
RelationshipType.DESCRIBES,
77-
[relationships[1].related_spdx_element_id],
80+
[f"{document_namespace}#{relationships[1].related_spdx_element_id}"],
7881
creation_info=creation_info,
7982
comment=relationships[1].comment,
8083
)
8184
assert payload.get_element(f"{document_namespace}#SPDXRef-Relationship-2") == Relationship(
8285
f"{document_namespace}#SPDXRef-Relationship-2",
83-
relationships[2].spdx_element_id,
86+
f"{document_namespace}#{relationships[2].spdx_element_id}",
8487
RelationshipType.SPECIFICATION_FOR,
8588
[],
8689
creation_info=creation_info,

tests/spdx3/bump/test_snippet_bump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ def test_bump_snippet(creation_info):
2626
assert snippet.copyright_text == spdx2_snippet.copyright_text
2727
assert snippet.attribution_text == spdx2_snippet.attribution_texts[0]
2828
assert snippet.concluded_license == ConjunctiveLicenseSet(
29-
[ListedLicense("MIT", "MIT", ""), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "")]
29+
[ListedLicense("MIT", "MIT", "blank"), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "blank")]
3030
)

tests/spdx3/model/software/test_snippet.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77

8+
from spdx_tools.spdx3.model.positive_integer_range import PositiveIntegerRange
89
from spdx_tools.spdx3.model.software import Snippet, SoftwarePurpose
910

1011

@@ -15,16 +16,16 @@ def test_correct_initialization(creation_info):
1516
creation_info=creation_info,
1617
content_identifier="https://content.identifier",
1718
purpose=[SoftwarePurpose.SOURCE],
18-
byte_range=(3, 4),
19-
line_range=(346, 456),
19+
byte_range=PositiveIntegerRange(3, 4),
20+
line_range=PositiveIntegerRange(346, 456),
2021
)
2122

2223
assert snippet.spdx_id == "SPDXRef-Snippet"
2324
assert snippet.creation_info == creation_info
2425
assert snippet.content_identifier == "https://content.identifier"
2526
assert snippet.purpose == [SoftwarePurpose.SOURCE]
26-
assert snippet.byte_range == (3, 4)
27-
assert snippet.line_range == (346, 456)
27+
assert snippet.byte_range == PositiveIntegerRange(3, 4)
28+
assert snippet.line_range == PositiveIntegerRange(346, 456)
2829

2930

3031
@mock.patch("spdx_tools.spdx3.model.software.Snippet", autospec=True)

tests/spdx3/writer/json_ld/test_json_ld_writer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2023 spdx contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
import os
45

56
from spdx_tools.spdx3.bump_from_spdx2.spdx_document import bump_spdx_document
67
from spdx_tools.spdx3.payload import Payload
@@ -14,4 +15,4 @@ def test_json_writer():
1415
payload: Payload = bump_spdx_document(spdx2_document)
1516

1617
# this currently generates an actual file to look at, this should be changed to a temp file later
17-
write_payload(payload, "../../../SPDX3_jsonld_test")
18+
write_payload(payload, os.path.join(os.path.dirname(__file__), "../../../SPDX3_jsonld_test"))

0 commit comments

Comments
 (0)