Merge ~nacc/git-ubuntu:fix-build-version-check into git-ubuntu:master

Proposed by Nish Aravamudan
Status: Superseded
Proposed branch: ~nacc/git-ubuntu:fix-build-version-check
Merge into: git-ubuntu:master
Diff against target: 509 lines (+192/-82)
7 files modified
gitubuntu/build.py (+9/-2)
gitubuntu/git_repository.py (+0/-12)
gitubuntu/importer.py (+11/-11)
gitubuntu/importlocal.py (+2/-1)
gitubuntu/lint.py (+1/-3)
gitubuntu/merge.py (+2/-1)
gitubuntu/versioning.py (+167/-52)
Reviewer Review Type Date Requested Status
Robie Basak Pending
Review via email: mp+328421@code.launchpad.net

This proposal has been superseded by a proposal from 2017-08-02.

Description of the change

I can't seem to find the right twiddles to make this branch depend on the sru-series-versioning, but it's one commit on top.

To post a comment you must log in.

Unmerged commits

0a277bc... by Nish Aravamudan

git ubuntu build: use semantic versioning check not string comparison

It is definitively incorrect to simply string compare the upstream
versions, as that puts, e.g. ubuntu2 after ubuntu16. Use the
now-common-code version_compare to do the comparison.

LP: #1707983

71fee3d... by Nish Aravamudan

versioning: add support for SRU series in the versioning logic

This reverts commit 151c31bbbc12b74f5aaff09bb57d85baf341d959.

This changes the versioned parts into a namedtuple and updates the unit
tests accordingly (purely passing the correct type). It also clarifies
when a suffix is being manipulated and when an entire version string is
being manipulated.

With this change, the unit tests now all pass in versioning.py.

ed90707... by Nish Aravamudan

versioning: rename before/after lists to befores/afters

This helps clarify they are iterables.

f3863b8... by Nish Aravamudan

versioning: add docstring and rename variables

The variable names now reflect their type, as it can be quite confusing.

93206ee... by Nish Aravamudan

versioning: clarify internal bump functions bump suffixes

272e775... by Nish Aravamudan

versioning: next_development_version should take a string version

The notion of Version objects can be fully encapsulated in the
versioning module.

d000d4f... by Nish Aravamudan

versioning: define exposed API with __all__

d924d59... by Nish Aravamudan

versioning: add more unit tests for SRU policies

54adbf0... by Nish Aravamudan

versioning: move GitUbuntuRepository.version_compare

version_compare was a classmethod of GitUbuntuRepository because there
wasn't a better place for it. Now that we have a 'versioning' module, it
makes sense for version comparison to also live there. Indicate it is an
exposed API, as well.

Add some simple unit tests, as well.

0cede92... by Nish Aravamudan

