From 86c951c4661d3af234f8a7b7e560ab88e12a3f2b Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jun 07 2019 08:48:20 +0000 Subject: 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ář --- diff --git a/.gitignore b/.gitignore index ccf9d17..a988ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ noarch/* .coverage htmlcov/ tests/repo +.tox diff --git a/compose_utils/changelog.py b/compose_utils/changelog.py index 1a38638..9f499b6 100644 --- a/compose_utils/changelog.py +++ b/compose_utils/changelog.py @@ -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: diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 3dca9b7..ffda70e 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -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ář - 1:0.1.0-1\n- new version'], + 'changelog': ['* Tue Mar 15 2016 Lubomír Sedlář - 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ář - 0.7.9-9.module_f8c7dcdc\n- First release'], + 'changelog': ['* Tue Sep 05 2017 Lubomír Sedlář - 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 1.0-1', 1000000, 'change 1') - c2 = ChangelogEntry(b'John Doe 1.1-1', 2000000, 'change 2') + c1 = ChangelogEntry('John Doe 1.0-1', 1000000, 'change 1') + c2 = ChangelogEntry('John Doe 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 1.0-1', 1000000, 'change 1') - c2 = ChangelogEntry(b'John Doe 1.1-1', 1000000, 'change 2') + c1 = ChangelogEntry('John Doe 1.0-1', 1000000, 'change 1') + c2 = ChangelogEntry('John Doe 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 0:2.0-1', 1000000, 'change 1') - c2 = ChangelogEntry(b'John Doe 1:1.1-1', 1000000, 'change 2') - c3 = ChangelogEntry(b'John Doe 1:1.2-1', 1000000, 'change 3') - c4 = ChangelogEntry(b'John Doe 1:1.3-1', 1000000, 'change 4') + c1 = ChangelogEntry('John Doe 0:2.0-1', 1000000, 'change 1') + c2 = ChangelogEntry('John Doe 1:1.1-1', 1000000, 'change 2') + c3 = ChangelogEntry('John Doe 1:1.2-1', 1000000, 'change 3') + c4 = ChangelogEntry('John Doe 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) diff --git a/tox.ini b/tox.ini index c80862b..a9e28e3 100644 --- a/tox.ini +++ b/tox.ini @@ -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