Skip to content

Commit 59b0987

Browse files
committed
get rid of tool-repo mutial exclusive tool vs component/service
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent e9fe527 commit 59b0987

File tree

2 files changed

+10
-51
lines changed

2 files changed

+10
-51
lines changed

cyclonedx/model/tool.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,9 @@ def __init__(
174174
self, *,
175175
components: Optional[Iterable[Component]] = None,
176176
services: Optional[Iterable[Service]] = None,
177-
# Deprecated in v1.5
177+
# Deprecated since v1.5
178178
tools: Optional[Iterable[Tool]] = None
179179
) -> None:
180-
if tools and (components or services):
181-
# Must use components/services or tools. Cannot use both
182-
raise MutuallyExclusivePropertiesException(
183-
'Cannot define both old (CycloneDX <= 1.4) and new '
184-
'(CycloneDX >= 1.5) format for tools.'
185-
)
186-
187180
if tools:
188181
warn('Using Tool is deprecated as of CycloneDX v1.5. Components and Services should be used now. '
189182
'See https://cyclonedx.org/docs/1.5/', DeprecationWarning)
@@ -202,12 +195,6 @@ def components(self) -> 'SortedSet[Component]':
202195

203196
@components.setter
204197
def components(self, components: Iterable[Component]) -> None:
205-
if self._tools:
206-
raise MutuallyExclusivePropertiesException(
207-
'Cannot define both old (CycloneDX <= 1.4) and new '
208-
'(CycloneDX >= 1.5) format for tools.'
209-
)
210-
211198
self._components = SortedSet(components)
212199

213200
@property
@@ -220,28 +207,14 @@ def services(self) -> 'SortedSet[Service]':
220207

221208
@services.setter
222209
def services(self, services: Iterable[Service]) -> None:
223-
if self._tools:
224-
raise MutuallyExclusivePropertiesException(
225-
'Cannot define both old (CycloneDX <= 1.4) and new '
226-
'(CycloneDX >= 1.5) format for tools.'
227-
)
228210
self._services = SortedSet(services)
229211

230212
@property
231213
def tools(self) -> 'SortedSet[Tool]':
232-
"""
233-
Returns:
234-
A SortedSet of Tools
235-
"""
236214
return self._tools
237215

238216
@tools.setter
239217
def tools(self, tools: Iterable[Tool]) -> None:
240-
if self._components or self._services:
241-
raise MutuallyExclusivePropertiesException(
242-
'Cannot define both old (CycloneDX <= 1.4) and new '
243-
'(CycloneDX >= 1.5) format for tools.'
244-
)
245218
self._tools = SortedSet(tools)
246219

247220
def __len__(self) -> int:

tests/test_model_tool_repository.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_tool_with_component_and_service_load_json(self) -> None:
4141
'bom_with_tool_with_component_and_service.json')
4242
with open(test_file, encoding='UTF-8') as f:
4343
bom_json = json_loads(f.read())
44-
bom = Bom.from_json(bom_json) # type: ignore[attr-defined]
44+
bom = Bom.from_json(bom_json) # type: ignore[attr-defined]
4545
self.assertTupleEqual(
4646
tuple(bom.metadata.tools.components),
4747
tuple(expected.metadata.tools.components), 'components')
@@ -68,23 +68,14 @@ def test_tool_with_component_and_service_load_xml(self) -> None:
6868
tuple(bom.metadata.tools.tools),
6969
tuple(expected.metadata.tools.tools), 'tools')
7070

71-
def test_invalid_tool_repo_properties(self) -> None:
72-
with self.assertRaises(MutuallyExclusivePropertiesException):
73-
ToolsRepository(
74-
components=[Component(name='test-component')],
75-
services=[Service(name='test-service')],
76-
tools=[Tool(name='test-tool')]
77-
)
78-
79-
def test_assign_component_with_existing_tool(self) -> None:
80-
tr = ToolsRepository(tools=[Tool()])
81-
with self.assertRaises(MutuallyExclusivePropertiesException):
82-
tr.components = SortedSet([Component(name='test-component')])
83-
84-
def test_assign_service_with_existing_tool(self) -> None:
85-
tr = ToolsRepository(tools=[Tool()])
86-
with self.assertRaises(MutuallyExclusivePropertiesException):
87-
tr.services = SortedSet([Service(name='test-service')])
71+
def test_init(self) -> None:
72+
cs = (Component(name='test-component'),)
73+
ss = (Service(name='test-service'),)
74+
ts = (Tool(name='test-tool'),)
75+
tr = ToolsRepository(components=cs, services=ss, tools=ts)
76+
self.assertTupleEqual(cs, tuple(tr.components))
77+
self.assertTupleEqual(ss, tuple(tr.services))
78+
self.assertTupleEqual(ts, tuple(tr.tools))
8879

8980
def test_unequal_different_type(self) -> None:
9081
tr = ToolsRepository()
@@ -117,11 +108,6 @@ def test_equal(self) -> None:
117108
tr2.tools.add(t)
118109
self.assertTrue(tr1 == tr2)
119110

120-
def test_assign_tool_with_existing_component(self) -> None:
121-
tr = ToolsRepository(components=SortedSet([Component(name='test-component')]))
122-
with self.assertRaises(MutuallyExclusivePropertiesException):
123-
tr.tools = SortedSet([Tool()])
124-
125111
def test_proper_service_provider_conversion(self) -> None:
126112
o = OrganizationalEntity(name='test-org')
127113
s = Service(name='test-service', provider=o)

0 commit comments

Comments
 (0)