test_parsable.py 769 B

12345678910111213141516171819202122232425262728
  1. import glob
  2. import os
  3. import pytest
  4. import sys
  5. from gflanguages import languages_public_pb2
  6. from google.protobuf import text_format
  7. if sys.version_info < (3, 10):
  8. from importlib_resources import files
  9. else:
  10. from importlib.resources import files
  11. languages_dir = files("gflanguages.data").joinpath("languages")
  12. textproto_files = [
  13. file.name for file in languages_dir.iterdir() if file.name.endswith(".textproto")
  14. ]
  15. @pytest.mark.parametrize("lang_code", textproto_files)
  16. def test_parsable(lang_code):
  17. f = languages_dir.joinpath(lang_code)
  18. msg = text_format.Parse(
  19. f.read_text(encoding="utf-8"), languages_public_pb2.LanguageProto()
  20. )
  21. assert msg.id
  22. assert msg.language
  23. assert msg.script
  24. assert msg.population is not None