lib.version.Dependency: Beautify exceptions

Add a dependent_package parameter to Dependency's constructor, and use it
in exceptions the class raises.
This commit is contained in:
Jan Lindemann 2026-09-10 07:41:32 +02:00
commit 6b13ae1212
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 43 additions and 31 deletions

View file

@ -1,6 +1,3 @@
import io
from jw.pkg.lib.log import add_capture_stream, rm_capture_stream
from jw.pkg.lib.version import Component, Dependency, Syntax, Version
class FakeApp:
@ -82,17 +79,13 @@ assert d.constraint_str(untemplated=False, include_revision=False) == \
# untemplated=False keeps the specifiers as written
d = Dependency('foo = VERSION', app.get_version)
assert d.constraint_str(untemplated = False) == 'foo = VERSION'
# REVISION resolves to the revision part
d = Dependency('foo = REVISION', app.get_version)
assert d.constraint_str() == 'foo = 45'
assert d.constraint_str(untemplated = False) == 'foo = REVISION'
# A bare REVISION warns: RPM reads a bare number as a version
buf = io.StringIO()
sd = add_capture_stream(buf)
d = Dependency('foo = REVISION', app.get_version)
assert d.constraint_str() == 'foo = 45'
assert 'not a release constraint' in buf.getvalue()
rm_capture_stream(sd)
# A bare REVISION is rejected on the grounds that is assumed that
# the user wanted VERSION instead
try:
Dependency('foo = REVISION', app.get_version).constraint_str()
assert False, 'Should have raised'
except Dependency.Error:
pass
# The lookup uses the base name, not the subpackage name
d = Dependency('foo-devel = VERSION', app.get_version)