lib.PackageFilter: Add unit tests
PackageFilterString is pure regex logic without test coverage. Add unit tests for the url=~ filter, packages without a url, whitespace around the operator, and the rejection of unsupported filter definitions. 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
b8d4402fe4
commit
5a17cd6819
2 changed files with 41 additions and 0 deletions
7
test/unit/python/jw/pkg/lib/PackageFilter/Makefile
Normal file
7
test/unit/python/jw/pkg/lib/PackageFilter/Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
TOPDIR = ../../../../../../..
|
||||||
|
|
||||||
|
include $(TOPDIR)/make/proj.mk
|
||||||
|
include $(JWBDIR)/make/py-run.mk
|
||||||
|
|
||||||
|
all:
|
||||||
|
test: run
|
||||||
34
test/unit/python/jw/pkg/lib/PackageFilter/test.py
Normal file
34
test/unit/python/jw/pkg/lib/PackageFilter/test.py
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
from jw.pkg.lib.Package import Package
|
||||||
|
from jw.pkg.lib.PackageFilter import PackageFilterString
|
||||||
|
|
||||||
|
pkg = Package(name = 'jw-core', url = 'https://example.com/jw-core')
|
||||||
|
pkg_other = Package(name = 'jw-base', url = 'https://other.org/jw-base')
|
||||||
|
pkg_nourl = Package(name = 'no-url')
|
||||||
|
|
||||||
|
# -- url=~ filters --
|
||||||
|
|
||||||
|
f = PackageFilterString('url=~example\\.com')
|
||||||
|
assert f.match(pkg)
|
||||||
|
assert not f.match(pkg_other)
|
||||||
|
# A package without a url never matches
|
||||||
|
assert not f.match(pkg_nourl)
|
||||||
|
|
||||||
|
# Whitespace around the operator is tolerated
|
||||||
|
f = PackageFilterString(' url =~ example')
|
||||||
|
assert f.match(pkg)
|
||||||
|
|
||||||
|
# An unanchored regex matches anywhere in the url
|
||||||
|
f = PackageFilterString('url=~jw-core$')
|
||||||
|
assert f.match(pkg)
|
||||||
|
assert not f.match(pkg_other)
|
||||||
|
|
||||||
|
# -- Unsupported definitions raise --
|
||||||
|
|
||||||
|
for definition in ('', 'url=example.com', 'name=jw-core', 'url ~ example'):
|
||||||
|
try:
|
||||||
|
PackageFilterString(definition)
|
||||||
|
assert False, f'Should have raised for "{definition}"'
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
print('All PackageFilter tests passed')
|
||||||
Loading…
Reference in a new issue