conftest.py 868 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from __future__ import annotations
  2. import pytest
  3. from numpy import array, uint8
  4. from minigrid.envs.wfc.config import PATTERN_PATH
  5. class Resources:
  6. def get_pattern(self, image: str) -> str:
  7. return PATTERN_PATH / image
  8. @pytest.fixture(scope="session")
  9. def resources() -> Resources:
  10. return Resources()
  11. @pytest.fixture(scope="session")
  12. def img_redmaze(resources: Resources) -> array:
  13. try:
  14. import imageio # type: ignore
  15. pattern = resources.get_pattern("RedMaze.png")
  16. img = imageio.v2.imread(pattern)
  17. except ImportError:
  18. b = [0, 0, 0]
  19. w = [255, 255, 255]
  20. r = [255, 0, 0]
  21. img = array(
  22. [
  23. [w, w, w, w],
  24. [w, b, b, b],
  25. [w, b, r, b],
  26. [w, b, b, b],
  27. ],
  28. dtype=uint8,
  29. )
  30. return img