Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove + character from platform releases string #895

Merged
merged 3 commits into from Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion pika/compat.py
@@ -1,9 +1,12 @@
import os
import sys as _sys
import platform
import re

PY2 = _sys.version_info < (3,)
PY3 = not PY2
RE_NUM = re.compile(r'(\d+).+')


if not PY2:
# these were moved around for Python 3
Expand Down Expand Up @@ -129,9 +132,16 @@ def as_bytes(value):
return value


def to_digit(value):
if value.isdigit():
return int(value)
match = RE_NUM.match(value)
return int(match.groups()[0]) if match else 0


def get_linux_version(release_str):
ver_str = release_str.split('-')[0]
return tuple(map(int, ver_str.split('.')[:3]))
return tuple(map(to_digit, ver_str.split('.')[:3]))


HAVE_SIGNAL = os.name == 'posix'
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/compat_tests.py
Expand Up @@ -13,3 +13,15 @@ def test_get_linux_version_normal(self):

def test_get_linux_version_short(self):
self.assertEqual(compat.get_linux_version("4.11.0"), (4, 11, 0))

def test_get_linux_version_gcp(self):
self.assertEqual(compat.get_linux_version("4.4.64+"), (4, 4, 64))

def test_to_digit(self):
self.assertEqual(compat.to_digit("64"), 64)

def test_to_digit_with_plus_sign(self):
self.assertEqual(compat.to_digit("64+"), 64)

def test_to_digit_with_dot(self):
self.assertEqual(compat.to_digit("64."), 64)