Skip to content

Commit d91eeeb

Browse files
committed
Revert "raise error when id tag doesn't match filename book id"
This reverts commit 8679b78.
1 parent 8679b78 commit d91eeeb

11 files changed

+27
-230
lines changed

machine/corpora/paratext_backup_text_corpus.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,18 @@ def __init__(self, filename: StrPath, include_markers: bool = False, include_all
1919
for sfm_entry in archive.filelist:
2020
book_id = settings.get_book_id(sfm_entry.filename)
2121
if book_id:
22-
text = UsfmZipText(
23-
settings.stylesheet,
24-
settings.encoding,
25-
book_id,
26-
filename,
27-
sfm_entry.filename,
28-
versification,
29-
include_markers,
30-
include_all_text,
31-
settings.name,
22+
texts.append(
23+
UsfmZipText(
24+
settings.stylesheet,
25+
settings.encoding,
26+
book_id,
27+
filename,
28+
sfm_entry.filename,
29+
versification,
30+
include_markers,
31+
include_all_text,
32+
settings.name,
33+
)
3234
)
33-
with text.get_rows() as rows:
34-
row = next(rows, None)
35-
if row and row.ref.book != book_id:
36-
if row.ref.book == "":
37-
raise ValueError(f"The \\id tag in {sfm_entry.filename} is invalid.")
38-
raise ValueError(
39-
f"The \\id tag {row.ref.book} in {sfm_entry.filename}"
40-
f" does not match filename book id {book_id}."
41-
)
42-
texts.append(text)
4335

4436
super().__init__(versification, texts)

machine/corpora/paratext_text_corpus.py

+11-18
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,17 @@ def __init__(self, project_dir: StrPath, include_markers: bool = False, include_
1818
for sfm_filename in Path(project_dir).glob(f"{settings.file_name_prefix}*{settings.file_name_suffix}"):
1919
book_id = settings.get_book_id(sfm_filename.name)
2020
if book_id:
21-
text = UsfmFileText(
22-
settings.stylesheet,
23-
settings.encoding,
24-
book_id,
25-
sfm_filename,
26-
versification,
27-
include_markers,
28-
include_all_text,
29-
settings.name,
21+
texts.append(
22+
UsfmFileText(
23+
settings.stylesheet,
24+
settings.encoding,
25+
book_id,
26+
sfm_filename,
27+
versification,
28+
include_markers,
29+
include_all_text,
30+
settings.name,
31+
)
3032
)
31-
with text.get_rows() as rows:
32-
row = next(rows, None)
33-
if row and row.ref.book != book_id:
34-
if row.ref.book == "":
35-
raise ValueError(f"The \\id tag in {sfm_filename} is invalid.")
36-
raise ValueError(
37-
f"The \\id tag {row.ref.book} in {sfm_filename} does not match filename book id {book_id}."
38-
)
39-
texts.append(text)
4033

4134
super().__init__(versification, texts)

tests/corpora/test_paratext_backup_text_corpus.py

+4-26
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
from pathlib import Path
44
from tempfile import TemporaryDirectory
5-
from typing import Any, ContextManager, Optional
5+
from typing import Any, ContextManager
66

7-
from pytest import raises
8-
from testutils.corpora_test_helpers import (
9-
create_test_paratext_backup,
10-
create_test_paratext_backup_invalid_id,
11-
create_test_paratext_backup_mismatch_id,
12-
)
7+
from testutils.corpora_test_helpers import create_test_paratext_backup
138

149
from machine.corpora import ParatextBackupTextCorpus
1510

@@ -33,27 +28,10 @@ def test_get_text() -> None:
3328
assert not any(jhn.get_rows())
3429

3530

36-
def test_invalid_id() -> None:
37-
with raises(ValueError, match=r"The \\id tag in .* is invalid."):
38-
with _TestEnvironment("invalid_id") as env:
39-
env.corpus.get_text("JDG")
40-
41-
42-
def test_mismatch_id() -> None:
43-
with raises(ValueError, match=r"The \\id tag .* in .* does not match filename book id .*"):
44-
with _TestEnvironment("mismatch_id") as env:
45-
env.corpus.get_text("JDG")
46-
47-
4831
class _TestEnvironment(ContextManager["_TestEnvironment"]):
49-
def __init__(self, project_folder_name: Optional[str] = None) -> None:
32+
def __init__(self) -> None:
5033
self._temp_dir = TemporaryDirectory()
51-
if project_folder_name == "invalid_id":
52-
archive_filename = create_test_paratext_backup_invalid_id(Path(self._temp_dir.name))
53-
elif project_folder_name == "mismatch_id":
54-
archive_filename = create_test_paratext_backup_mismatch_id(Path(self._temp_dir.name))
55-
else:
56-
archive_filename = create_test_paratext_backup(Path(self._temp_dir.name))
34+
archive_filename = create_test_paratext_backup(Path(self._temp_dir.name))
5735
self._corpus = ParatextBackupTextCorpus(archive_filename)
5836

5937
@property

tests/corpora/test_paratext_text_corpus.py

-14
This file was deleted.

tests/testutils/corpora_test_helpers.py

-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
USFM_TEST_PROJECT_PATH = TEST_DATA_PATH / "usfm" / "Tes"
1010
USFM_TARGET_PROJECT_PATH = TEST_DATA_PATH / "usfm" / "target"
1111
USFM_SOURCE_PROJECT_PATH = TEST_DATA_PATH / "usfm" / "source"
12-
USFM_MISMATCH_ID_PROJECT_PATH = TEST_DATA_PATH / "usfm" / "mismatch_id"
13-
USFM_INVALID_ID_PROJECT_PATH = TEST_DATA_PATH / "usfm" / "invalid_id"
1412
USX_TEST_PROJECT_PATH = TEST_DATA_PATH / "usx" / "Tes"
1513
TEXT_TEST_PROJECT_PATH = TEST_DATA_PATH / "txt"
1614
CUSTOM_VERS_PATH = TEST_DATA_PATH / "custom.vrs"
@@ -26,16 +24,6 @@ def create_test_paratext_backup(temp_dir: Path) -> Path:
2624
return temp_dir / "Tes.zip"
2725

2826

29-
def create_test_paratext_backup_invalid_id(temp_dir: Path) -> Path:
30-
shutil.make_archive(str(temp_dir / "invalid_id"), "zip", USFM_INVALID_ID_PROJECT_PATH)
31-
return temp_dir / "invalid_id.zip"
32-
33-
34-
def create_test_paratext_backup_mismatch_id(temp_dir: Path) -> Path:
35-
shutil.make_archive(str(temp_dir / "mismatch_id"), "zip", USFM_MISMATCH_ID_PROJECT_PATH)
36-
return temp_dir / "mismatch_id.zip"
37-
38-
3927
def verse_ref(segment: TextRow) -> VerseRef:
4028
assert isinstance(segment.ref, VerseRef)
4129
return segment.ref

tests/testutils/data/usfm/invalid_id/07JDG.SFM

-5
This file was deleted.

tests/testutils/data/usfm/invalid_id/Settings.xml

-34
This file was deleted.

tests/testutils/data/usfm/invalid_id/custom.vrs

-31
This file was deleted.

tests/testutils/data/usfm/mismatch_id/07JDG.SFM

-5
This file was deleted.

tests/testutils/data/usfm/mismatch_id/Settings.xml

-34
This file was deleted.

tests/testutils/data/usfm/mismatch_id/custom.vrs

-31
This file was deleted.

0 commit comments

Comments
 (0)