test_wallpaper.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import time
  2. import pytest
  3. from conftest import KINDS, Unsupported, changed_fraction
  4. # what is known not to work yet, each reason is a thing to fix: the test starts passing and strict xfail says so
  5. KNOWN_GAPS = {}
  6. # what the lab cannot show, not the engine
  7. LAB_LIMITS = {}
  8. def _param(name):
  9. if name in LAB_LIMITS:
  10. return pytest.param(name, marks=pytest.mark.skip(reason=LAB_LIMITS[name]))
  11. if name in KNOWN_GAPS:
  12. return pytest.param(name, marks=pytest.mark.xfail(reason=KNOWN_GAPS[name], strict=True))
  13. return name
  14. WALLPAPER_SESSIONS = [_param(name) for name in KINDS]
  15. @pytest.mark.parametrize("desktop", WALLPAPER_SESSIONS, indirect=True)
  16. def test_engine_draws_the_wallpaper(desktop, engine, tmp_path):
  17. before = tmp_path / "before.png"
  18. try:
  19. desktop.shot(before)
  20. except Unsupported as error:
  21. pytest.skip(str(error))
  22. outputs = desktop.output_names()
  23. assert outputs, f"{desktop.name} lists no output"
  24. process = desktop.client([engine["binary"], "--assets-dir", engine["assets"], "--screen-root", outputs[0],
  25. "--silent", "--fps", "30", engine["wallpaper"]], log=tmp_path / "engine.log")
  26. try:
  27. deadline = time.monotonic() + 45
  28. fraction = 0.0
  29. while time.monotonic() < deadline and fraction < 0.03:
  30. time.sleep(3)
  31. assert process.poll() is None, f"the engine exited with {process.returncode}:\n{(tmp_path / 'engine.log').read_text()[-1500:]}"
  32. after = tmp_path / "after.png"
  33. desktop.shot(after)
  34. fraction = changed_fraction(before, after)
  35. assert fraction >= 0.03, f"{fraction:.0%} of {desktop.name}'s screen changed after the engine started"
  36. finally:
  37. process.terminate()
  38. process.wait(10)