Files
kadence/desktop/tests/test_placement.py
T
timka123andClaude Opus 5 ec7eedbc66 style: say which lint rules this repo keeps, then keep them
`[tool.ruff]` set a line length and a target version and nothing else, so which
rules ran depended on the installed ruff's defaults — fine while nobody ran it,
not fine for a CI job that can turn a push red because a tool changed its mind.

The set is named explicitly (E, F, I, UP, SIM, B, RUF) with three ignores that
are each a real decision rather than a shrug: B008, because FastAPI's whole
dependency idiom is a call in a default argument; E501, because wrapping prose
is a formatter's business; and RUF001, because the reports and the bot speak
Russian and "ambiguous character" is the wrong complaint about a string the
user is meant to read.

The 73 findings that remained are fixed — mostly `datetime.timezone.utc` →
`datetime.UTC`, `typing.Callable` → `collections.abc.Callable`, import order,
and unused `noqa` markers — plus seven by hand: `contextlib.suppress` for two
try/except/pass pairs, unpacking instead of list concatenation, one negated
return.

`ruff format` is deliberately *not* adopted: it would reformat 51 files, and
some of the layout here is hand-set (the comment tables, the DNS wire-format
structs) in ways a formatter flattens.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-22 17:28:57 +03:00

53 lines
2.0 KiB
Python

"""The mini timer's corner geometry.
A pure function, so it is worth pinning down: this is the sort of arithmetic
that silently puts a window half off the screen on somebody else's monitor.
"""
from __future__ import annotations
import pytest
from kadence_desktop.integrations.placement import CORNER_LABELS, CORNERS, Rect, point_for
SCREEN = Rect(0, 0, 1536, 960)
SIZE = (252, 152)
def test_each_corner_lands_where_its_name_says():
assert point_for("top-left", SCREEN, SIZE, 24) == (24, 24)
assert point_for("top-right", SCREEN, SIZE, 24) == (1260, 24)
assert point_for("bottom-left", SCREEN, SIZE, 24) == (24, 784)
assert point_for("bottom-right", SCREEN, SIZE, 24) == (1260, 784)
def test_edge_centres_and_centre_are_centred():
centre_x = (1536 - 252) // 2
assert point_for("top-centre", SCREEN, SIZE, 24) == (centre_x, 24)
assert point_for("bottom-centre", SCREEN, SIZE, 24) == (centre_x, 784)
assert point_for("centre", SCREEN, SIZE, 24) == (centre_x, (960 - 152) // 2)
def test_a_margin_of_zero_hugs_the_edge():
assert point_for("bottom-right", SCREEN, SIZE, 0) == (1536 - 252, 960 - 152)
def test_the_screen_offset_is_respected_on_a_second_monitor():
"""A monitor to the right of the primary one starts at a non-zero x."""
second = Rect(1536, 0, 1920, 1080)
assert point_for("top-right", second, SIZE, 24) == (1536 + 1920 - 252 - 24, 24)
assert point_for("bottom-left", second, SIZE, 24) == (1536 + 24, 1080 - 152 - 24)
@pytest.mark.parametrize("corner", [c for c in CORNERS if c != "remember"])
def test_the_window_never_leaves_the_screen(corner):
"""Even on a screen smaller than the window, or with a silly margin."""
tiny = Rect(0, 0, 200, 120)
x, y = point_for(corner, tiny, SIZE, 400)
assert x >= tiny.x and y >= tiny.y
assert x <= tiny.x + max(tiny.width - SIZE[0], 0)
assert y <= tiny.y + max(tiny.height - SIZE[1], 0)
def test_every_corner_has_a_label_for_the_settings_page():
assert set(CORNER_LABELS) == set(CORNERS)