-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Don't repeat yourself * Use the new-fangled importlib.resources * Use backport until 3.9 is dead
- Loading branch information
1 parent
1037e30
commit a495359
Showing
3 changed files
with
38 additions
and
45 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
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
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,22 +1,24 @@ | ||
from gflanguages import DATA_DIR | ||
from importlib_resources import files | ||
import glob | ||
import os | ||
import pytest | ||
from gflanguages import languages_public_pb2 | ||
from google.protobuf import text_format | ||
|
||
|
||
languages_dir = os.path.join(DATA_DIR, "languages") | ||
languages_dir = files("gflanguages.data").joinpath("languages") | ||
textproto_files = [ | ||
os.path.basename(x) for x in glob.iglob(os.path.join(languages_dir, "*.textproto")) | ||
file.name for file in languages_dir.iterdir() if file.name.endswith(".textproto") | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("lang_code", textproto_files) | ||
def test_parsable(lang_code): | ||
with open(os.path.join(languages_dir, lang_code), "r", encoding="utf-8") as f: | ||
msg = text_format.Parse(f.read(), languages_public_pb2.LanguageProto()) | ||
assert msg.id | ||
assert msg.language | ||
assert msg.script | ||
assert msg.population is not None | ||
f = languages_dir.joinpath(lang_code) | ||
msg = text_format.Parse( | ||
f.read_text(encoding="utf-8"), languages_public_pb2.LanguageProto() | ||
) | ||
assert msg.id | ||
assert msg.language | ||
assert msg.script | ||
assert msg.population is not None |