Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roel committed Jan 23, 2024
1 parent ce91e96 commit 1ca6b2d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
23 changes: 23 additions & 0 deletions tests/abstract.py
Expand Up @@ -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)
38 changes: 30 additions & 8 deletions tests/conftest.py
Expand Up @@ -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``
Expand All @@ -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)
Expand Down

0 comments on commit 1ca6b2d

Please sign in to comment.