test_wallpaper.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. "river": "river 0.4 closes every layer surface unless a window manager client runs, and none is packaged",
  9. }
  10. def _param(name):
  11. if name in LAB_LIMITS:
  12. return pytest.param(name, marks=pytest.mark.skip(reason=LAB_LIMITS[name]))
  13. if name in KNOWN_GAPS:
  14. return pytest.param(name, marks=pytest.mark.xfail(reason=KNOWN_GAPS[name], strict=True))
  15. return name
  16. WALLPAPER_SESSIONS = [_param(name) for name in KINDS]
  17. @pytest.mark.parametrize("desktop", WALLPAPER_SESSIONS, indirect=True)
  18. def test_engine_draws_the_wallpaper(desktop, engine, tmp_path):
  19. before = tmp_path / "before.png"
  20. try:
  21. desktop.shot(before)
  22. except Unsupported as error:
  23. pytest.skip(str(error))
  24. outputs = desktop.output_names()
  25. assert outputs, f"{desktop.name} lists no output"
  26. process = desktop.client([engine["binary"], "--assets-dir", engine["assets"], "--screen-root", outputs[0],
  27. "--silent", "--fps", "30", engine["wallpaper"]], log=tmp_path / "engine.log")
  28. try:
  29. deadline = time.monotonic() + 45
  30. fraction = 0.0
  31. while time.monotonic() < deadline and fraction < 0.03:
  32. time.sleep(3)
  33. assert process.poll() is None, f"the engine exited with {process.returncode}:\n{(tmp_path / 'engine.log').read_text()[-1500:]}"
  34. after = tmp_path / "after.png"
  35. desktop.shot(after)
  36. fraction = changed_fraction(before, after)
  37. assert fraction >= 0.03, f"{fraction:.0%} of {desktop.name}'s screen changed after the engine started"
  38. finally:
  39. process.terminate()
  40. process.wait(10)