test_gflanguages_api.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright 2022 Google LLC All Rights Reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS-IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. import sys
  18. if sys.version_info < (3, 10):
  19. import importlib_resources as importlib_resources
  20. else:
  21. import importlib.resources as importlib_resources
  22. from gflanguages import (LoadLanguages,
  23. LoadRegions,
  24. LoadScripts)
  25. DATA_DIR = importlib_resources.files("gflanguages") / "data"
  26. def test_LoadLanguages():
  27. with importlib_resources.as_file(DATA_DIR) as data_path:
  28. for langs in [LoadLanguages(),
  29. LoadLanguages(None),
  30. LoadLanguages(data_path)]:
  31. numerals = langs["yi_Hebr"].exemplar_chars.numerals
  32. assert numerals == '- , . % + 0 1 2 3 4 5 6 7 8 9'
  33. def test_LoadScripts():
  34. with importlib_resources.as_file(DATA_DIR) as data_path:
  35. for scripts in [LoadScripts(),
  36. LoadScripts(None),
  37. LoadScripts(data_path)]:
  38. scripts = LoadScripts()
  39. assert scripts["Tagb"].name == 'Tagbanwa'
  40. def test_LoadRegions():
  41. with importlib_resources.as_file(DATA_DIR) as data_path:
  42. for regions in [LoadRegions(),
  43. LoadRegions(None),
  44. LoadRegions(data_path)]:
  45. regions = LoadRegions()
  46. br = regions["BR"]
  47. assert br.name == 'Brazil'
  48. assert br.region_group == ['Americas']