Skip to content

Commit e284381

Browse files
mshannon-silCopilot
andcommitted
Move memory Paratext classes to testutils and remove filter_tokens_by_chapter export
- Move MemoryParatextProjectFileHandler and MemoryParatextProjectTextUpdater to tests/testutils - Remove MemoryParatextProjectFileHandler and MemoryParatextProjectTextUpdater from machine/corpora - Remove filter_tokens_by_chapter from public exports - Update all imports to use testutils locations Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e7f3c2c commit e284381

11 files changed

Lines changed: 39 additions & 54 deletions

machine/corpora/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from .file_paratext_project_versification_error_detector import FileParatextProjectVersificationErrorDetector
1515
from .flatten import flatten
1616
from .memory_alignment_collection import MemoryAlignmentCollection
17-
from .memory_paratext_project_file_handler import MemoryParatextProjectFileHandler
18-
from .memory_paratext_project_text_updater import MemoryParatextProjectTextUpdater
1917
from .memory_stream_container import MemoryStreamContainer
2018
from .memory_text import MemoryText
2119
from .multi_key_ref import MultiKeyRef
@@ -29,7 +27,7 @@
2927
from .paratext_project_settings import ParatextProjectSettings
3028
from .paratext_project_settings_parser_base import ParatextProjectSettingsParserBase
3129
from .paratext_project_terms_parser_base import KeyTerm, ParatextProjectTermsParserBase
32-
from .paratext_project_text_updater_base import ParatextProjectTextUpdaterBase, filter_tokens_by_chapter
30+
from .paratext_project_text_updater_base import ParatextProjectTextUpdaterBase
3331
from .paratext_project_versification_error_detector_base import ParatextProjectVersificationErrorDetectorBase
3432
from .paratext_text_corpus import ParatextTextCorpus
3533
from .place_markers_usfm_update_block_handler import PlaceMarkersAlignmentInfo, PlaceMarkersUsfmUpdateBlockHandler
@@ -117,14 +115,11 @@
117115
"FileParatextProjectTermsParser",
118116
"FileParatextProjectTextUpdater",
119117
"FileParatextProjectVersificationErrorDetector",
120-
"filter_tokens_by_chapter",
121118
"flatten",
122119
"is_scripture",
123120
"KeyTerm",
124121
"lowercase",
125122
"MemoryAlignmentCollection",
126-
"MemoryParatextProjectFileHandler",
127-
"MemoryParatextProjectTextUpdater",
128123
"MemoryStreamContainer",
129124
"MemoryText",
130125
"MultiKeyRef",

machine/corpora/memory_paratext_project_file_handler.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

machine/corpora/memory_paratext_project_text_updater.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/corpora/test_paratext_project_terms_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Dict, List, Optional
22

3-
from testutils.default_paratext_project_settings import DefaultParatextProjectSettings
3+
from testutils.memory_paratext_project_file_handler import DefaultParatextProjectSettings
44
from testutils.memory_paratext_project_terms_parser import MemoryParatextProjectTermsParser
55

66
from machine.corpora import KeyTerm, ParatextProjectSettings, ParatextProjectTermsParserBase

tests/corpora/test_update_usfm_parser_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from typing import Iterable, List, Optional, Sequence, Tuple, Union
22

33
from testutils.corpora_test_helpers import USFM_TEST_PROJECT_PATH, ignore_line_endings
4-
from testutils.default_paratext_project_settings import DefaultParatextProjectSettings
4+
from testutils.memory_paratext_project_file_handler import DefaultParatextProjectSettings, MemoryParatextProjectTextUpdater
55

66
from machine.corpora import (
77
FileParatextProjectTextUpdater,
8-
MemoryParatextProjectTextUpdater,
98
ScriptureRef,
109
UpdateUsfmMarkerBehavior,
1110
UpdateUsfmRow,

tests/corpora/test_usfm_versification_error_detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from io import StringIO
22
from typing import Dict, List, Optional
33

4-
from testutils.default_paratext_project_settings import DefaultParatextProjectSettings
4+
from testutils.memory_paratext_project_file_handler import DefaultParatextProjectSettings
55
from testutils.memory_paratext_project_versification_error_detector import (
66
MemoryParatextProjectVersificationErrorDetector,
77
)

tests/punctuation_analysis/test_paratext_project_quote_convention_detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Dict, List, Optional
22

3-
from testutils.default_paratext_project_settings import DefaultParatextProjectSettings
3+
from testutils.memory_paratext_project_file_handler import DefaultParatextProjectSettings
44
from testutils.memory_paratext_project_quote_convention_detector import MemoryParatextProjectQuoteConventionDetector
55

66
from machine.corpora import ParatextProjectSettings

tests/testutils/default_paratext_project_settings.py renamed to tests/testutils/memory_paratext_project_file_handler.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
1-
from typing import Optional
1+
from io import BytesIO
2+
from typing import BinaryIO, Dict, Optional
23

3-
from machine.corpora import ParatextProjectSettings, UsfmStylesheet
4+
from machine.corpora import ParatextProjectFileHandler, ParatextProjectSettings, UsfmStylesheet
5+
from machine.corpora.paratext_project_text_updater_base import ParatextProjectTextUpdaterBase
46
from machine.scripture import ORIGINAL_VERSIFICATION, Versification
57

68

9+
class MemoryParatextProjectFileHandler(ParatextProjectFileHandler):
10+
def __init__(self, files: Dict[str, str]) -> None:
11+
self.files = files
12+
13+
def exists(self, file_name: str) -> bool:
14+
return file_name in self.files
15+
16+
def open(self, file_name: str) -> BinaryIO:
17+
return BytesIO(self.files[file_name].encode("utf-8"))
18+
19+
def find(self, extension: str) -> Optional[str]:
20+
for name in self.files:
21+
if name.endswith(extension):
22+
return name
23+
return None
24+
25+
def create_stylesheet(self, file_name: str) -> UsfmStylesheet:
26+
return UsfmStylesheet(file_name)
27+
28+
29+
class MemoryParatextProjectTextUpdater(ParatextProjectTextUpdaterBase):
30+
def __init__(self, files: Dict[str, str], settings: ParatextProjectSettings) -> None:
31+
super().__init__(MemoryParatextProjectFileHandler(files), settings)
32+
33+
734
class DefaultParatextProjectSettings(ParatextProjectSettings):
835
def __init__(
936
self,

tests/testutils/memory_paratext_project_quote_convention_detector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Dict
22

3-
from machine.corpora import MemoryParatextProjectFileHandler, ParatextProjectSettings
3+
from machine.corpora import ParatextProjectSettings
44
from machine.punctuation_analysis import ParatextProjectQuoteConventionDetector
55

6-
from .default_paratext_project_settings import DefaultParatextProjectSettings
6+
from .memory_paratext_project_file_handler import DefaultParatextProjectSettings, MemoryParatextProjectFileHandler
77

88

99
class MemoryParatextProjectQuoteConventionDetector(ParatextProjectQuoteConventionDetector):

tests/testutils/memory_paratext_project_terms_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Dict, Optional
22

3-
from machine.corpora import MemoryParatextProjectFileHandler, ParatextProjectSettings, ParatextProjectTermsParserBase
3+
from machine.corpora import ParatextProjectSettings, ParatextProjectTermsParserBase
44

5-
from .default_paratext_project_settings import DefaultParatextProjectSettings
5+
from .memory_paratext_project_file_handler import DefaultParatextProjectSettings, MemoryParatextProjectFileHandler
66

77

88
class MemoryParatextProjectTermsParser(ParatextProjectTermsParserBase):

0 commit comments

Comments
 (0)