|
4 | 4 | from pydantic import ValidationError |
5 | 5 |
|
6 | 6 | from zenml.models import ( |
| 7 | + ArtifactVersionIdentifier, |
| 8 | + ModelVersionIdentifier, |
7 | 9 | PipelineRunIdentifier, |
8 | 10 | StepRunIdentifier, |
9 | | - VersionedIdentifier, |
10 | 11 | ) |
11 | 12 |
|
12 | 13 |
|
13 | 14 | def test_versioned_identifier_validators(): |
14 | | - v_id = VersionedIdentifier(id=uuid4()) |
15 | | - assert v_id.id is not None and v_id.name is None and v_id.version is None |
| 15 | + for cls in [ArtifactVersionIdentifier, ModelVersionIdentifier]: |
| 16 | + v_id = cls(id=uuid4()) |
| 17 | + assert ( |
| 18 | + v_id.id is not None and v_id.name is None and v_id.version is None |
| 19 | + ) |
16 | 20 |
|
17 | | - v_nv = VersionedIdentifier(id=None, name="artifact", version="1.2.3") |
18 | | - assert v_nv.name == "artifact" and v_nv.version == "1.2.3" |
| 21 | + v_nv = cls(id=None, name="artifact", version="1.2.3") |
| 22 | + assert v_nv.name == "artifact" and v_nv.version == "1.2.3" |
19 | 23 |
|
20 | | - with pytest.raises(ValidationError): |
21 | | - VersionedIdentifier(id=uuid4(), name="artifact", version="1.0") |
| 24 | + with pytest.raises(ValidationError): |
| 25 | + cls(id=uuid4(), name="artifact", version="1.0") |
22 | 26 |
|
23 | | - with pytest.raises(ValidationError): |
24 | | - VersionedIdentifier(id=None, name=None, version=None) |
| 27 | + with pytest.raises(ValidationError): |
| 28 | + cls(id=None, name=None, version=None) |
25 | 29 |
|
26 | | - with pytest.raises(ValidationError): |
27 | | - VersionedIdentifier(name="artifact") |
| 30 | + with pytest.raises(ValidationError): |
| 31 | + cls(name="artifact") |
28 | 32 |
|
29 | | - with pytest.raises(ValidationError): |
30 | | - VersionedIdentifier(version="1.0.0") |
| 33 | + with pytest.raises(ValidationError): |
| 34 | + cls(version="1.0.0") |
31 | 35 |
|
32 | 36 |
|
33 | 37 | def test_pipeline_run_identifier_validators(): |
@@ -63,30 +67,29 @@ def test_pipeline_run_identifier_validators(): |
63 | 67 |
|
64 | 68 |
|
65 | 69 | def test_step_run_identifier_validators(): |
66 | | - s_id_only = StepRunIdentifier(id=uuid4(), name="", pipeline=None) |
67 | | - assert ( |
68 | | - s_id_only.id is not None |
69 | | - and s_id_only.name == "" |
70 | | - and s_id_only.pipeline is None |
71 | | - ) |
| 70 | + id_ = uuid4() |
| 71 | + |
| 72 | + s_id_only = StepRunIdentifier(id=id_) |
| 73 | + |
| 74 | + assert s_id_only.id == id_ |
72 | 75 |
|
73 | 76 | run_ident = PipelineRunIdentifier(id=None, name="nightly", prefix=None) |
74 | 77 |
|
75 | 78 | s_name_with_pipeline = StepRunIdentifier( |
76 | | - id=None, name="load_data", pipeline=run_ident |
| 79 | + id=None, name="load_data", run=run_ident |
77 | 80 | ) |
78 | 81 | assert s_name_with_pipeline.id is None |
79 | 82 | assert s_name_with_pipeline.name == "load_data" |
80 | | - assert isinstance(s_name_with_pipeline.pipeline, PipelineRunIdentifier) |
| 83 | + assert isinstance(s_name_with_pipeline.run, PipelineRunIdentifier) |
81 | 84 |
|
82 | 85 | with pytest.raises(ValidationError): |
83 | | - StepRunIdentifier(id=uuid4(), name="transform", pipeline=run_ident) |
| 86 | + StepRunIdentifier(id=uuid4(), name="transform", run=run_ident) |
84 | 87 |
|
85 | 88 | with pytest.raises(ValidationError): |
86 | | - StepRunIdentifier(id=None, name="", pipeline=None) |
| 89 | + StepRunIdentifier(id=None, name="") |
87 | 90 |
|
88 | 91 | with pytest.raises(ValidationError): |
89 | | - StepRunIdentifier(id=None, name="train_model", pipeline=None) |
| 92 | + StepRunIdentifier(id=None, name="train_model") |
90 | 93 |
|
91 | 94 | with pytest.raises(ValidationError): |
92 | | - StepRunIdentifier(id=None, name="", pipeline=run_ident) |
| 95 | + StepRunIdentifier(id=None, run=run_ident) |
0 commit comments