test: Add TConf class tests
This commit is contained in:
parent
cb5e38b503
commit
620a7bc401
1 changed files with 22 additions and 1 deletions
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from topen import OPTIONS, parse_cli, parse_env, parse_rc
|
from topen import OPTIONS, TConf, parse_cli, parse_env, parse_rc
|
||||||
|
|
||||||
|
|
||||||
class TestCli:
|
class TestCli:
|
||||||
|
|
@ -35,6 +35,8 @@ class TestCli:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def isolate_env(monkeypatch):
|
def isolate_env(monkeypatch):
|
||||||
# delete all existing env vars that could interfere
|
# delete all existing env vars that could interfere
|
||||||
|
monkeypatch.delenv("EDITOR", raising=False)
|
||||||
|
monkeypatch.delenv("VISUAL", raising=False)
|
||||||
for opt in OPTIONS.values():
|
for opt in OPTIONS.values():
|
||||||
if opt.env:
|
if opt.env:
|
||||||
monkeypatch.delenv(opt.env, raising=False)
|
monkeypatch.delenv(opt.env, raising=False)
|
||||||
|
|
@ -86,3 +88,22 @@ class TestRcFile:
|
||||||
assert rc_cfg["notes_annot"] == "Boo!"
|
assert rc_cfg["notes_annot"] == "Boo!"
|
||||||
assert rc_cfg["notes_editor"] == "micro"
|
assert rc_cfg["notes_editor"] == "micro"
|
||||||
assert rc_cfg["notes_quiet"] is True
|
assert rc_cfg["notes_quiet"] is True
|
||||||
|
|
||||||
|
|
||||||
|
class TestTConf:
|
||||||
|
def test_paths_are_expanded(self):
|
||||||
|
cfg = TConf.from_dict(
|
||||||
|
{
|
||||||
|
"task_data": "~/somewhere/tasks",
|
||||||
|
"task_id": 0,
|
||||||
|
"task_rc": "$HOME/taskrc",
|
||||||
|
"notes_dir": "$HOME/notes",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert cfg.task_data == Path("~/somewhere/tasks").expanduser()
|
||||||
|
assert cfg.task_rc == Path("~/taskrc").expanduser()
|
||||||
|
assert cfg.notes_dir == Path("~/notes").expanduser()
|
||||||
|
|
||||||
|
def test_default_notes_sub_dir(self):
|
||||||
|
cfg = TConf.from_dict({"task_data": "~/my/tasks", "task_id": 0})
|
||||||
|
assert cfg.notes_dir == Path("~/my/tasks/notes").expanduser()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue