test + lib: Fix miscellanous bugs and inconsistencies #46

Merged
Jan Lindemann merged 8 commits from jan/feature/20260704-test-fix-test-py-duplicate-module-name-error into master 2026-07-04 07:46:09 +02:00 AGit
9 changed files with 49 additions and 49 deletions

View file

@ -112,7 +112,7 @@ class CmdBuild(Cmd): # export
return ret
def add_dep_tree(cur, prereq_types, tree, all_deps):
log(DEBUG, 'Adding deps "{" ".join(prereq_types)}" of module {cur)')
log(DEBUG, f'Adding deps "{" ".join(prereq_types)}" of module {cur}')
if cur in all_deps:
log(DEBUG, 'Already handled module "{cur}"')
return 0

View file

@ -112,18 +112,6 @@ class DistroContext(FilesContext):
ec = Local()
return (await get(src_uri, content_filter = ProcFilterGpg(ec = ec))).stdout
def _matches_host_prefix(path: str) -> bool:
return re.match(r'^' + host_root_in_tar, path) is not None
def _crop_host_prefix(path: str) -> bool:
return re.sub(r'^' + host_root_in_tar, '', path) is not None
def _crop_default_prefix(path: str) -> bool:
return re.sub(default_rx, '', path) is not None
def _matches_default_prefix(path: str) -> bool:
return re.match(r'^default', path) is not None
def _is_needed_secret(path: str) -> bool:
return path in secret_paths

View file

@ -66,7 +66,7 @@ class CopyContext:
return self.__dst
async def _run(self) -> None:
await self._run()
raise NotImplementedError('CopyContext._run() must be overridden')
async def run(self) -> None:
await self._run()

View file

@ -29,10 +29,10 @@ class Distro(abc.ABC):
default_pkg_filter: PackageFilter | None = None,
) -> None:
if id is None:
raise ValueError('Tried to instaniate Distro without id')
raise ValueError('Tried to instantiate Distro without id')
if ec is None:
raise ValueError(
f'Tried to instaniate Distro "{id}" without execution context'
f'Tried to instantiate Distro "{id}" without execution context'
)
self.__exec_context = ec
self.__id: str | None = None

View file

@ -63,7 +63,7 @@ class Uri:
def scheme(self) -> str:
ret = self.__p.scheme
if not ret:
return 'file://'
return 'file'
return ret
@cached_property

0
test/__init__.py Normal file
View file

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')

View file

@ -19,7 +19,7 @@ assert '<hidden>' in u.safe_full_with_username # safe version hides password
# Scheme defaults to file
u = Uri('/local/path')
assert u.scheme == 'file://'
assert u.scheme == 'file'
assert u.protocol == 'file'
# Pimp returns existing Uri unchanged