test: Restructure test files
Some checks are pending
website / deploy (push) Blocked by required conditions
website / build (push) Waiting to run

Extract the individual parsing tests (cli, env, rc) and add additional
configuration test file (TConf and config builder).

To extract the fixtures they have to go into an additional 'conftest.py'
file for pytest to recognize and automatically import them, see:
https://docs.pytest.org/en/stable/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files

and:
https://docs.pytest.org/en/stable/how-to/fixtures.html#using-fixtures-from-other-projects
This commit is contained in:
Marty Oehme 2025-11-29 11:18:48 +01:00
parent ff0e6cccfb
commit 13c34b08e2
Signed by: Marty
GPG key ID: 4E535BC19C61886E
6 changed files with 224 additions and 114 deletions

35
test/test_parse_env.py Normal file
View file

@ -0,0 +1,35 @@
from pathlib import Path
from topen import parse_env
class TestEnv:
def test_env_notes_ext(self, isolate_env, monkeypatch):
monkeypatch.setenv("TOPEN_NOTES_DIR", "/blablubb")
monkeypatch.setenv("TOPEN_NOTES_EXT", "rst")
monkeypatch.setenv("TOPEN_NOTES_ANNOT", "qmd")
monkeypatch.setenv("TOPEN_NOTES_EDITOR", "vim")
monkeypatch.setenv("TOPEN_NOTES_QUIET", "true")
env = parse_env()
assert env["notes_dir"] == Path("/blablubb")
assert env["notes_ext"] == "rst"
assert env["notes_annot"] == "qmd"
assert env["notes_editor"] == "vim"
assert env["notes_quiet"] is True
def test_env_task_rc(self, isolate_env, monkeypatch):
monkeypatch.setenv("TASKRC", "/a/dir/that/dont/exist/file")
monkeypatch.setenv("TASKDATA", "~/somewhere/tasks")
env = parse_env()
assert env["task_rc"] == Path("/a/dir/that/dont/exist/file")
assert env["task_data"] == Path("~/somewhere/tasks")
def test_env_parses_boolean_true(self, isolate_env, monkeypatch):
monkeypatch.setenv("TOPEN_NOTES_QUIET", "true")
env = parse_env()
assert env["notes_quiet"] is True
def test_env_parses_boolean_false(self, isolate_env, monkeypatch):
monkeypatch.setenv("TOPEN_NOTES_QUIET", "false")
env = parse_env()
assert env["notes_quiet"] is False