Skip to content

Commit a4deeaf

Browse files
committed
rename classes
Signed-off-by: Johannes Feichtner <[email protected]>
1 parent 028db25 commit a4deeaf

File tree

5 files changed

+68
-68
lines changed

5 files changed

+68
-68
lines changed

cyclonedx/model/lifecycle.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343

4444
@serializable.serializable_enum
45-
class Phase(str, Enum):
45+
class LifecyclePhase(str, Enum):
4646
DESIGN = 'design'
4747
PREBUILD = 'pre-build'
4848
BUILD = 'build'
@@ -53,46 +53,46 @@ class Phase(str, Enum):
5353

5454

5555
@serializable.serializable_class
56-
class PredefinedPhase:
56+
class PredefinedLifecycle:
5757
"""
5858
Object that defines pre-defined phases in the product lifecycle.
5959
6060
.. note::
6161
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.5/#metadata_lifecycles
6262
"""
6363

64-
def __init__(self, phase: Phase) -> None:
64+
def __init__(self, phase: LifecyclePhase) -> None:
6565
self._phase = phase
6666

6767
@property
68-
def phase(self) -> Phase:
68+
def phase(self) -> LifecyclePhase:
6969
return self._phase
7070

7171
@phase.setter
72-
def phase(self, phase: Phase) -> None:
72+
def phase(self, phase: LifecyclePhase) -> None:
7373
self._phase = phase
7474

7575
def __hash__(self) -> int:
7676
return hash(self._phase)
7777

7878
def __eq__(self, other: object) -> bool:
79-
if isinstance(other, PredefinedPhase):
79+
if isinstance(other, PredefinedLifecycle):
8080
return hash(other) == hash(self)
8181
return False
8282

8383
def __lt__(self, other: Any) -> bool:
84-
if isinstance(other, PredefinedPhase):
84+
if isinstance(other, PredefinedLifecycle):
8585
return self._phase < other._phase
86-
if isinstance(other, CustomPhase):
87-
return True # put PredefinedPhase before any CustomPhase
86+
if isinstance(other, NamedLifecycle):
87+
return True # put PredefinedLifecycle before any NamedLifecycle
8888
return NotImplemented
8989

9090
def __repr__(self) -> str:
91-
return f'<PredefinedPhase name={self._phase}>'
91+
return f'<PredefinedLifecycle name={self._phase}>'
9292

9393

9494
@serializable.serializable_class
95-
class CustomPhase:
95+
class NamedLifecycle:
9696
def __init__(self, name: str, *, description: Optional[str] = None) -> None:
9797
self._name = name
9898
self._description = description
@@ -133,28 +133,28 @@ def __hash__(self) -> int:
133133
return hash((self._name, self._description))
134134

135135
def __eq__(self, other: object) -> bool:
136-
if isinstance(other, CustomPhase):
136+
if isinstance(other, NamedLifecycle):
137137
return hash(other) == hash(self)
138138
return False
139139

140140
def __lt__(self, other: Any) -> bool:
141-
if isinstance(other, CustomPhase):
141+
if isinstance(other, NamedLifecycle):
142142
return _ComparableTuple((self._name, self._description)) < _ComparableTuple(
143143
(other._name, other._description)
144144
)
145-
if isinstance(other, PredefinedPhase):
146-
return False # put CustomPhase after any PredefinedPhase
145+
if isinstance(other, PredefinedLifecycle):
146+
return False # put NamedLifecycle after any PredefinedLifecycle
147147
return NotImplemented
148148

149149
def __repr__(self) -> str:
150-
return f'<CustomPhase name={self._name}>'
150+
return f'<NamedLifecycle name={self._name}>'
151151

152152

153-
Lifecycle = Union[PredefinedPhase, CustomPhase]
153+
Lifecycle = Union[PredefinedLifecycle, NamedLifecycle]
154154
"""TypeAlias for a union of supported lifecycle models.
155155
156-
- :class:`PredefinedPhase`
157-
- :class:`CustomPhase`
156+
- :class:`PredefinedLifecycle`
157+
- :class:`NamedLifecycle`
158158
"""
159159

