-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Tests | ||
|
||
This package contains tests for the translation file. | ||
Run them using pytest against the repository root. | ||
|
||
```shell | ||
pip install pytest | ||
pytest -v | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,25 @@ | ||
from pathlib import Path | ||
|
||
BASE_PATH = Path(__file__).resolve().parent.parent | ||
TRANSLATION_FILE = BASE_PATH/"master_dv.divehi.txt" | ||
|
||
class QuranCorpus: | ||
""" | ||
Simple wrapper class to read | ||
content from master_dv.divehi.txt | ||
""" | ||
|
||
BASE_PATH = Path(__file__).resolve().parent.parent | ||
TRANSLATION_FILE = BASE_PATH / "master_dv.divehi.txt" | ||
|
||
@staticmethod | ||
def read_all(): | ||
with open(QuranCorpus.TRANSLATION_FILE, "r") as f: | ||
return f.read() | ||
|
||
@staticmethod | ||
def read_lines(): | ||
with open(QuranCorpus.TRANSLATION_FILE, "r") as f: | ||
for line in f: | ||
if line.startswith("\n") or line.startswith("#"): | ||
continue | ||
|
||
yield line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
from . import TRANSLATION_FILE | ||
from . import QuranCorpus | ||
|
||
|
||
def test_line_count(): | ||
""" | ||
Number of lines in translation files must == 6236 | ||
""" | ||
with open(TRANSLATION_FILE, "r") as f: | ||
lines = [line for line in f.readlines() if not line.startswith("#")] | ||
assert len(lines) == 6236, f"Expected 6236 lines, got {len(lines)}" | ||
lines = list(QuranCorpus.read_lines()) | ||
assert len(lines) == 6236, f"Expected 6236 lines, got {len(lines)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters