"""The Summit watermark (framegen/watermark.py) and its setting.""" import pathlib import sys sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from framegen import watermark as wm from framegen.settings import BY_KEY, Settings def test_text_and_default(): assert wm.TEXT == "summit - git.molberg.cloud/alex/summit" spec = BY_KEY["watermark"] assert spec.default is True and spec.choices == (True, False) s = Settings() assert s.watermark is True s.override("watermark", False) assert s.watermark is False def test_it_is_small_and_has_text_in_it(): img = wm.render(1.0) h, w = img.shape[:2] assert h <= 30 and w <= 360 # a thin strip, well under a fifth of a 1080p picture's width assert (img == wm.BG).all(axis=2).mean() < 0.97 # some pixels are text assert (img[0] == wm.BG).all() and (img[-1] == wm.BG).all() # with a margin of box around it half = wm.render(0.5) assert half.shape[1] < w def test_corner_keeps_clear_of_the_stats(): assert wm.corner("top-left") == "bottom-left" assert wm.corner("bottom-right") == "bottom-left" assert wm.corner("bottom-left") == "bottom-right" assert wm.corner("bottom-left", stats_on=False) == "bottom-left" def test_place_in_gl_coordinates(): # picture at (10, 20), 1000x500; a 100x20 panel with a 12 px margin. GL y grows upwards; `top` is its top edge. assert wm.place("bottom-left", 100, 20, 10, 20, 1000, 500, 12) == (22, 52) assert wm.place("bottom-right", 100, 20, 10, 20, 1000, 500, 12) == (898, 52) assert wm.place("top-left", 100, 20, 10, 20, 1000, 500, 12) == (22, 508)