lib.Package: Add unit tests
parse_spec_str(), parse_specs_str(), order_tags(), and __repr__ are pure text processing without test coverage, shared by the dpkg and rpm package manager backends. Add unit tests for valid and invalid spec strings, multi-line input with and without a trailing newline, tag ordering with default values, and the repr layout. Signed-off-by: Jan Lindemann <jan@janware.com> Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
This commit is contained in:
parent
dc101a5a7f
commit
94f7838c0b
2 changed files with 87 additions and 0 deletions
7
test/unit/python/jw/pkg/lib/Package/Makefile
Normal file
7
test/unit/python/jw/pkg/lib/Package/Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
TOPDIR = ../../../../../../..
|
||||
|
||||
include $(TOPDIR)/make/proj.mk
|
||||
include $(JWBDIR)/make/py-run.mk
|
||||
|
||||
all:
|
||||
test: run
|
||||
80
test/unit/python/jw/pkg/lib/Package/test.py
Normal file
80
test/unit/python/jw/pkg/lib/Package/test.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
from jw.pkg.lib.Package import Package, meta_tags
|
||||
|
||||
# -- parse_spec_str --
|
||||
|
||||
p = Package.parse_spec_str(
|
||||
'jw-core|jw|Jan|https://example.com/jw-core|Jan <jan@example.com>'
|
||||
)
|
||||
assert p.name == 'jw-core'
|
||||
assert p.vendor == 'jw'
|
||||
assert p.packager == 'Jan'
|
||||
assert p.url == 'https://example.com/jw-core'
|
||||
assert p.maintainer == 'Jan <jan@example.com>'
|
||||
|
||||
# An empty field is preserved as an empty string
|
||||
p = Package.parse_spec_str('name||||')
|
||||
assert p.name == 'name'
|
||||
assert p.vendor == ''
|
||||
assert p.packager == ''
|
||||
assert p.url == ''
|
||||
assert p.maintainer == ''
|
||||
|
||||
# A custom delimiter works
|
||||
p = Package.parse_spec_str('a,b,c,d,e', delimiter = ',')
|
||||
assert p.name == 'a'
|
||||
assert p.maintainer == 'e'
|
||||
|
||||
# Wrong field counts raise
|
||||
for spec in ('a', 'a|b', 'a|b|c|d', 'a|b|c|d|e|f'):
|
||||
try:
|
||||
Package.parse_spec_str(spec)
|
||||
assert False, f'Should have raised for "{spec}"'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# -- parse_specs_str --
|
||||
|
||||
specs = (
|
||||
'jw-core|jw|Jan|https://example.com/jw-core|Jan\n'
|
||||
'jw-base|jw|Jan|https://example.com/jw-base|Jan'
|
||||
)
|
||||
packages = Package.parse_specs_str(specs)
|
||||
assert [p.name for p in packages] == ['jw-core', 'jw-base']
|
||||
# A trailing newline does not create a phantom package
|
||||
assert len(packages) == 2
|
||||
# A trailing newline is not needed
|
||||
packages = Package.parse_specs_str(specs + '\n')
|
||||
assert [p.name for p in packages] == ['jw-core', 'jw-base']
|
||||
|
||||
# An empty string parses to no packages
|
||||
assert Package.parse_specs_str('') == []
|
||||
|
||||
# -- order_tags --
|
||||
|
||||
mapping = {
|
||||
'maintainer': 'Jan',
|
||||
'name': 'jw-core',
|
||||
'url': 'https://example.com/jw-core',
|
||||
}
|
||||
ordered = Package.order_tags(mapping)
|
||||
assert list(ordered) == meta_tags
|
||||
assert ordered == {
|
||||
'name': 'jw-core',
|
||||
'vendor': '',
|
||||
'packager': '',
|
||||
'url': 'https://example.com/jw-core',
|
||||
'maintainer': 'Jan',
|
||||
}
|
||||
|
||||
# -- __repr__ --
|
||||
|
||||
p = Package.parse_spec_str('jw-core|jw|Jan|url|Jan')
|
||||
assert repr(p) == (
|
||||
'name : jw-core\n'
|
||||
'vendor : jw\n'
|
||||
'packager : Jan\n'
|
||||
'url : url\n'
|
||||
'maintainer : Jan'
|
||||
)
|
||||
|
||||
print('All Package tests passed')
|
||||
Loading…
Reference in a new issue