Skip to content

Commit d9f76a0

Browse files
committed
Fixing logic for trim_punctuation and improving tests
1 parent 39dda20 commit d9f76a0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/folio_migration_tools/marc_rules_transformation/conditions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ def condition_trim_punctuation(self, legacy_id, value, parameter, marc_field: fi
170170
the period is preceded by a single alpha character (eg. "John D."). Also preserves any
171171
trailing "-" (eg. "1981-"). This condition was introduced in Poppy.
172172
"""
173-
pattern1 = re.compile(r"^(.*?)\\s.[.]$")
174-
pattern2 = re.compile(r"^(.*?)\\s.,[.]$")
173+
pattern1 = re.compile(r"^(.*?)\s.[.]$")
174+
pattern2 = re.compile(r"^(.*?)\s.,[.]$")
175175
value = value.strip()
176-
if pattern1.match(value) or pattern2.match(value):
176+
if pattern1.match(value) or value.endswith("-"):
177177
return value
178178
elif pattern2.match(value):
179179
return value.rstrip(",")

tests/test_conditions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ def test_condition_trim_period():
1515

1616
def test_condition_trim_punctuation():
1717
mock = Mock(spec=Conditions)
18-
res = Conditions.condition_trim_punctuation(None, mock, "Rockefeller, John D.,", None, None)
18+
res = Conditions.condition_trim_punctuation(None, mock, "Rockefeller, John D.", None, None)
1919
res2 = Conditions.condition_trim_punctuation(
2020
None, mock, "Rockefeller, John D., 1893-, ", None, None
2121
)
2222
res3 = Conditions.condition_trim_punctuation(None, mock, "Rockefeller, John. ", None, None)
23+
res4 = Conditions.condition_trim_punctuation(None, mock, "Rockefeller, John D.,", None, None)
2324
assert res == "Rockefeller, John D."
2425
assert res2 == "Rockefeller, John D., 1893-"
2526
assert res3 == "Rockefeller, John"
27+
assert res4 == "Rockefeller, John D."
2628

2729

2830
def test_condition_concat_subfields_by_name():

0 commit comments

Comments
 (0)