From ad9c5b581a5dd7d96586c0512aac9b0272832d95 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 3 Jul 2026 10:14:32 +0200 Subject: [PATCH] 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 --- test/unit/python/jw/pkg/lib/ProjectConf/test.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/unit/python/jw/pkg/lib/ProjectConf/test.py b/test/unit/python/jw/pkg/lib/ProjectConf/test.py index 36a3f558..6f359ece 100644 --- a/test/unit/python/jw/pkg/lib/ProjectConf/test.py +++ b/test/unit/python/jw/pkg/lib/ProjectConf/test.py @@ -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')