diff --git a/tests/abstract.py b/tests/abstract.py index 7223f219..9f353f6a 100644 --- a/tests/abstract.py +++ b/tests/abstract.py @@ -1000,3 +1000,26 @@ def test_missing_pkey(self): """ with pytest.raises(ValueError): self.datatype_class(None) + + def test_nested_subtype_from_xml_element(self, dov_xml): + """Test initialising the subtype(s) from the XML document. + + Parameters + ---------- + dov_xml : pytest.fixture returning bytes + Fixture providing DOV XML data. + """ + def instance_from_xml(clz, xml): + if len(clz.subtypes) == 0: + return + + if xml is None: + return + + st_instance = next( + clz.subtypes[0].from_xml(dov_xml)) + assert isinstance(st_instance, clz.subtypes[0]) + + instance_from_xml(clz.subtypes[0], dov_xml) + + instance_from_xml(self.datatype_class, dov_xml) diff --git a/tests/conftest.py b/tests/conftest.py index 8cf0f4fe..fcf1d169 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -314,7 +314,35 @@ def __get_remote_wfs_feature(*args, **kwargs): @pytest.fixture -def mp_dov_xml(monkeypatch, request): +def dov_xml(request): + """Fixture providing the DOV XML data. + + This fixture requires a module variable ``location_dov_xml`` + with the path to the dov_xml file on disk. + + Parameters + ---------- + request : pytest.fixture + PyTest fixture providing request context. + + """ + if not hasattr(request.module, "location_dov_xml"): + return + + file_path = getattr(request.module, "location_dov_xml") + + if file_path is None or not os.path.isfile(file_path): + return None + + with open(file_path, 'r', encoding="utf-8") as f: + data = f.read() + if not isinstance(data, bytes): + data = data.encode('utf-8') + return data + + +@pytest.fixture +def mp_dov_xml(monkeypatch, dov_xml): """Monkeypatch the call to get the remote XML data. This monkeypatch requires a module variable ``location_dov_xml`` @@ -328,14 +356,8 @@ def mp_dov_xml(monkeypatch, request): PyTest fixture providing request context. """ - def _get_xml_data(*args, **kwargs): - file_path = getattr(request.module, "location_dov_xml") - with open(file_path, 'r', encoding="utf-8") as f: - data = f.read() - if not isinstance(data, bytes): - data = data.encode('utf-8') - return data + return dov_xml monkeypatch.setattr(pydov.types.abstract.AbstractDovType, '_get_xml_data', _get_xml_data)