Skip to content

Commit

Permalink
Rename Transformer > XmlTransformer
Browse files Browse the repository at this point in the history
* Rename Transformer > XmlTransformer across repo to prepare for the creation of Transformer metaclass
  • Loading branch information
ehanson8 committed Nov 20, 2023
1 parent 2f2f832 commit 43dba21
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 64 deletions.
34 changes: 17 additions & 17 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,47 @@
from transmogrifier.helpers import parse_xml_records
from transmogrifier.models import TimdexRecord
from transmogrifier.sources.datacite import Datacite
from transmogrifier.sources.transformer import Transformer
from transmogrifier.sources.transformer import XmlTransformer


def test_transformer_initializes_with_expected_attributes(oai_pmh_records):
transformer = Transformer("cool-repo", oai_pmh_records)
def test_xmltransformer_initializes_with_expected_attributes(oai_pmh_records):
transformer = XmlTransformer("cool-repo", oai_pmh_records)
assert transformer.source == "cool-repo"
assert transformer.source_base_url == "https://example.com/"
assert transformer.source_name == "A Cool Repository"
assert transformer.input_records == oai_pmh_records


def test_transformer_iterates_through_all_records(oai_pmh_records):
output_records = Transformer("cool-repo", oai_pmh_records)
def test_xmltransformer_iterates_through_all_records(oai_pmh_records):
output_records = XmlTransformer("cool-repo", oai_pmh_records)
assert len(list(output_records)) == 2
assert output_records.processed_record_count == 3
assert output_records.transformed_record_count == 2
assert len(output_records.deleted_records) == 1


def test_transformer_iterates_successfully_if_get_optional_fields_returns_none(
def test_xmltransformer_iterates_successfully_if_get_optional_fields_returns_none(
oai_pmh_records,
):
with patch(
"transmogrifier.sources.transformer.Transformer.get_optional_fields"
"transmogrifier.sources.transformer.XmlTransformer.get_optional_fields"
) as m:
m.return_value = None
output_records = Transformer("cool-repo", oai_pmh_records)
output_records = XmlTransformer("cool-repo", oai_pmh_records)
assert len(list(output_records)) == 0
assert output_records.processed_record_count == 3
assert output_records.skipped_record_count == 2
assert output_records.transformed_record_count == 0
assert len(output_records.deleted_records) == 1


def test_transformer_record_is_deleted_returns_true_if_deleted(caplog):
def test_xmltransformer_record_is_deleted_returns_true_if_deleted(caplog):
input_records = parse_xml_records("tests/fixtures/record_deleted.xml")
assert Transformer.record_is_deleted(next(input_records)) is True
assert XmlTransformer.record_is_deleted(next(input_records)) is True


def test_transformer_get_required_fields_returns_expected_values(oai_pmh_records):
transformer = Transformer("cool-repo", oai_pmh_records)
def test_xmltransformer_get_required_fields_returns_expected_values(oai_pmh_records):
transformer = XmlTransformer("cool-repo", oai_pmh_records)
assert transformer.get_required_fields(next(oai_pmh_records)) == {
"source": "A Cool Repository",
"source_link": "https://example.com/12345",
Expand All @@ -52,8 +52,8 @@ def test_transformer_get_required_fields_returns_expected_values(oai_pmh_records
}


def test_transformer_transform_returns_timdex_record(oai_pmh_records):
transformer = Transformer("cool-repo", oai_pmh_records)
def test_xmltransformer_transform_returns_timdex_record(oai_pmh_records):
transformer = XmlTransformer("cool-repo", oai_pmh_records)
assert next(transformer) == TimdexRecord(
source="A Cool Repository",
source_link="https://example.com/12345",
Expand All @@ -64,7 +64,7 @@ def test_transformer_transform_returns_timdex_record(oai_pmh_records):
)


def test_get_valid_title_with_title_field_blank_logs_warning(caplog):
def test_xmltransformer_get_valid_title_with_title_field_blank_logs_warning(caplog):
input_records = parse_xml_records("tests/fixtures/record_title_field_blank.xml")
output_records = Datacite("cool-repo", input_records)
assert next(output_records).title == "Title not provided"
Expand All @@ -74,7 +74,7 @@ def test_get_valid_title_with_title_field_blank_logs_warning(caplog):
)


def test_get_valid_title_with_title_field_missing_logs_warning(caplog):
def test_xmltransformer_get_valid_title_with_title_field_missing_logs_warning(caplog):
input_records = parse_xml_records("tests/fixtures/record_title_field_missing.xml")
output_records = Datacite("cool-repo", input_records)
assert next(output_records).title == "Title not provided"
Expand All @@ -84,7 +84,7 @@ def test_get_valid_title_with_title_field_missing_logs_warning(caplog):
)


