TestThemes.py 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (c) 2021 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import json # To parse the deprecated icons files.
  4. import os # To find the theme folders.
  5. import pytest
  6. theme_base = os.path.join(os.path.split(__file__)[0], "..", "resources", "themes")
  7. theme_paths = [os.path.join(theme_base, theme_folder) for theme_folder in os.listdir(theme_base) if os.path.isdir(os.path.join(theme_base, theme_folder))]
  8. @pytest.mark.parametrize("theme_path", theme_paths)
  9. def test_deprecatedIconsExist(theme_path: str) -> None:
  10. icons_folder = os.path.join(theme_path, "icons")
  11. deprecated_icons_file = os.path.join(icons_folder, "deprecated_icons.json")
  12. if not os.path.exists(deprecated_icons_file):
  13. return # No deprecated icons file, there is nothing to go wrong.
  14. # Find out which icons exist in this theme file.
  15. existing_icons = {}
  16. for size in [subfolder for subfolder in os.listdir(icons_folder) if os.path.isdir(os.path.join(icons_folder, subfolder))]:
  17. existing_icons[size] = set(os.path.splitext(fname)[0] for fname in os.listdir(os.path.join(icons_folder, size)))
  18. with open(deprecated_icons_file) as f:
  19. deprecated_icons = json.load(f)
  20. for entry in deprecated_icons.values():
  21. assert "new_icon" in entry # For each deprecated icon we must know which icon replaced it.
  22. new_icon = entry["new_icon"]
  23. assert "size" in entry
  24. size = entry["size"]
  25. assert size in existing_icons # The replacement icon must have a size that exists.
  26. assert new_icon in existing_icons[size] # The new icon must exist for that size.