test_translations.py 1.6 KB

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