# Development

From a clone of the source, after `pip install -e . pytest`. A copy started from
the clone keeps its settings where an installed one does; give it a folder of its own with
`--data-dir` if both are on the same computer.

```
python -m pytest                 # runs against a fake KVM, no hardware needed
ruff check . && mypy             # the other two checks every push gets (pip install ruff mypy)
python -m tests.demo             # wall with fake KVMs in every state: http://127.0.0.1:8788/
python -m tests.demo --fresh     # the same fakes, starting from the first-run setup
```

The demo's sign-in password is `DEMO_PASSWORD` in `tests/demo.py`.

Two files of tests run the page itself in a real browser, pressing what a person presses:
`tests/test_in_a_browser.py`, and `tests/test_in_a_browser_with_the_program_itself.py` for what
ends in a restart (an update, a move to HTTPS). They need Playwright and a browser for it, which
are for those tests only: nothing qKVM is installed with. Without them the files are skipped.

```
pip install playwright && python -m playwright install chromium
python -m pytest tests/test_in_a_browser.py tests/test_in_a_browser_with_the_program_itself.py
```

A test that passes alone and fails on a busy computer (GitHub's runners are slow ones) takes
something for granted about time. `tools/under_load.py` runs tests the way a busy computer does,
so that such a failure happens on purpose before it is fixed, and is seen gone after:

```
python tools/under_load.py --copies 6 --burners 12 --cores 0-7 -- tests/test_live.py   # six at once beside twelve busy processes, on eight cores
python tools/under_load.py --late 10:0 --repeat 20 -- tests/test_jetkvm.py            # every event loop held up 10 ms at every turn
```

Such a test waits for what it means instead of a moment of the clock; where the time is a limit of
the program's, it stays, and the test measures it with the program's own clock.

An update is tried on a data folder the released version before it made: `tests/fixtures/data-0.3.2.tar`,
made by 0.3.2 as published, run as a person runs it, with accounts, devices, alerts, history and
an export (`tools/make_0_3_2_data.py` says how; every name and secret in it is made up for it).
`tests/test_a_data_folder_of_0_3_2.py` opens it with the version of today; with
`QKVM_RELEASED_0_3_2` naming the released 0.3.2's source, it also starts that 0.3.2 again on the
folder afterwards, as a person who goes back would.
