|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | import sdmx.model as model |
8 | | -from sdmx.model import v21 |
| 8 | +from sdmx.model import common, v21 |
9 | 9 | from sdmx.model.common import ( |
10 | 10 | Agency, |
11 | 11 | AnnotableArtefact, |
|
16 | 16 | IdentifiableArtefact, |
17 | 17 | Item, |
18 | 18 | ItemScheme, |
19 | | - MaintainableArtefact, |
20 | 19 | NameableArtefact, |
21 | 20 | Representation, |
22 | 21 | ) |
@@ -90,18 +89,22 @@ def test_eval_annotation(self, caplog) -> None: |
90 | 89 | ) |
91 | 90 |
|
92 | 91 |
|
| 92 | +URN = "urn:sdmx:org.sdmx.infomodel.conceptscheme.ConceptScheme=IT1:VARIAB_ALL(9.6)" |
| 93 | + |
| 94 | + |
93 | 95 | class TestIdentifiableArtefact: |
94 | | - def test_general(self): |
95 | | - urn = ( |
96 | | - "urn:sdmx:org.sdmx.infomodel.conceptscheme.ConceptScheme=IT1:VARIAB_ALL" |
97 | | - "(9.6)" |
98 | | - ) |
99 | | - urn_pat = urn.replace("(", r"\(").replace(")", r"\)") |
| 96 | + def test_init_urn(self): |
| 97 | + """IdentifiableArtefact can be initialized with URN.""" |
| 98 | + ia = IdentifiableArtefact(urn=URN) |
| 99 | + assert "VARIAB_ALL" == ia.id |
| 100 | + |
| 101 | + def test_general(self) -> None: |
| 102 | + urn_pat = URN.replace("(", r"\(").replace(")", r"\)") |
100 | 103 |
|
101 | 104 | with pytest.raises( |
102 | 105 | ValueError, match=f"ID BAD_URN does not match URN {urn_pat}" |
103 | 106 | ): |
104 | | - IdentifiableArtefact(id="BAD_URN", urn=urn) |
| 107 | + IdentifiableArtefact(id="BAD_URN", urn=URN) |
105 | 108 |
|
106 | 109 | # IdentifiableArtefact is hashable |
107 | 110 | ia = IdentifiableArtefact() |
@@ -162,27 +165,32 @@ def test_namea(self, caplog) -> None: |
162 | 165 | assert na1.compare(na2) |
163 | 166 |
|
164 | 167 |
|
165 | | -class TestMaintainableArtefact: |
166 | | - def test_urn(self): |
167 | | - urn = ( |
168 | | - "urn:sdmx:org.sdmx.infomodel.conceptscheme.ConceptScheme=" |
169 | | - "IT1:VARIAB_ALL(9.6)" |
170 | | - ) |
171 | | - ma = MaintainableArtefact(id="VARIAB_ALL", urn=urn) |
| 168 | +class TestVersionableArtefact: |
| 169 | + def test_urn(self) -> None: |
| 170 | + va = common.VersionableArtefact(id="VARIAB_ALL", urn=URN) |
172 | 171 |
|
173 | 172 | # Version is parsed from URN |
174 | | - assert ma.version == "9.6" |
| 173 | + assert va.version == "9.6" |
175 | 174 |
|
176 | 175 | # Mismatch raises an exception |
177 | | - with pytest.raises(ValueError, match="Version 9.7 does not match URN"): |
178 | | - MaintainableArtefact(version="9.7", urn=urn) |
| 176 | + with pytest.raises(ValueError, match="Version '9.7' does not match URN"): |
| 177 | + common.VersionableArtefact(version="9.7", urn=URN) |
| 178 | + |
| 179 | + def test_version_none(self) -> None: |
| 180 | + va = common.VersionableArtefact(version="None") |
| 181 | + assert va.version is None |
| 182 | + |
| 183 | + |
| 184 | +class TestMaintainableArtefact: |
| 185 | + def test_urn(self) -> None: |
| 186 | + ma = common.MaintainableArtefact(id="VARIAB_ALL", urn=URN) |
179 | 187 |
|
180 | 188 | # Maintainer is parsed from URN |
181 | 189 | assert ma.maintainer == Agency(id="IT1") |
182 | 190 |
|
183 | 191 | # Mismatch raises an exception |
184 | 192 | with pytest.raises(ValueError, match="Maintainer FOO does not match URN"): |
185 | | - MaintainableArtefact(maintainer=Agency(id="FOO"), urn=urn) |
| 193 | + common.MaintainableArtefact(maintainer=Agency(id="FOO"), urn=URN) |
186 | 194 |
|
187 | 195 |
|
188 | 196 | class TestItem: |
|
0 commit comments