test_wallpaper.py 2.0 KB

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