test_translations.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. Tests for translation files.
  3. """
  4. from fnmatch import fnmatch
  5. from os import walk
  6. from os.path import dirname, join
  7. from homeassistant.util.json import load_json
  8. import custom_components.tuya_local as root
  9. from custom_components.tuya_local.helpers.device_config import (
  10. TuyaDeviceConfig,
  11. available_configs,
  12. )
  13. def get_translations():
  14. translations = join(dirname(root.__file__), "translations")
  15. for path, dirs, files in walk(translations):
  16. for file in files:
  17. if fnmatch(file, "*.json"):
  18. yield load_json(join(path, file))
  19. english = None
  20. def get_english():
  21. global english
  22. if english is None:
  23. translations = join(dirname(root.__file__), "translations", "en.json")
  24. json = load_json(translations)
  25. english = json["config"]["step"]["choose_entities"]["data"]
  26. return english
  27. def get_devices():
  28. for device in available_configs():
  29. yield TuyaDeviceConfig(device)
  30. # def subtest_entity_covered(entity):
  31. # strings = get_english()
  32. # TestCase().assertIn(
  33. # entity.config_id,
  34. # strings,
  35. # f"{entity._device.config}: {entity.config_id} is missing a translation",
  36. # )
  37. # @pytest.mark.parametrize("device", get_devices())
  38. # def test_device_covered(device):
  39. # entity = device.primary_entity
  40. # if entity.deprecated:
  41. # subtest_entity_covered(entity)
  42. # for entity in device.secondary_entities():
  43. # if entity.deprecated:
  44. # subtest_entity_covered(entity)