versioning: fix stray whitespace

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitubuntu/build.py b/gitubuntu/build.py
2index 825cb67..16d7c99 100644
3--- a/gitubuntu/build.py
4+++ b/gitubuntu/build.py
5@@ -27,6 +27,7 @@ from gitubuntu.run import run, runq
6 from gitubuntu.source_information import GitUbuntuSourceInformation, NoPublicationHistoryException
7 from gitubuntu.cache import CACHE_PATH
8 from gitubuntu.dsc import GitUbuntuDsc, orig_re
9+from gitubuntu.versioning import version_compare
10 try:
11 pkg = 'python3-debian'
12 from debian.changelog import Changelog
13@@ -166,7 +167,10 @@ class GitUbuntuBuild:
14 'publish %s matches %s' %
15 (spi.version, last_upstream_version)
16 )
17- if spi.upstream_version < last_upstream_version:
18+ if version_compare(
19+ spi.upstream_version,
20+ last_upstream_version
21+ ) < 0:
22 logging.info('New upstream version detected '
23 '(%s) which is after the last published '
24 'upstream version (%s). Falling through '
25@@ -174,7 +178,10 @@ class GitUbuntuBuild:
26 last_upstream_version, spi.upstream_version)
27 upstream_version_found = True
28 break
29- if spi.upstream_version == last_upstream_version:
30+ if version_compare(
31+ spi.upstream_version,
32+ last_upstream_version
33+ ) == 0:
34 logging.debug('Upstream version of publish %s '
35 'matches' % spi.version
36 )
37diff --git a/gitubuntu/git_repository.py b/gitubuntu/git_repository.py
38index ba0480b..b505da3 100644
39--- a/gitubuntu/git_repository.py
40+++ b/gitubuntu/git_repository.py
41@@ -17,8 +17,6 @@ import tempfile
42 import time
43 from gitubuntu.run import run, runq, decode_binary
44 try:
45- pkg = 'python3-debian'
46- import debian
47 pkg = 'python3-pygit2'
48 import pygit2
49 except ImportError:
50@@ -869,16 +867,6 @@ class GitUbuntuRepository:
51 runq(['git', 'reset', '--hard'], env=self._env)
52 runq(['git', 'clean', '-f', '-d'], env=self._env)
53
54- @staticmethod
55- def version_compare(a, b):
56- if a is None:
57- if b is None:
58- return 0
59- return -1
60- if b is None:
61- return 1
62- return debian.debian_support.version_compare(a, b)
63-
64 def get_all_changelog_versions_from_treeish(self, treeish):
65 try:
66 lines = self.parse_changelog_field_in_treeish(
67diff --git a/gitubuntu/importer.py b/gitubuntu/importer.py
68index 83f3675..9f466c9 100644
69--- a/gitubuntu/importer.py
70+++ b/gitubuntu/importer.py
71@@ -41,6 +41,7 @@ from gitubuntu.git_repository import GitUbuntuRepository, orphan_tag, applied_ta
72 from gitubuntu.run import decode_binary, run, runq
73 from gitubuntu.source_information import GitUbuntuSourceInformation, NoPublicationHistoryException, SourceExtractionException, launchpad_login_auth
74 from gitubuntu.version import VERSION
75+from gitubuntu.versioning import version_compare
76 try:
77 pkg = 'python3-pygit2'
78 import pygit2
79@@ -688,7 +689,7 @@ class GitUbuntuImport:
80 devel_head_version, _ = self.local_repo.get_changelog_versions_from_treeish(devel_head_hash)
81 except AttributeError:
82 devel_head_version = None
83- if self.local_repo.version_compare(spi.version, devel_head_version) <= 0:
84+ if version_compare(spi.version, devel_head_version) <= 0:
85 return
86 logging.debug("Updating %s to %s" % (devel_head,
87 spi.head_name(namespace)))
88@@ -709,14 +710,13 @@ class GitUbuntuImport:
89 # Find highest version publish in these pockets
90 for suff in ("-proposed", "-updates", "-security", ""):
91 name = "%s/ubuntu/%s%s" % (namespace, rel, suff)
92- if name in ubuntu_head_versions and \
93- self.local_repo.version_compare(
94- ubuntu_head_versions[name]['version'],
95- series_devel_version
96- ) > 0:
97- series_devel_name = name
98- series_devel_version = ubuntu_head_versions[name]['version']
99- series_devel_hash = str(ubuntu_head_versions[name]['head'].peel().id)
100+ if name in ubuntu_head_versions and version_compare(
101+ ubuntu_head_versions[name]['version'],
102+ series_devel_version
103+ ) > 0:
104+ series_devel_name = name
105+ series_devel_version = ubuntu_head_versions[name]['version']
106+ series_devel_hash = str(ubuntu_head_versions[name]['head'].peel().id)
107 if series_devel_hash:
108 if not devel_hash:
109 devel_hash = series_devel_hash
110@@ -843,7 +843,7 @@ class GitUbuntuImport:
111 except AttributeError:
112 pass
113
114- if self.local_repo.version_compare(str(spi.version), unapplied_tip_version) <= 0:
115+ if version_compare(str(spi.version), unapplied_tip_version) <= 0:
116 logging.warn('Version to import (%s) is not after %s tip (%s)',
117 spi.version, pretty_head_name, unapplied_tip_version
118 )
119@@ -1003,7 +1003,7 @@ class GitUbuntuImport:
120 except AttributeError:
121 pass
122
123- if self.local_repo.version_compare(str(spi.version), applied_tip_version) <= 0:
124+ if version_compare(str(spi.version), applied_tip_version) <= 0:
125 logging.warn('Version to import (%s) is not after %s tip (%s)',
126 spi.version, pretty_head_name, applied_tip_version
127 )
128diff --git a/gitubuntu/importlocal.py b/gitubuntu/importlocal.py
129index c8c4fe4..bf1700e 100644
130--- a/gitubuntu/importlocal.py
131+++ b/gitubuntu/importlocal.py
132@@ -11,6 +11,7 @@ from gitubuntu.git_repository import GitUbuntuRepository, git_dep14_tag
133 from gitubuntu.run import decode_binary, run, runq
134 from gitubuntu.version import VERSION
135 from gitubuntu.importer import GitUbuntuImport
136+from gitubuntu.versioning import version_compare
137 try:
138 pkg = 'python3-pygit2'
139 import pygit2
140@@ -143,7 +144,7 @@ class GitUbuntuImportLocal(GitUbuntuImport):
141 unapplied_changelog_parent_commit = None
142 applied_changelog_parent_commit = None
143
144- if self.local_repo.version_compare(changelog_version, head_version) <= 0:
145+ if version_compare(changelog_version, head_version) <= 0:
146 logging.warn('Version to import (%s) is not after HEAD '
147 'version (%s), history may not make sense.',
148 changelog_version, head_version
149diff --git a/gitubuntu/lint.py b/gitubuntu/lint.py
150index ef3652f..f176a44 100644
151--- a/gitubuntu/lint.py
152+++ b/gitubuntu/lint.py
153@@ -348,9 +348,7 @@ class GitUbuntuLint:
154 version, _ = self.local_repo.get_changelog_versions_from_treeish(
155 commitish
156 )
157- return gitubuntu.versioning.next_development_version(
158- gitubuntu.versioning.Version(version)
159- )
160+ return gitubuntu.versioning.next_development_version(version)
161
162 def do_merge_lint(self, old, new_base):
163 """
164diff --git a/gitubuntu/merge.py b/gitubuntu/merge.py
165index 339c1b0..55df89a 100644
166--- a/gitubuntu/merge.py
167+++ b/gitubuntu/merge.py
168@@ -10,6 +10,7 @@ import textwrap
169 from gitubuntu.git_repository import GitUbuntuRepository, git_dep14_tag
170 from gitubuntu.run import decode_binary, run
171 from gitubuntu.source_information import GitUbuntuSourceInformation
172+from gitubuntu.versioning import version_compare
173
174 class TagException(Exception):
175 pass
176@@ -330,7 +331,7 @@ class GitUbuntuMerge:
177
178 try:
179 onto_version, _ = self.local_repo.get_changelog_versions_from_treeish(self.onto)
180- if self.local_repo.version_compare(commitish_version, onto_version) >= 0:
181+ if version_compare(commitish_version, onto_version) >= 0:
182 if self.force:
183 logging.info('%s version (%s) is after %s version (%s), '
184 'but --force passed.', self.commitish,
185diff --git a/gitubuntu/versioning.py b/gitubuntu/versioning.py
186index 10afb56..d2d76aa 100644
187--- a/gitubuntu/versioning.py
188+++ b/gitubuntu/versioning.py
189@@ -1,4 +1,6 @@
190+from collections import namedtuple
191 import copy
192+import functools
193 import logging
194 import re
195 import sys
196@@ -16,11 +18,22 @@ except ImportError:
197 logging.error('Is %s installed?', pkg)
198 sys.exit(1)
199
200+__all__ = [
201+ "next_development_version",
202+ "next_sru_version",
203+ "version_compare",
204+]
205+
206+# see _decompose_version_string for explanation of members
207+_VersionComps = namedtuple(
208+ "_VersionComps",
209+ ["prefix_parts", "ubuntu_maj", "ubuntu_series", "ubuntu_min"]
210+)
211+
212 def _decompose_version_string(version_string):
213- """Return the "Ubuntu"-relevant parts of a version string
214+ """Return the "Ubuntu"-relevant components of a version string
215
216- Returns a 3-tuple of (prefix_parts, ubuntu_maj, ubuntu_min), throwing away
217- some information.
218+ Returns a _VersionComps namedtuple, throwing away some information.
219
220 prefix_parts is a list of separated string parts forming the first
221 "non-Ubuntu" part of the string, to which Ubuntu-specific version parts
222@@ -34,10 +47,15 @@ def _decompose_version_string(version_string):
223 "1.0-2ubuntu3.4", 3 is the major Ubuntu version number in both cases. In
224 "1.0-2", the major Ubuntu version number is not present.
225
226+ ubuntu_series is the "series" in the Ubuntu version number as a string, or
227+ None if not present. For example, in the version string
228+ "1.0.2ubuntu3.17.04.4", 17.04 is the Ubuntu series string. In both
229+ "1.0-2ubuntu3.4" and "1.0-2", the Ubuntu series is not present.
230+
231 ubuntu_min is the "minor" Ubuntu version number as an integer, or None if
232- not present. For example, in the version strings "1.0-2ubuntu3.4", 4 is the
233- Ubuntu minor version number. In both "1.0-2" and "1.0-2ubuntu3", the minor
234- Ubuntu version number is not present.
235+ not present. For example, in the version strings "1.0-2ubuntu3.4" and
236+ "1.0-2ubuntu3.17.04.4", 4 is the Ubuntu minor version number. In both
237+ "1.0-2" and "1.0-2ubuntu3", the minor Ubuntu version number is not present.
238
239 For version strings not following these standard forms, the result is
240 undefined except where specific test cases exist for them.
241@@ -50,9 +68,13 @@ def _decompose_version_string(version_string):
242 ]
243
244 if 'build' in parts and 'ubuntu' in parts:
245- raise ValueError("Not sure how to decompose %s" % version_string)
246+ raise ValueError("Not sure how to decompose %s: both build and "
247+ "ubuntu found" % version_string
248+ )
249 elif 'build' in parts:
250- return parts[:parts.index('build')], None, None
251+ return _VersionComps._make(
252+ [parts[:parts.index('build')], None, None, None]
253+ )
254 elif 'ubuntu' in parts:
255 ubuntu_idx = parts.index('ubuntu')
256 static_parts = parts[:ubuntu_idx]
257@@ -62,6 +84,7 @@ def _decompose_version_string(version_string):
258 except IndexError:
259 # nothing after "Xubuntu", treated as 1
260 ubuntu_maj = 1
261+ ubuntu_series = None
262 if len(suffix_parts) < 2:
263 ubuntu_min = None
264 else:
265@@ -69,9 +92,18 @@ def _decompose_version_string(version_string):
266 ubuntu_min = int(suffix_parts[-1])
267 except ValueError:
268 ubuntu_min = None
269- return static_parts, ubuntu_maj, ubuntu_min
270+ if len(suffix_parts[1:-1]) > 2:
271+ ubuntu_series = ''.join(suffix_parts[2:-2])
272+ if not re.match(r'\d\d\.\d\d', ubuntu_series):
273+ raise ValueError("Not sure how to decompose %s: "
274+ "series %s not in expected format" %
275+ (version_string, ubuntu_series)
276+ )
277+ return _VersionComps._make(
278+ [static_parts, ubuntu_maj, ubuntu_series, ubuntu_min]
279+ )
280 else:
281- return parts, None, None
282+ return _VersionComps._make([parts, None, None, None])
283
284
285 def _bump_version_object(old_version_object, bump_function):
286@@ -81,8 +113,8 @@ def _bump_version_object(old_version_object, bump_function):
287 non-native packages need to have their upstream_version bumped with their
288 debian_version staying the same. The bumping mechanism is the same either
289 way. This function handles this by working out which is needed, calling
290- bump_function with the old version string to return a bumped attribute
291- string, and creating a new Version object with the required attributed
292+ bump_function with the old version suffix to return a bumped attribute
293+ suffix, and creating a new Version object with the required attributed
294 bumped accordingly.
295 """
296
297@@ -91,74 +123,133 @@ def _bump_version_object(old_version_object, bump_function):
298 else:
299 bump_attr = 'debian_version'
300
301- old_version_string = getattr(old_version_object, bump_attr)
302- new_version_string = bump_function(old_version_string)
303+ old_version_suffix = getattr(old_version_object, bump_attr)
304+ # While we are only bumping a specific suffix, we need to know the
305+ # entire version for SRU version testing
306+ new_version_suffix = bump_function(old_version_object, old_version_suffix)
307 new_version_object = copy.deepcopy(old_version_object)
308- setattr(new_version_object, bump_attr, new_version_string)
309+ setattr(new_version_object, bump_attr, new_version_suffix)
310 return new_version_object
311
312
313-def _bump_development_version_string(version):
314- static_parts, old_ubuntu_maj, _ = _decompose_version_string(version)
315+def _bump_development_version_suffix(version, version_suffix):
316+ """Return the next development version suffix
317+
318+ Keeping the static components the same, bump the Ubuntu major
319+ version (see _decompose_version_string for definitions of these terms)
320+ and drop any minors.
321+ """
322+
323+ old_suffix_comps = _decompose_version_string(version_suffix)
324+
325+ new_ubuntu_maj = 1 if old_suffix_comps.ubuntu_maj is None else old_suffix_comps.ubuntu_maj + 1
326+ new_suffix_comps = old_suffix_comps.prefix_parts + ['ubuntu', str(new_ubuntu_maj)]
327+
328+ return ''.join(new_suffix_comps)
329
330- new_ubuntu_maj = 1 if old_ubuntu_maj is None else old_ubuntu_maj + 1
331- new_parts = static_parts + ['ubuntu', str(new_ubuntu_maj)]
332
333- return ''.join(new_parts)
334+def _bump_sru_version_suffix(befores, series, afters, version, version_suffix):
335+ """Return the next SRU version suffix
336
337+ Keeping the static components the same, maintain the same major (or
338+ set it to 0 if the first major) and bump the minor. Keep the series
339+ string (e.g., 16.04) in the version, if it was present before.
340+ """
341
342-def _bump_sru_version_string(version, series=None):
343- static_parts, old_maj, old_min = _decompose_version_string(version)
344+ befores_comps = [_decompose_version_string(str(v)) for v in befores]
345+ afters_comps = [_decompose_version_string(str(v)) for v in afters]
346+ old_suffix_comps = _decompose_version_string(version_suffix)
347+ old_version_comps = _decompose_version_string(str(version))
348
349- new_maj = 0 if old_maj is None else old_maj
350- new_min = 1 if old_min is None else old_min + 1
351+ new_maj = 0 if old_suffix_comps.ubuntu_maj is None else old_suffix_comps.ubuntu_maj
352+ new_min = 1 if old_suffix_comps.ubuntu_min is None else old_suffix_comps.ubuntu_min + 1
353
354 bumped_parts = ['ubuntu', str(new_maj), '.']
355- if series:
356+ if old_suffix_comps.ubuntu_series:
357+ bumped_parts.extend([old_suffix_comps.ubuntu_series, '.'])
358+ elif str(version) in [str(v) for v in befores + afters]:
359+ bumped_parts.extend([series, '.'])
360+ elif any(
361+ v.prefix_parts + ['ubuntu', str(v.ubuntu_maj), '.'] == old_version_comps.prefix_parts + bumped_parts
362+ for v in befores_comps + afters_comps
363+ ):
364 bumped_parts.extend([series, '.'])
365 bumped_parts.append(str(new_min))
366
367- return ''.join(static_parts + bumped_parts)
368+ return ''.join(old_suffix_comps.prefix_parts + bumped_parts)
369
370
371-def next_development_version(version):
372- return _bump_version_object(version, _bump_development_version_string)
373+def next_development_version(version_string):
374+ """Return the next development version relative to @version_string
375+ """
376+ return _bump_version_object(
377+ Version(version_string),
378+ _bump_development_version_suffix
379+ )
380
381
382-def _next_sru_version(before, series, current, after):
383- return _bump_version_object(current, _bump_sru_version_string)
384+def _next_sru_version(befores, series, current, afters):
385+ """Return the next SRU version respecting other series information
386+
387+ Currently incorrect, as it does not actually use other series
388+ information.
389+ """
390+ return _bump_version_object(current,
391+ functools.partial(_bump_sru_version_suffix, befores, series,
392+ afters
393+ )
394+ )
395
396
397-def max_version(lp_series, pkgname):
398+def max_version(lp_series_object, pkgname):
399+ """Return the latest published version for a given source package
400+ and series
401+ """
402 ubuntu_source_information = GitUbuntuSourceInformation('ubuntu', pkgname)
403 for spi in ubuntu_source_information.launchpad_versions_published(
404- sorted_by_version=True, series=lp_series
405+ sorted_by_version=True, series=lp_series_object
406 ):
407 return Version(spi.version)
408
409
410-def next_sru_version(series, pkgname):
411+def next_sru_version(lp_series_object, pkgname):
412+ """Return the next SRU version for a given source package and series
413+
414+ Queries Launchpad for publishing information about other active
415+ series for the same source package.
416+ """
417 # for a series extract the required parameters
418 ubuntu_source_information = GitUbuntuSourceInformation('ubuntu')
419- active_series = ubuntu_source_information.active_series
420- before = [max_version(before_series, pkgname)
421- for before_series in active_series
422- if float(before_series.version) < float(series.version)
423+ active_series_objects = ubuntu_source_information.active_series
424+ befores = [max_version(before_series_object, pkgname)
425+ for before_series_object in active_series_objects
426+ if float(before_series_object.version) < float(lp_series_object.version)
427 ]
428- after = [max_version(after_series, pkgname)
429- for after_series in active_series
430- if float(after_series.version) > float(series.version)
431+ afters = [max_version(after_series_object, pkgname)
432+ for after_series_object in active_series_objects
433+ if float(after_series_object.version) > float(lp_series_object.version)
434 ]
435- current = max_version(series, pkgname)
436- return _next_sru_version(before, series, current, after)
437+ current = max_version(lp_series_obj, pkgname)
438+ return _next_sru_version(befores, lp_series_obj, current, afters)
439+
440+
441+def version_compare(a, b):
442+ if a is None:
443+ if b is None:
444+ return 0
445+ return -1
446+ if b is None:
447+ return 1
448+ return debian.debian_support.version_compare(a, b)
449+
450
451 @pytest.mark.parametrize('test_input, expected', [
452- ('2', (['2'], None, None)),
453- ('2ubuntu1', (['2'], 1, None)),
454- ('2ubuntu1.3', (['2'], 1, 3)),
455- ('2ubuntu0.16.04.3', (['2'], 0, 3)),
456- ('2build1', (['2'], None, None)),
457- ('2build1.3', (['2'], None, None)),
458+ ('2', _VersionComps._make([['2'], None, None, None])),
459+ ('2ubuntu1', _VersionComps._make([['2'], 1, None, None])),
460+ ('2ubuntu1.3', _VersionComps._make([['2'], 1, None, 3])),
461+ ('2ubuntu0.16.04.3', _VersionComps._make([['2'], 0, '16.04', 3])),
462+ ('2build1', _VersionComps._make([['2'], None, None, None])),
463+ ('2build1.3', _VersionComps._make([['2'], None, None, None])),
464 ])
465 def test_decompose_version_string(test_input, expected):
466 assert _decompose_version_string(test_input) == expected
467@@ -178,14 +269,38 @@ def test_next_development_version(test_input, expected):
468 assert next_development_version(Version(test_input)) == expected
469
470
471-@pytest.mark.parametrize('before, series, current, after, expected', [
472+@pytest.mark.parametrize('befores, series, current, afters, expected', [
473 ([], '16.04', '1.0-1', [], '1.0-1ubuntu0.1'),
474 (['1.0-1'], '16.04', '1.0-1', [], '1.0-1ubuntu0.16.04.1'),
475+ ([], '16.04', '1.0-1', ['1.0-1'], '1.0-1ubuntu0.16.04.1'),
476+ (['1.0-1ubuntu1'], '16.04', '1.0-1ubuntu1', [], '1.0-1ubuntu1.16.04.1'),
477+ ([], '16.04', '1.0-1ubuntu1', ['1.0-1ubuntu1'], '1.0-1ubuntu1.16.04.1'),
478+ (['1.0-1ubuntu1'], '16.04', '1.0-1ubuntu1', ['1.0.1-ubuntu1'], '1.0-1ubuntu1.16.04.1'),
479+ (['1.0-1ubuntu1'], '16.04', '1.0-1ubuntu1', ['1.0.1-ubuntu2'], '1.0-1ubuntu1.16.04.1'),
480+ (['1.0-1ubuntu1.14.04.1'], '16.04', '1.0-1ubuntu1.16.04.1', ['1.0-1ubuntu1.17.10.1'], '1.0-1ubuntu1.16.04.2'),
481+ (['1.0-1ubuntu1.14.04.1'], '16.04', '1.0-1ubuntu1', ['1.0-1ubuntu2'], '1.0-1ubuntu1.16.04.1'),
482+ (['1.0-1ubuntu1.14.04.1'], '16.04', '1.0-1ubuntu1', ['1.0-1ubuntu1.17.10.1'], '1.0-1ubuntu1.16.04.1'),
483+ (['1.0-1'], '16.04', '1.0-1ubuntu1', ['1.0-1ubuntu11'], '1.0-1ubuntu1.1'),
484+ (['1.0-1'], '16.04', '1.0-2ubuntu1', ['1.0-2ubuntu11'], '1.0-2ubuntu1.1'),
485+ ([], '16.04', '1.0-2ubuntu1', ['2.0-2ubuntu1'], '1.0-2ubuntu1.1'),
486 ])
487-def test_next_sru_version(before, series, current, after, expected):
488+def test_next_sru_version(befores, series, current, afters, expected):
489 assert _next_sru_version(
490- before=[Version(vstr) for vstr in before],
491+ befores=[Version(vstr) for vstr in befores],
492 series=series,
493 current=Version(current),
494- after=[Version(vstr) for vstr in after],
495+ afters=[Version(vstr) for vstr in afters],
496 ) == expected
497+
498+
499+@pytest.mark.parametrize('a, b, expected', [
500+ (None, '1.0-1', -1),
501+ (None, None, 0),
502+ ('1.0-1', None, 1),
503+ ('1.0-1', '1.0-1ubuntu1', -1),
504+ ('1.0-1ubuntu1', '1.0-1ubuntu1', 0),
505+ ('1.0-1ubuntu1', '2.0-1', -1),
506+ ('1.0-1ubuntu1', '1.0-2', -1),
507+])
508+def test_version_compare(a, b, expected):
509+ assert version_compare(a, b) == expected

Subscribers

People subscribed via source and target branches