From 5a17cd68198ef0e100038f49d75d70074b8f8294 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 8 Sep 2026 22:37:09 +0200 Subject: [PATCH] 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 Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1 --- .../python/jw/pkg/lib/PackageFilter/Makefile | 7 ++++ .../python/jw/pkg/lib/PackageFilter/test.py | 34 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/unit/python/jw/pkg/lib/PackageFilter/Makefile create mode 100644 test/unit/python/jw/pkg/lib/PackageFilter/test.py diff --git a/test/unit/python/jw/pkg/lib/PackageFilter/Makefile b/test/unit/python/jw/pkg/lib/PackageFilter/Makefile new file mode 100644 index 00000000..de693650 --- /dev/null +++ b/test/unit/python/jw/pkg/lib/PackageFilter/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../../../../../.. + +include $(TOPDIR)/make/proj.mk +include $(JWBDIR)/make/py-run.mk + +all: +test: run diff --git a/test/unit/python/jw/pkg/lib/PackageFilter/test.py b/test/unit/python/jw/pkg/lib/PackageFilter/test.py new file mode 100644 index 00000000..f7c985bd --- /dev/null +++ b/test/unit/python/jw/pkg/lib/PackageFilter/test.py @@ -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')