Skip to content

Commit a51766d

Browse files
committed
fix: temporary fix for __hash__ of Component with properties #153
Signed-off-by: Paul Horton <[email protected]>
1 parent 2090c08 commit a51766d

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

cyclonedx/model/component.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ def __eq__(self, other: object) -> bool:
511511
def __hash__(self) -> int:
512512
return hash((
513513
self.author, self.copyright, self.description, str(self.external_references), self.group,
514-
str(self.hashes), str(self.licenses), self.mime_type, self.name, self.properties, self.publisher, self.purl,
515-
self.release_notes, self.scope, self.supplier, self.type, self.version, self.cpe
514+
str(self.hashes), str(self.licenses), self.mime_type, self.name, str(self.properties), self.publisher,
515+
self.purl, self.release_notes, self.scope, self.supplier, self.type, self.version, self.cpe
516516
))
517517

518518
def __repr__(self) -> str:

tests/test_model_component.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#
1717
# SPDX-License-Identifier: Apache-2.0
1818
# Copyright (c) OWASP Foundation. All Rights Reserved.
19+
from typing import List
1920
from unittest import TestCase
2021
from unittest.mock import Mock, patch
2122

22-
from cyclonedx.model import ExternalReference, ExternalReferenceType
23+
from cyclonedx.model import ExternalReference, ExternalReferenceType, Property
2324
from cyclonedx.model.component import Component, ComponentType
2425

2526

@@ -115,7 +116,7 @@ def test_empty_basic_component_no_version(self) -> None:
115116
self.assertEqual(len(c.hashes), 0)
116117
self.assertEqual(len(c.get_vulnerabilities()), 0)
117118

118-
def test_component_equal(self) -> None:
119+
def test_component_equal_1(self) -> None:
119120
c = Component(
120121
name='test-component', version='1.2.3'
121122
)
@@ -135,3 +136,34 @@ def test_component_equal(self) -> None:
135136
))
136137

137138
self.assertEqual(c, c2)
139+
140+
def test_component_equal_2(self) -> None:
141+
props: List[Property] = [
142+
Property(name='prop1', value='val1'),
143+
Property(name='prop2', value='val2')
144+
]
145+
146+
c = Component(
147+
name='test-component', version='1.2.3', properties=props
148+
)
149+
c2 = Component(
150+
name='test-component', version='1.2.3', properties=props
151+
)
152+
153+
self.assertEqual(c, c2)
154+
155+
def test_component_equal_3(self) -> None:
156+
c = Component(
157+
name='test-component', version='1.2.3', properties=[
158+
Property(name='prop1', value='val1'),
159+
Property(name='prop2', value='val2')
160+
]
161+
)
162+
c2 = Component(
163+
name='test-component', version='1.2.3', properties=[
164+
Property(name='prop3', value='val3'),
165+
Property(name='prop4', value='val4')
166+
]
167+
)
168+
169+
self.assertNotEqual(c, c2)

0 commit comments

Comments
 (0)