lib.ProjectConf: Clean up temp files

The _load() helper in test/unit/python/jw/pkg/lib/ProjectConf/test.py uses tempfile.NamedTemporaryFile(..., delete=False) but never removes the created files. Each test call leaked a .conf file in /tmp.

Track all created paths in a _tmpfiles list and call _cleanup() at the end of the test to unlink them.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-07-03 10:14:32 +02:00
commit ad9c5b581a
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -1,14 +1,25 @@
import os
import tempfile
from jw.pkg.lib.ProjectConf import ProjectConf
# -- Helper: create temp file and read it --
_tmpfiles: list[str] = []
def _load(text: str) -> ProjectConf:
with tempfile.NamedTemporaryFile(mode='w', suffix='.conf', delete=False) as f:
f.write(text)
f.flush()
_tmpfiles.append(f.name)
return ProjectConf.read(f.name)
def _cleanup():
for _p in _tmpfiles:
os.unlink(_p)
del _p
_tmpfiles.clear()
# -- Basic construction --
pc = _load('[section]\nkey = value\n')
@ -250,4 +261,5 @@ assert pc.get_str('section', 'not_a_key') == '[bracket]'
pc = _load('[section]\nlist = "a", "b", "c"\n')
assert pc.get_list('section', 'list') == ['a', 'b', 'c']
_cleanup()
print('All ProjectConf tests passed')