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
5 changes: 5 additions & 0 deletions cyclonedx/model/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, BomMetaData):
return self.__comparable_tuple() == other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down
10 changes: 10 additions & 0 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, Pedigree):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down Expand Up @@ -806,6 +811,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, Swid):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down
10 changes: 10 additions & 0 deletions cyclonedx/model/component_evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, CallStackFrame):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down Expand Up @@ -744,6 +749,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, ComponentEvidence):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down
30 changes: 30 additions & 0 deletions cyclonedx/model/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, AlgorithmProperties):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down Expand Up @@ -683,6 +688,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, CertificateProperties):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down Expand Up @@ -810,6 +820,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, RelatedCryptoMaterialSecuredBy):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down Expand Up @@ -1055,6 +1070,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, RelatedCryptoMaterialProperties):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down Expand Up @@ -1314,6 +1334,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, Ikev2TransformTypes):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down Expand Up @@ -1440,6 +1465,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, ProtocolProperties):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down
5 changes: 5 additions & 0 deletions cyclonedx/model/release_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, ReleaseNotes):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down
5 changes: 5 additions & 0 deletions cyclonedx/model/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ def __eq__(self, other: object) -> bool:
return self.__comparable_tuple() == other.__comparable_tuple()
return False

def __lt__(self, other: object) -> bool:
if isinstance(other, ToolRepository):
return self.__comparable_tuple() < other.__comparable_tuple()
return NotImplemented

def __hash__(self) -> int:
return hash(self.__comparable_tuple())

Expand Down
170 changes: 170 additions & 0 deletions tests/_data/own/json/1.6/pr899.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/test_deserialize_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ def test_component_evidence_identity(self) -> None:
json = json_loads(f.read())
bom: Bom = Bom.from_json(json) # <<< is expected to not crash
self.assertIsNotNone(bom)

def test_pr899(self) -> None:
"""real world case from PR#899
see https://github.com/CycloneDX/cyclonedx-python-lib/pull/899
"""
json_file = join(OWN_DATA_DIRECTORY, 'json',
SchemaVersion.V1_6.to_version(),
'pr899.json')
with open(json_file) as f:
json = json_loads(f.read())
bom: Bom = Bom.from_json(json) # <<< is expected to not crash
self.assertIsNotNone(bom)
20 changes: 20 additions & 0 deletions tests/test_model_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ def test_basic_bom_metadata(self) -> None:
self.assertTrue(tools[0] in metadata.tools.tools)
self.assertTrue(tools[1] in metadata.tools.tools)

def test_bom_metadata_sorting(self) -> None:
"""Test that BomMetaData instances can be sorted without triggering TypeError"""
metadata1 = BomMetaData(
tools=[Tool(name='tool_a')],
authors=[OrganizationalContact(name='contact_a')]
)
metadata2 = BomMetaData(
tools=[Tool(name='tool_b')],
authors=[OrganizationalContact(name='contact_b')]
)
metadata3 = BomMetaData(
tools=[Tool(name='tool_c')],
authors=[OrganizationalContact(name='contact_c')]
)

# This should not raise TypeError: '<' not supported between instances
metadata_list = [metadata3, metadata1, metadata2]
sorted_metadata = sorted(metadata_list)
self.assertEqual(len(sorted_metadata), 3)


@ddt
class TestBom(TestCase):
Expand Down
Loading