Skip to content

Commit

Permalink
test sorting of all the OpenSSL versions ever released
Browse files Browse the repository at this point in the history
- closes: #46

Signed-off-by: Keshav Priyadarshi <git@keshav.space>
  • Loading branch information
keshav-space committed Apr 19, 2022
1 parent 33f680f commit 6b4d3e5
Show file tree
Hide file tree
Showing 6 changed files with 1,117 additions and 13 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ testing =
pytest-xdist >= 2
aboutcode-toolkit >= 6.0.0
black
commoncode

docs =
Sphinx >= 3.3.1
Expand Down
25 changes: 12 additions & 13 deletions src/univers/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from functools import total_ordering
import functools
import re

import attr
import semantic_version
Expand Down Expand Up @@ -158,6 +157,13 @@ def __ge__(self, other):
return NotImplemented
return self.value.__ge__(other.value)

def to_dict(self):
return {
"string": self.string,
"normalized_string": self.normalized_string,
"value": str(self.value),
}


@attr.s(frozen=True, order=False, hash=True)
class GenericVersion(Version):
Expand Down Expand Up @@ -452,17 +458,18 @@ def __lt__(self, other):
return NotImplemented
base_vers1 = self.value[:-1]
base_vers2 = other.value[:-1]
if base_vers1 == base_vers2 and (is_prerelease(self.value) or is_prerelease(other.value)):
return is_prerelease1_lt_prerelease2(self.value, other.value)
# Check if versions have the same base, and `one and only one` of them is a pre-release.
if base_vers1 == base_vers2 and (is_prerelease(self.value) != is_prerelease(other.value)):
return is_prerelease(self.value)
return self.value.__lt__(other.value)

def __gt__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
base_vers1 = self.value[:-1]
base_vers2 = other.value[:-1]
if base_vers1 == base_vers2 and (is_prerelease(self.value) or is_prerelease(other.value)):
return not is_prerelease1_lt_prerelease2(self.value, other.value)
if base_vers1 == base_vers2 and (is_prerelease(self.value) != is_prerelease(other.value)):
return is_prerelease(other.value)
return self.value.__gt__(other.value)


Expand All @@ -471,14 +478,6 @@ def is_prerelease(value):
return patch.startswith("-beta") or patch.startswith("-alpha")


def is_prerelease1_lt_prerelease2(value1, value2):
if is_prerelease(value1) and is_prerelease(value2):
patch1 = value1[-1]
patch2 = value2[-1]
return patch1[1:] < patch2[1:]
return is_prerelease(value1) and not is_prerelease(value2)


@attr.s(frozen=True, order=False, eq=False, hash=True)
class OpensslVersion(Version):
"""
Expand Down
172 changes: 172 additions & 0 deletions tests/data/openssl/openssl_all_versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
3.0.0
3.0.1
1.1.1
1.1.1a
1.1.1b
1.1.1c
1.1.1d
1.1.1e
1.1.1f
1.1.1g
1.1.1h
1.1.1i
1.1.1j
1.1.1k
1.1.1l
1.1.1m
1.0.2
1.0.2a
1.0.2b
1.0.2c
1.0.2d
1.0.2e
1.0.2f
1.0.2g
1.0.2h
1.0.2i
1.0.2j
1.0.2k
1.0.2l
1.0.2m
1.0.2n
1.0.2o
1.0.2p
1.0.2q
1.0.2r
1.0.2s
1.0.2t
1.0.2u
1.0.2v
1.0.2w
1.0.2x
1.0.2y
1.0.2za
1.0.2zb
1.0.2zc
3.0.2
1.1.1n
1.0.2zd
1.0.2zc-dev
1.1.0
1.1.0a
1.1.0b
1.1.0c
1.1.0d
1.1.0e
1.1.0f
1.1.0g
1.1.0h
1.1.0i
1.1.0j
1.1.0k
1.1.0l
1.0.1
1.0.1a
1.0.1b
1.0.1c
1.0.1d
1.0.1e
1.0.1f
1.0.1g
1.0.1h
1.0.1i
1.0.1j
1.0.1k
1.0.1l
1.0.1m
1.0.1n
1.0.1o
1.0.1p
1.0.1q
1.0.1r
1.0.1s
1.0.1t
1.0.1u
0.9.8
0.9.8a
0.9.8b
0.9.8c
0.9.8d
0.9.8e
0.9.8f
0.9.8g
0.9.8h
0.9.8i
0.9.8j
0.9.8k
0.9.8l
0.9.8m
0.9.8n
0.9.8o
0.9.8p
0.9.8q
0.9.8r
0.9.8s
0.9.8t
0.9.8u
0.9.8v
0.9.8w
0.9.8x
0.9.8y
0.9.8za
0.9.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