Skip to content

Commit

Permalink
get_edition
Browse files Browse the repository at this point in the history
  • Loading branch information
jonavellecuerdo committed Jul 24, 2024
1 parent 3f9ca54 commit fab75c6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
37 changes: 37 additions & 0 deletions tests/sources/xml/test_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,43 @@ def test_get_dates_transforms_correctly_if_char_positions_blank():
assert Marc.get_dates(source_record) is None


def test_get_edition_success():
source_record = create_marc_source_record_stub(
datafield_insert=(
"""
<datafield tag="250" ind1=" " ind2=" ">
<subfield code="a">9th ed. /</subfield>
<subfield code="b">Nick Ray ... [et al.].</subfield>
</datafield>
<datafield tag="250" ind1=" " ind2=" ">
<subfield code="a">Unabridged.</subfield>
</datafield>
"""
)
)
assert (
Marc.get_edition(source_record) == "9th ed. / Nick Ray ... [et al.]. Unabridged."
)


def test_get_edition_transforms_correctly_if_fields_blank():
source_record = create_marc_source_record_stub(
datafield_insert=(
"""
<datafield tag="250" ind1=" " ind2=" ">
<subfield code="a"></subfield>
</datafield>
"""
)
)
assert Marc.get_edition(source_record) is None


def test_get_edition_transforms_correctly_if_fields_missing():
source_record = create_marc_source_record_stub()
assert Marc.get_edition(source_record) is None


def test_marc_record_missing_leader_skips_record(caplog):
marc_xml_records = Marc.parse_source_file(
"tests/fixtures/marc/marc_record_missing_leader.xml"
Expand Down
21 changes: 14 additions & 7 deletions transmogrifier/sources/xml/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ def get_optional_fields(self, source_record: Tag) -> dict | None:
fields["dates"] = self.get_dates(source_record)

# edition
edition_values = []
for datafield in source_record.find_all("datafield", tag="250"):
if edition_value := self.create_subfield_value_string_from_datafield(
datafield, "ab", " "
):
edition_values.append(edition_value) # noqa: PERF401
fields["edition"] = " ".join(edition_values) or None
fields["edition"] = self.get_edition(source_record)

# file_formats

Expand Down Expand Up @@ -860,6 +854,19 @@ def get_dates(cls, source_record: Tag) -> list[timdex.Date] | None:
return [timdex.Date(kind="Publication date", value=publication_year)]
return None

@classmethod
def get_edition(cls, source_record: Tag) -> str | None:
edition_values = [
edition_value
for datafield in source_record.find_all("datafield", tag="250")
if (
edition_value := cls.create_subfield_value_string_from_datafield(
datafield, "ab", " "
)
)
]
return " ".join(edition_values) or None

@staticmethod
def get_main_titles(xml: Tag) -> list[str]:
"""
Expand Down

0 comments on commit fab75c6

Please sign in to comment.