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