Update for newer RPM

python < 4.14.2 returned bytes, but that is now changed to return
decoded strings.

Once Kobo is updated to work with newer RPM, these changes are still
needed to get the test suite passing.

Tox configuration is updated to run tests on multiple versions of
python. It should now be sufficient to run it without installing any
Python packages first.

Relates: https://bugzilla.redhat.com/show_bug.cgi?id=1713107
Relates: https://github.com/release-engineering/kobo/pull/115
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-06-05 08:43:31 +02:00
commit 86c951c466
4 changed files with 21 additions and 27 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ noarch/*
.coverage
htmlcov/
tests/repo
.tox

View file

@ -37,16 +37,6 @@ def formatsize(size):
return '{0:.{1}f} {2}'.format(size, prec, chosen)
def to_utf8(text):
encodings = ["ascii", "utf8", "latin1", "latin2"]
for encoding in encodings:
try:
return text.decode(encoding)
except UnicodeDecodeError:
pass
return text.decode("ascii", "ignore")
clogs = {}
@ -61,7 +51,7 @@ class SimpleRpmWrapperWithChangelog(kobo.pkgset.SimpleRpmWrapper):
ts = kwargs.pop("ts", None)
header = kobo.rpmlib.get_rpm_header(file_path, ts=ts)
self.summary = kobo.rpmlib.get_header_field(header, "summary").decode('utf-8')
self.summary = kobo.rpmlib.get_header_field(header, "summary")
if self.sourcerpm:
key = self.sourcerpm
@ -106,10 +96,10 @@ def get_changelog_diff_from_headers(old, new, max_records=-1):
result = []
try:
old_time = old_changelog[0].time
old_nvr = LooseVersion(to_utf8(old_changelog[0].name).rsplit(None, 1)[-1])
old_nvr = LooseVersion(old_changelog[0].name.rsplit(None, 1)[-1])
while new_changelog:
entry = new_changelog.pop(0)
new_nvr = LooseVersion(to_utf8(entry.name).rsplit(None, 1)[-1])
new_nvr = LooseVersion(entry.name.rsplit(None, 1)[-1])
if entry.time < old_time or (
entry.time == old_time and new_nvr <= old_nvr
):
@ -375,7 +365,7 @@ class ComposeChangelog(object):
data["changelog"] = []
for i in get_changelog_diff_from_headers(old_package, new_package, max_logs):
data["changelog"].append("* %s %s\n%s" % (i.ctime, to_utf8(i.name), to_utf8(i.text)))
data["changelog"].append("* %s %s\n%s" % (i.ctime, i.name, i.text))
# TODO: comps, system release
# if rpm.versionCompare(old_package, new_package.header) == -1:

View file

@ -28,7 +28,7 @@ DUMMY_FIREFOX = {
'old_rpms': ['Dummy-firefox'],
'common_rpms': ['Dummy-firefox'],
'rpms': ['Dummy-firefox'],
'changelog': [u'* Tue Mar 15 2016 Lubomír Sedlář <lubomir.sedlar@gmail.com> - 1:0.1.0-1\n- new version'],
'changelog': ['* Tue Mar 15 2016 Lubomír Sedlář <lubomir.sedlar@gmail.com> - 1:0.1.0-1\n- new version'],
'added_rpms': [],
'dropped_rpms': [],
'nvr': 'Dummy-firefox-1:0.1.0-1',
@ -60,7 +60,7 @@ DUMMY_CLOUD_INIT = {
'old_rpms': ['cloud-init'],
'common_rpms': ['cloud-init'],
'rpms': ['cloud-init'],
'changelog': [u'* Tue Sep 05 2017 Lubomír Sedlář <lsedlar@redhat.com> - 0.7.9-9.module_f8c7dcdc\n- First release'],
'changelog': ['* Tue Sep 05 2017 Lubomír Sedlář <lsedlar@redhat.com> - 0.7.9-9.module_f8c7dcdc\n- First release'],
'added_rpms': [],
'dropped_rpms': [],
'nvr': 'cloud-init-0.7.9-9.module_f8c7dcdc',
@ -227,26 +227,26 @@ class TestFormat(unittest.TestCase):
class TestCompareChangelogs(unittest.TestCase):
def test_select_new(self):
c1 = ChangelogEntry(b'John Doe <jdoe@example.com> 1.0-1', 1000000, 'change 1')
c2 = ChangelogEntry(b'John Doe <jdoe@example.com> 1.1-1', 2000000, 'change 2')
c1 = ChangelogEntry('John Doe <jdoe@example.com> 1.0-1', 1000000, 'change 1')
c2 = ChangelogEntry('John Doe <jdoe@example.com> 1.1-1', 2000000, 'change 2')
old = mock.Mock(changelogs=[c1])
new = mock.Mock(changelogs=[c2, c1])
clog = get_changelog_diff_from_headers(old, new)
self.assertEqual(clog, [c2])
def test_select_with_same_date(self):
c1 = ChangelogEntry(b'John Doe <jdoe@example.com> 1.0-1', 1000000, 'change 1')
c2 = ChangelogEntry(b'John Doe <jdoe@example.com> 1.1-1', 1000000, 'change 2')
c1 = ChangelogEntry('John Doe <jdoe@example.com> 1.0-1', 1000000, 'change 1')
c2 = ChangelogEntry('John Doe <jdoe@example.com> 1.1-1', 1000000, 'change 2')
old = mock.Mock(changelogs=[c1])
new = mock.Mock(changelogs=[c2, c1])
clog = get_changelog_diff_from_headers(old, new)
self.assertEqual(clog, [c2])
def test_no_subset(self):
c1 = ChangelogEntry(b'John Doe <jdoe@example.com> 0:2.0-1', 1000000, 'change 1')
c2 = ChangelogEntry(b'John Doe <jdoe@example.com> 1:1.1-1', 1000000, 'change 2')
c3 = ChangelogEntry(b'John Doe <jdoe@example.com> 1:1.2-1', 1000000, 'change 3')
c4 = ChangelogEntry(b'John Doe <jdoe@example.com> 1:1.3-1', 1000000, 'change 4')
c1 = ChangelogEntry('John Doe <jdoe@example.com> 0:2.0-1', 1000000, 'change 1')
c2 = ChangelogEntry('John Doe <jdoe@example.com> 1:1.1-1', 1000000, 'change 2')
c3 = ChangelogEntry('John Doe <jdoe@example.com> 1:1.2-1', 1000000, 'change 3')
c4 = ChangelogEntry('John Doe <jdoe@example.com> 1:1.3-1', 1000000, 'change 4')
old = mock.Mock(changelogs=[c3, c1])
new = mock.Mock(changelogs=[c4, c2, c1])
clog = get_changelog_diff_from_headers(old, new)

View file

@ -1,14 +1,17 @@
[tox]
envlist=py27,py35,py36
envlist=py26,py27,py35,py36,py37,py38
skip_missing_interpreters = true
minversion=3.12.0
[testenv]
deps=
nose
mock
freezegun
py26: freezegun<0.3.11
!py26: freezegun
unittest2
koji
kobo
kobo>=0.10.0
commands=
nosetests