160160
if TYPE_CHECKING: # pragma: no cover
@@ -192,9 +192,9 @@ def json_denormalize(cls, o: List[Dict[str, Any]],
192192
repo = LifecycleRepository()
193193
for li in o:
194194
if 'phase' in li:
195-
repo.add(PredefinedPhase.from_json(li)) # type:ignore[attr-defined]
195+
repo.add(PredefinedLifecycle.from_json(li)) # type:ignore[attr-defined]
196196
elif 'name' in li:
197-
repo.add(CustomPhase.from_json(li)) # type:ignore[attr-defined]
197+
repo.add(NamedLifecycle.from_json(li)) # type:ignore[attr-defined]
198198
else:
199199
raise CycloneDxDeserializationException(f'unexpected: {li!r}')
200200

@@ -228,12 +228,12 @@ def xml_denormalize(cls, o: Element,
228228
if tag == 'lifecycle':
229229
stages = list(li)
230230

231-
predefined_phase = next((el for el in stages if 'phase' in el.tag), None)
232-
custom_phase = next((el for el in stages if 'name' in el.tag), None)
233-
if predefined_phase is not None:
234-
repo.add(PredefinedPhase.from_xml(li, default_ns)) # type:ignore[attr-defined]
235-
elif custom_phase is not None:
236-
repo.add(CustomPhase.from_xml(li, default_ns)) # type:ignore[attr-defined]
231+
predefined_lifecycle = next((el for el in stages if 'phase' in el.tag), None)
232+
named_lifecycle = next((el for el in stages if 'name' in el.tag), None)
233+
if predefined_lifecycle is not None:
234+
repo.add(PredefinedLifecycle.from_xml(li, default_ns)) # type:ignore[attr-defined]
235+
elif named_lifecycle is not None:
236+
repo.add(NamedLifecycle.from_xml(li, default_ns)) # type:ignore[attr-defined]
237237
else:
238238
raise CycloneDxDeserializationException(f'unexpected: {li!r}')
239239

tests/_data/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
)
8888
from cyclonedx.model.issue import IssueClassification, IssueType, IssueTypeSource
8989
from cyclonedx.model.license import DisjunctiveLicense, License, LicenseAcknowledgement, LicenseExpression
90-
from cyclonedx.model.lifecycle import CustomPhase, Phase, PredefinedPhase
90+
from cyclonedx.model.lifecycle import LifecyclePhase, NamedLifecycle, PredefinedLifecycle
9191
from cyclonedx.model.release_note import ReleaseNotes
9292
from cyclonedx.model.service import Service
9393
from cyclonedx.model.vulnerability import (
@@ -534,7 +534,7 @@ def get_bom_just_complete_metadata() -> Bom:
534534
content='VGVzdCBjb250ZW50IC0gdGhpcyBpcyBub3QgdGhlIEFwYWNoZSAyLjAgbGljZW5zZSE='
535535
)
536536
)]
537-
bom.metadata.lifecycles = [PredefinedPhase(Phase.BUILD)]
537+
bom.metadata.lifecycles = [PredefinedLifecycle(LifecyclePhase.BUILD)]
538538
bom.metadata.properties = get_properties_1()
539539
return bom
540540

@@ -1129,10 +1129,10 @@ def get_bom_with_lifecycles() -> Bom:
11291129
return _make_bom(
11301130
metadata=BomMetaData(
11311131
lifecycles=[
1132-
PredefinedPhase(Phase.BUILD),
1133-
PredefinedPhase(Phase.POSTBUILD),
1134-
CustomPhase(name='platform-integration-testing',
1135-
description='Integration testing specific to the runtime platform'),
1132+
PredefinedLifecycle(LifecyclePhase.BUILD),
1133+
PredefinedLifecycle(LifecyclePhase.POSTBUILD),
1134+
NamedLifecycle(name='platform-integration-testing',
1135+
description='Integration testing specific to the runtime platform'),
11361136
],
11371137
component=Component(name='app', type=ComponentType.APPLICATION, bom_ref='my-app'),
11381138
),

tests/test_enums.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from cyclonedx.model.component import Component, Patch, Pedigree
3535
from cyclonedx.model.issue import IssueType
3636
from cyclonedx.model.license import DisjunctiveLicense
37-
from cyclonedx.model.lifecycle import Phase, PredefinedPhase
37+
from cyclonedx.model.lifecycle import LifecyclePhase, PredefinedLifecycle
3838
from cyclonedx.model.service import DataClassification, Service
3939
from cyclonedx.model.vulnerability import (
4040
BomTarget,
@@ -497,12 +497,12 @@ class TestEnumLifecyclePhase(_EnumTestCase):
497497
dp_cases_from_json_schemas('definitions', 'metadata', 'properties', 'lifecycles', 'items', 'phase'),
498498
)))
499499
def test_knows_value(self, value: str) -> None:
500-
super()._test_knows_value(Phase, value)
500+
super()._test_knows_value(LifecyclePhase, value)
501501