def test_get_valid_title_with_title_field_multiple_logs_warning(caplog):
def test_xmltransformer_get_valid_title_with_title_field_multiple_logs_warning(caplog):
input_records = parse_xml_records("tests/fixtures/record_title_field_multiple.xml")
output_records = Datacite("cool-repo", input_records)
assert (
Expand Down
6 changes: 3 additions & 3 deletions transmogrifier/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from transmogrifier.config import DATE_FORMATS
from transmogrifier.models import TimdexRecord

# import Transformer only when type checking to avoid circular dependency
# import XmlTransformer only when type checking to avoid circular dependency
if TYPE_CHECKING: # pragma: no cover
from transmogrifier.sources.transformer import Transformer
from transmogrifier.sources.transformer import XmlTransformer

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -177,7 +177,7 @@ def write_deleted_records_to_file(deleted_records: list[str], output_file_path:


def write_timdex_records_to_json(
transformer_instance: "Transformer", output_file_path: str
transformer_instance: "XmlTransformer", output_file_path: str
) -> int:
count = 0
try:
Expand Down
4 changes: 2 additions & 2 deletions transmogrifier/sources/datacite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import transmogrifier.models as timdex
from transmogrifier.helpers import validate_date, validate_date_range
from transmogrifier.sources.transformer import Transformer
from transmogrifier.sources.transformer import XmlTransformer

logger = logging.getLogger(__name__)


class Datacite(Transformer):
class Datacite(XmlTransformer):
"""Datacite transformer."""

def get_optional_fields(self, xml: Tag) -> Optional[dict]:
Expand Down
4 changes: 2 additions & 2 deletions transmogrifier/sources/dspace_dim.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import transmogrifier.models as timdex
from transmogrifier.helpers import validate_date, validate_date_range
from transmogrifier.sources.transformer import Transformer
from transmogrifier.sources.transformer import XmlTransformer

logger = logging.getLogger(__name__)


class DspaceDim(Transformer):
class DspaceDim(XmlTransformer):
"""DSpace DIM transformer."""

def get_optional_fields(self, xml: Tag) -> Optional[dict]:
Expand Down
4 changes: 2 additions & 2 deletions transmogrifier/sources/dspace_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import transmogrifier.models as timdex
from transmogrifier.helpers import validate_date
from transmogrifier.sources.transformer import Transformer
from transmogrifier.sources.transformer import XmlTransformer

logger = logging.getLogger(__name__)


class DspaceMets(Transformer):
class DspaceMets(XmlTransformer):
"""DSpace METS transformer."""

def get_optional_fields(self, xml: Tag) -> dict:
Expand Down
4 changes: 2 additions & 2 deletions transmogrifier/sources/ead.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import transmogrifier.models as timdex
from transmogrifier.config import load_external_config
from transmogrifier.helpers import validate_date, validate_date_range
from transmogrifier.sources.transformer import Transformer
from transmogrifier.sources.transformer import XmlTransformer

logger = logging.getLogger(__name__)

Expand All @@ -16,7 +16,7 @@
)


class Ead(Transformer):
class Ead(XmlTransformer):
"""EAD transformer."""

def get_optional_fields(self, xml: Tag) -> Optional[dict]:
Expand Down
4 changes: 2 additions & 2 deletions transmogrifier/sources/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import transmogrifier.models as timdex
from transmogrifier.config import load_external_config
from transmogrifier.helpers import validate_date
from transmogrifier.sources.transformer import Transformer
from transmogrifier.sources.transformer import XmlTransformer

logger = logging.getLogger(__name__)

Expand All @@ -30,7 +30,7 @@
)


class Marc(Transformer):
class Marc(XmlTransformer):
"""Marc transformer."""

def get_optional_fields(self, xml: Tag) -> Optional[dict]:
Expand Down
4 changes: 2 additions & 2 deletions transmogrifier/sources/oaidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import transmogrifier.models as timdex
from transmogrifier.helpers import validate_date
from transmogrifier.sources.transformer import Transformer
from transmogrifier.sources.transformer import XmlTransformer

logger = logging.getLogger(__name__)


class OaiDc(Transformer):
class OaiDc(XmlTransformer):
"""
Generic OAI DC transformer.
Expand Down
Loading

0 comments on commit 43dba21

Please sign in to comment.