test: Add test for parsing circular env vars
Some checks failed
website / build (push) Has been cancelled
website / deploy (push) Has been cancelled

This commit is contained in:
Marty Oehme 2025-12-08 17:38:23 +01:00
parent 0820b686e5
commit f00d230fd3
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -7,6 +7,7 @@ import pytest
from topen import TConf, build_config from topen import TConf, build_config
class TestTConf: class TestTConf:
def test_paths_are_expanded(self): def test_paths_are_expanded(self):
cfg = TConf.from_dict( cfg = TConf.from_dict(
@ -62,6 +63,17 @@ class TestBuildConfigPrecedence:
cfg = build_config() cfg = build_config()
assert cfg.notes_ext == "from-env" assert cfg.notes_ext == "from-env"
def test_circular_env_vars(self, isolate_env, monkeypatch, fake_id):
"""Test environment variables with circular references."""
for k, v in {
"TOPEN_NOTES_DIR": "$TOPEN_NOTES_DIR/subdir",
"EDITOR": "${EDITOR}_backup",
}.items():
monkeypatch.setenv(k, v)
cfg = build_config()
assert cfg.notes_dir == Path("$TOPEN_NOTES_DIR/subdir/subdir")
assert cfg.notes_editor == "nano"
def test_cli_overrides_env(self, fake_rc, monkeypatch, isolate_env): def test_cli_overrides_env(self, fake_rc, monkeypatch, isolate_env):
fake_rc.write_text("notes.ext=from-rc\n") fake_rc.write_text("notes.ext=from-rc\n")
monkeypatch.setenv("TOPEN_NOTES_EXT", "from-env") monkeypatch.setenv("TOPEN_NOTES_EXT", "from-env")