502502
@named_data(*NAMED_OF_SV)
503503
@patch('cyclonedx.model.ThisTool._version', 'TESTING')
504504
def test_cases_render_valid(self, of: OutputFormat, sv: SchemaVersion, *_: Any, **__: Any) -> None:
505505
bom = _make_bom(metadata=BomMetaData(
506-
lifecycles=[PredefinedPhase(phase=phase) for phase in Phase]
506+
lifecycles=[PredefinedLifecycle(phase=phase) for phase in LifecyclePhase]
507507
))
508508
super()._test_cases_render(bom, of, sv)

tests/test_model_bom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from cyclonedx.model.component import Component, ComponentType
3030
from cyclonedx.model.contact import OrganizationalContact, OrganizationalEntity
3131
from cyclonedx.model.license import DisjunctiveLicense
32-
from cyclonedx.model.lifecycle import CustomPhase, Phase, PredefinedPhase
32+
from cyclonedx.model.lifecycle import LifecyclePhase, NamedLifecycle, PredefinedLifecycle
3333
from tests._data.models import (
3434
get_bom_component_licenses_invalid,
3535
get_bom_component_nested_licenses_invalid,
@@ -76,8 +76,8 @@ def test_basic_bom_metadata(self) -> None:
7676
DisjunctiveLicense(id='Apache-2.0'),
7777
]
7878
lifecycles = [
79-
PredefinedPhase(phase=Phase.BUILD),
80-
CustomPhase(name='custom_phase', description='test'),
79+
PredefinedLifecycle(phase=LifecyclePhase.BUILD),
80+
NamedLifecycle(name='named_lifecycle', description='test'),
8181
]
8282
properties = [
8383
Property(name='property_1', value='value_1'),

tests/test_model_lifecycle.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,72 +19,72 @@
1919
from random import shuffle
2020
from unittest import TestCase
2121

22-
from cyclonedx.model.lifecycle import CustomPhase, Phase, PredefinedPhase
22+
from cyclonedx.model.lifecycle import LifecyclePhase, NamedLifecycle, PredefinedLifecycle
2323
from tests import reorder
2424

2525

26-
class TestModelPredefinedPhase(TestCase):
26+
class TestModelPredefinedLifecycle(TestCase):
2727
def test_create(self) -> None:
28-
lifecycle = PredefinedPhase(phase=Phase.BUILD)
29-
self.assertIs(Phase.BUILD, lifecycle.phase)
28+
lifecycle = PredefinedLifecycle(phase=LifecyclePhase.BUILD)
29+
self.assertIs(LifecyclePhase.BUILD, lifecycle.phase)
3030

3131
def test_update(self) -> None:
32-
lifecycle = PredefinedPhase(phase=Phase.DESIGN)
33-
lifecycle.phase = Phase.DISCOVERY
34-
self.assertIs(Phase.DISCOVERY, lifecycle.phase)
32+
lifecycle = PredefinedLifecycle(phase=LifecyclePhase.DESIGN)
33+
lifecycle.phase = LifecyclePhase.DISCOVERY
34+
self.assertIs(LifecyclePhase.DISCOVERY, lifecycle.phase)
3535

3636
def test_equal(self) -> None:
37-
a = PredefinedPhase(phase=Phase.BUILD)
38-
b = PredefinedPhase(phase=Phase.BUILD)
39-
c = PredefinedPhase(phase=Phase.DESIGN)
37+
a = PredefinedLifecycle(phase=LifecyclePhase.BUILD)
38+
b = PredefinedLifecycle(phase=LifecyclePhase.BUILD)
39+
c = PredefinedLifecycle(phase=LifecyclePhase.DESIGN)
4040
self.assertEqual(a, b)
4141
self.assertNotEqual(a, c)
4242

4343
def test_sort(self) -> None:
4444
expected_order = [3, 0, 2, 1]
4545
lifecycles = [
46-
CustomPhase(name='foo', description='baz'),
47-
CustomPhase(name='foo'),
48-
CustomPhase(name='foo', description='qux'),
49-
CustomPhase(name='bar'),
46+
NamedLifecycle(name='foo', description='baz'),
47+
NamedLifecycle(name='foo'),
48+
NamedLifecycle(name='foo', description='qux'),
49+
NamedLifecycle(name='bar'),
5050
]
5151
expected_lifecycles = reorder(lifecycles, expected_order)
5252
shuffle(lifecycles)
5353
sorted_lifecycles = sorted(lifecycles)
5454
self.assertListEqual(sorted_lifecycles, expected_lifecycles)
5555

5656

57-
class TestModelCustomPhase(TestCase):
57+
class TestModelNamedLifecycle(TestCase):
5858
def test_create(self) -> None:
59-
lifecycle = CustomPhase(name='foo')
59+
lifecycle = NamedLifecycle(name='foo')
6060
self.assertEqual('foo', lifecycle.name)
6161
self.assertIsNone(lifecycle.description)
6262

63-
lifecycle = CustomPhase(name='foo2n', description='foo2d')
63+
lifecycle = NamedLifecycle(name='foo2n', description='foo2d')
6464
self.assertEqual('foo2n', lifecycle.name)
6565
self.assertEqual('foo2d', lifecycle.description)
6666

6767
def test_update(self) -> None:
68-
lifecycle = CustomPhase(name='foo')
68+
lifecycle = NamedLifecycle(name='foo')
6969
self.assertEqual('foo', lifecycle.name)
7070
lifecycle.name = 'bar'
7171
self.assertEqual('bar', lifecycle.name)
7272

7373
def test_equal(self) -> None:
74-
a = CustomPhase('foo')
75-
b = CustomPhase('foo')
76-
c = CustomPhase('bar')
74+
a = NamedLifecycle('foo')
75+
b = NamedLifecycle('foo')
76+
c = NamedLifecycle('bar')
7777
self.assertEqual(a, b)
7878
self.assertNotEqual(a, c)
7979
self.assertNotEqual(a, 'foo')
8080

8181
def test_sort(self) -> None:
8282
expected_order = [3, 0, 2, 1]
8383
lifecycles = [
84-
CustomPhase(name='foo', description='baz'),
85-
CustomPhase(name='foo'),
86-
CustomPhase(name='foo', description='qux'),
87-
CustomPhase(name='bar'),
84+
NamedLifecycle(name='foo', description='baz'),
85+
NamedLifecycle(name='foo'),
86+
NamedLifecycle(name='foo', description='qux'),
87+
NamedLifecycle(name='bar'),
8888
]
8989
expected_lifecycles = reorder(lifecycles, expected_order)
9090
shuffle(lifecycles)
@@ -96,10 +96,10 @@ class TestModelLifecycle(TestCase):
9696
def test_sort_mixed(self) -> None:
9797
expected_order = [3, 0, 2, 1]
9898
lifecycles = [
99-
PredefinedPhase(phase=Phase.DESIGN),
100-
CustomPhase(name='Example2'),
101-
CustomPhase(name='Example'),
102-
PredefinedPhase(phase=Phase.BUILD),
99+
PredefinedLifecycle(phase=LifecyclePhase.DESIGN),
100+
NamedLifecycle(name='Example2'),
101+
NamedLifecycle(name='Example'),
102+
PredefinedLifecycle(phase=LifecyclePhase.BUILD),
103103
]
104104
expected_lifecycles = reorder(lifecycles, expected_order)
105105
shuffle(lifecycles)

0 commit comments

Comments
 (0)