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:
Jan Lindemann 2026-09-08 22:37:09 +02:00
commit 5a17cd6819
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,7 @@
TOPDIR = ../../../../../../..
include $(TOPDIR)/make/proj.mk
include $(JWBDIR)/make/py-run.mk
all:
test: run

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