Skip to content

Commit

Permalink
Add tests for issue to prevent regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
linearcombination committed Dec 12, 2024
1 parent 543bea7 commit b579d99
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 34 deletions.
40 changes: 40 additions & 0 deletions tests/e2e/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,3 +1693,43 @@ def test_en_ulb_1jn_en_ulb_3jn_language_book_order_with_no_email_1c() -> None:
assert (
"1 John</h2>" in body_content and "3 John</h2>" in body_content
), "Document should have had both 1 John and 3 John in it, but it didn't"

@pytest.mark.focus
def test_en_tn_mat_with_book_intro() -> None:
with TestClient(app=app, base_url=settings.api_test_url()) as client:
response = client.post(
"/documents",
json={
# "email_address": settings.TO_EMAIL_ADDRESS,
"assembly_strategy_kind": model.AssemblyStrategyEnum.LANGUAGE_BOOK_ORDER,
"assembly_layout_kind": model.AssemblyLayoutEnum.ONE_COLUMN,
"layout_for_print": False,
"chunk_size": model.ChunkSizeEnum.CHAPTER,
"generate_pdf": False,
"generate_epub": False,
"generate_docx": False,
"resource_requests": [
{
"lang_code": "en",
"resource_type": "tn",
"book_code": "mat",
},
],
},
)
finished_document_request_key = check_result(
response, suffix="html", poll_duration=4
)
html_filepath = os.path.join(
settings.DOCUMENT_OUTPUT_DIR,
"{}.html".format(finished_document_request_key),
)
with open(html_filepath, "r") as fin:
html = fin.read()
body_match = re.search(r"<body.*?>(.*?)</body>", html, re.DOTALL)
assert body_match, "Body not found in HTML"
body_content = body_match.group(1)
if settings.SHOW_TN_BOOK_INTRO:
assert (
"Outline of the Book of Matthew" in body_content
), "Document should have had TN book intro for mat, but didn't"
67 changes: 33 additions & 34 deletions tests/unit/test_usfm_error_detection_and_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,55 +74,55 @@ def test_fix_verse_marker_without_v(self) -> None:
\v 3 Vinse na man kpha fuhm ka nan zii bagaba.\v 4 Vinse we ba linwabung ɓuocnham la,la bagaba se ,Ii nyin faram la Neman li nwah buock.\v 5 Na man kha fuh la bai ba gamza gabq we bai fuh la bepiu la wulah vii a jekang.\v 6 In bi yang la bai ninka,Yuka be pi ba ba chonin ala we ba la ba ,au tarta vii kau u gama wala vii ba wai Yeso Almasihu.""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers(self) -> None:
self.assertEqual(
fix_standalone_verse_numbers(r"1 Some text."),
r"\v 1 Some text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers2(self) -> None:
self.assertEqual(
fix_standalone_verse_numbers(r"1 Some text. 2 This is more text."),
r"\v 1 Some text. \v 2 This is more text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers3(self) -> None:
self.assertEqual(
fix_standalone_verse_numbers(r"\v 1 Some text. \v 2 This is more text."),
r"\v 1 Some text. \v 2 This is more text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers4(self) -> None:
self.assertEqual(
fix_standalone_verse_numbers(r"1 Some text. \v 2 This is more text."),
r"\v 1 Some text. \v 2 This is more text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers5(self) -> None:
self.assertEqual(
fix_standalone_verse_numbers(r"\c 1 Some text. \v 1 This is more text."),
r"\c 1 Some text. \v 1 This is more text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers6(self) -> None:
self.assertEqual(
fix_standalone_verse_numbers(r"\1 Some text. \2 This is more text."),
r"\1 Some text. \2 This is more text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers7(self) -> None:
actual = fix_standalone_verse_numbers(
Expand All @@ -144,7 +144,7 @@ def test_standalone_verse_numbers7(self) -> None:
# print(repr(expected))
self.assertEqual(actual, expected)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers8(self) -> None:
self.assertEqual(
Expand All @@ -160,7 +160,7 @@ def test_standalone_verse_numbers8(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers9(self) -> None:
self.assertEqual(
Expand All @@ -174,7 +174,7 @@ def test_standalone_verse_numbers9(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers10(self) -> None:
self.assertEqual(
Expand All @@ -184,7 +184,7 @@ def test_standalone_verse_numbers10(self) -> None:
r"""\v 15 وأليود ولد أليعازر \li1 وأليعازر ولد متان \li1 ومتان ولد يعقوب \li1 \v 16 ويعقوب ولد يوسف رجل مريم اللي ولدت عيسى اللي يسموه المسيح \li4 \v 17 ويطلع مجموع الأجيال من إبراهيم إلى داود 14 جيل ومن داود إلى الأسر البابلي 14 جيل ومن الأسر البابلي إلى المسيح 14 جيل""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers11(self) -> None:
self.assertEqual(
Expand All @@ -194,7 +194,7 @@ def test_standalone_verse_numbers11(self) -> None:
r"""\v 1 This is a verse \v2 this is another verse \v 3 and this verse too \v 4 and another as well""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers12(self) -> None:
self.assertEqual(
Expand All @@ -204,7 +204,7 @@ def test_standalone_verse_numbers12(self) -> None:
r"""\v 1 This is a verse \v2 this is another verse 3 and this verse too 3 and another as well""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers13(self) -> None:
self.assertEqual(
Expand Down Expand Up @@ -262,7 +262,7 @@ def test_standalone_verse_numbers13(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers14(self) -> None:
self.assertEqual(
Expand All @@ -288,7 +288,7 @@ def test_standalone_verse_numbers14(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers15(self) -> None:
self.assertEqual(
Expand Down Expand Up @@ -320,7 +320,7 @@ def test_standalone_verse_numbers15(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_standalone_verse_numbers16(self) -> None:
self.assertEqual(
Expand Down Expand Up @@ -397,31 +397,31 @@ def test_fix_usfm(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_after_number(self) -> None:
self.assertEqual(
fix_missing_space_after_number(r"\v 1Some text."),
r"\v 1 Some text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_after_number2(self) -> None:
self.assertEqual(
fix_missing_space_after_number(r"\v 2Another verse."),
r"\v 2 Another verse.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_after_number3(self) -> None:
self.assertEqual(
fix_missing_space_after_number(r"\v 5 5Some text."),
r"\v 5 5 Some text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_after_number4(self) -> None:
self.assertEqual(
Expand All @@ -434,7 +434,7 @@ def test_fix_missing_space_after_number4(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_after_number5(self) -> None:
self.assertEqual(
Expand All @@ -449,8 +449,7 @@ def test_fix_missing_space_after_number5(self) -> None:
""",
)

# FIXME 11 gets matched and then split into 1 1
@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_missing_space_after_number6(self) -> None:
self.assertEqual(
Expand All @@ -464,7 +463,7 @@ def test_missing_space_after_number6(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_missing_space_after_number7(self) -> None:
self.assertEqual(
Expand Down Expand Up @@ -494,23 +493,23 @@ def test_missing_space_after_number7(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_number(self) -> None:
self.assertEqual(
fix_missing_space_before_number(r"Wut.1 Some text."),
r"Wut. 1 Some text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_number2(self) -> None:
self.assertEqual(
fix_missing_space_before_number(r"Wut.1 Some text. \v 2 Yo"),
r"Wut. 1 Some text. \v 2 Yo",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_number3(self) -> None:
self.assertEqual(
Expand All @@ -524,7 +523,7 @@ def test_fix_missing_space_before_number3(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_number4(self) -> None:
actual = fix_missing_space_before_number(
Expand All @@ -539,7 +538,7 @@ def test_fix_missing_space_before_number4(self) -> None:
print("Actual: ", actual)
self.assertEqual(actual, expected)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_number5(self) -> None:
self.assertEqual(
Expand All @@ -553,7 +552,7 @@ def test_fix_missing_space_before_number5(self) -> None:
""",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_number6(self) -> None:
actual = fix_missing_space_before_number(
Expand All @@ -568,15 +567,15 @@ def test_fix_missing_space_before_number6(self) -> None:
print("Actual: ", actual)
self.assertEqual(actual, expected)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_verse_marker(self) -> None:
self.assertEqual(
fix_missing_space_before_verse_marker(r"Wut\v 1Some text."),
r"Wut \v 1Some text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_verse_marker2(self) -> None:
self.assertEqual(
Expand All @@ -586,15 +585,15 @@ def test_fix_missing_space_before_verse_marker2(self) -> None:
r"\v 2Another verse. \v 3 This is more text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_verse_marker3(self) -> None:
self.assertEqual(
fix_missing_space_before_verse_marker(r"\v 5 5Some text."),
r"\v 5 5Some text.",
)

@pytest.mark.focus
# @pytest.mark.focus
@pytest.mark.usfm_fixes
def test_fix_missing_space_before_verse_marker4(self) -> None:
self.assertEqual(
Expand Down

0 comments on commit b579d99

Please sign in to comment.