Skip to content

Commit

Permalink
feat: establish SPASE conversion strategy (#213)
Browse files Browse the repository at this point in the history
Establish a new conversion strategy for the SPASE metadata standard,
laying the groundwork for future development. This includes:

- Connecting metadata to the test suite
- Updating relevant utility functions
- Modifying test fixtures
- Temporarily skipping tests for undeveloped conversion methods
  • Loading branch information
clnsmth committed Dec 10, 2024
1 parent 72492c8 commit 18f75a3
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/source/user/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ EML Strategy
:members:
:noindex:

SPASE Strategy
--------------

.. autoclass:: soso.strategies.spase.SPASE
:members:
:noindex:

Utilities
---------

Expand Down
14 changes: 13 additions & 1 deletion src/soso/strategies/spase.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, file: str, **kwargs: dict):
raise ValueError(file + " must be an XML file.")
super().__init__(metadata=etree.parse(file))
self.file = file
self.schema_version = None
self.schema_version = get_schema_version(self.metadata)
self.kwargs = kwargs

def get_id(self) -> None:
Expand Down Expand Up @@ -169,3 +169,15 @@ def get_was_generated_by(self) -> None:


# Below are utility functions for the SPASE strategy.


def get_schema_version(metadata: etree.ElementTree) -> str:
"""
:param metadata: The SPASE metadata object as an XML tree.
:returns: The version of the SPASE schema used in the metadata record.
"""
schema_version = metadata.findtext(
"{http://www.spase-group.org/data/schema}Version"
)
return schema_version
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from copy import deepcopy
import pytest
from soso.strategies.eml import EML
from soso.strategies.spase import SPASE
from soso.utilities import get_example_metadata_file_path, get_empty_metadata_file_path


Expand All @@ -18,18 +19,20 @@ def strategy_names() -> list:
return ["eml", "spase"]


@pytest.fixture(params=[EML])
@pytest.fixture(params=[EML, SPASE])
def strategy_instance(request) -> Union[Type, None]:
"""
:returns: The strategy instances.
"""
res = None
if request.param is EML:
res = request.param(file=get_example_metadata_file_path("EML"))
elif request.param is SPASE:
res = request.param(file=get_example_metadata_file_path("SPASE"))
return res


@pytest.fixture(params=[EML])
@pytest.fixture(params=[EML, SPASE])
def strategy_instance_no_meta(request) -> Union[Type, None]:
"""
:returns: The strategy instances parameterized with an empty metadata
Expand All @@ -38,6 +41,8 @@ def strategy_instance_no_meta(request) -> Union[Type, None]:
res = None
if request.param is EML:
res = request.param(file=get_empty_metadata_file_path("EML"))
elif request.param is SPASE:
res = request.param(file=get_empty_metadata_file_path("SPASE"))
return res


Expand Down
1 change: 1 addition & 0 deletions tests/data/spase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"@context": {"@vocab": "https://schema.org/"}, "@type": "Dataset"}
19 changes: 19 additions & 0 deletions tests/test_spase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Test additional SPASE module functions and methods."""

from lxml import etree
from soso.strategies.spase import get_schema_version
from soso.utilities import get_empty_metadata_file_path, get_example_metadata_file_path


def test_get_schema_version_returns_expected_value():
"""Test that the get_schema_version function returns the expected value."""

# Positive case: The function will return the schema version of the EML
# file.
spase = etree.parse(get_example_metadata_file_path("SPASE"))
assert get_schema_version(spase) == "2.5.0"

# Negative case: If the schema version is not present, the function will
# return None.
spase = etree.parse(get_empty_metadata_file_path("SPASE"))
assert get_schema_version(spase) is None
31 changes: 31 additions & 0 deletions tests/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_strategy_reads_schema_version(strategy_instance, strategy_instance_no_m
# consistent test suite.


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_id_returns_expected_type(strategy_instance, strategy_instance_no_meta):
"""Test that the get_id method returns the expected type."""
Expand All @@ -64,6 +65,7 @@ def test_get_id_returns_expected_type(strategy_instance, strategy_instance_no_me
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_name_returns_expected_type(strategy_instance, strategy_instance_no_meta):
"""Test that the get_name method returns the expected type."""
# Positive case
Expand All @@ -75,6 +77,7 @@ def test_get_name_returns_expected_type(strategy_instance, strategy_instance_no_
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_description_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -88,6 +91,7 @@ def test_get_description_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_url_returns_expected_type(strategy_instance, strategy_instance_no_meta):
"""Test that the get_url method returns the expected type."""
Expand All @@ -100,6 +104,7 @@ def test_get_url_returns_expected_type(strategy_instance, strategy_instance_no_m
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_same_as_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -114,6 +119,7 @@ def test_get_same_as_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_version_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -128,6 +134,7 @@ def test_get_version_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_is_accessible_for_free_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -143,6 +150,7 @@ def test_get_is_accessible_for_free_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_keywords_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -156,6 +164,7 @@ def test_get_keywords_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_identifier_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -172,6 +181,7 @@ def test_get_identifier_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_citation_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -186,6 +196,7 @@ def test_get_citation_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_variable_measured_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -199,6 +210,7 @@ def test_get_variable_measured_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_included_in_data_catalog_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -214,6 +226,7 @@ def test_get_included_in_data_catalog_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_subject_of_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -228,6 +241,7 @@ def test_get_subject_of_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_distribution_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -241,6 +255,7 @@ def test_get_distribution_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_potential_action_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -255,6 +270,7 @@ def test_get_potential_action_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_date_created_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -269,6 +285,7 @@ def test_get_date_created_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_date_modified_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -282,6 +299,7 @@ def test_get_date_modified_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_date_published_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -295,6 +313,7 @@ def test_get_date_published_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_expires_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -309,6 +328,7 @@ def test_get_expires_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_temporal_coverage_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -331,6 +351,7 @@ def test_get_temporal_coverage_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_spatial_coverage_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -344,6 +365,7 @@ def test_get_spatial_coverage_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_creator_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -360,6 +382,7 @@ def test_get_creator_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_contributor_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -376,6 +399,7 @@ def test_get_contributor_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_provider_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -390,6 +414,7 @@ def test_get_provider_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_publisher_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -404,6 +429,7 @@ def test_get_publisher_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_funding_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -417,6 +443,7 @@ def test_get_funding_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_license_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -430,6 +457,7 @@ def test_get_license_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_was_revision_of_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand All @@ -444,6 +472,7 @@ def test_get_was_revision_of_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_was_derived_from_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -457,6 +486,7 @@ def test_get_was_derived_from_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
def test_get_is_based_on_returns_expected_type(
strategy_instance, strategy_instance_no_meta
):
Expand All @@ -470,6 +500,7 @@ def test_get_is_based_on_returns_expected_type(
assert res is None


@pytest.mark.skipif(strategy_instance="SPASE", reason="Not yet implemented")
@pytest.mark.skipif(strategy_instance="EML", reason="Property not in schema")
def test_get_was_generated_by_returns_expected_type(
strategy_instance, strategy_instance_no_meta
Expand Down

0 comments on commit 18f75a3

Please sign in to comment.