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.2Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
00b632d1cd
commit
ad9c5b581a
1 changed files with 12 additions and 0 deletions
|
|
@ -1,14 +1,25 @@
|
||||||
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
from jw.pkg.lib.ProjectConf import ProjectConf
|
from jw.pkg.lib.ProjectConf import ProjectConf
|
||||||
|
|
||||||
# -- Helper: create temp file and read it --
|
# -- Helper: create temp file and read it --
|
||||||
|
|
||||||
|
_tmpfiles: list[str] = []
|
||||||
|
|
||||||
def _load(text: str) -> ProjectConf:
|
def _load(text: str) -> ProjectConf:
|
||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.conf', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.conf', delete=False) as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
_tmpfiles.append(f.name)
|
||||||
return ProjectConf.read(f.name)
|
return ProjectConf.read(f.name)
|
||||||
|
|
||||||
|
|
||||||
|
def _cleanup():
|
||||||
|
for _p in _tmpfiles:
|
||||||
|
os.unlink(_p)
|
||||||
|
del _p
|
||||||
|
_tmpfiles.clear()
|
||||||
|
|
||||||
# -- Basic construction --
|
# -- Basic construction --
|
||||||
|
|
||||||
pc = _load('[section]\nkey = value\n')
|
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')
|
pc = _load('[section]\nlist = "a", "b", "c"\n')
|
||||||
assert pc.get_list('section', 'list') == ['a', 'b', 'c']
|
assert pc.get_list('section', 'list') == ['a', 'b', 'c']
|
||||||
|
|
||||||
|
_cleanup()
|
||||||
print('All ProjectConf tests passed')
|
print('All ProjectConf tests passed')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue