Skip to content

Commit 6af3094

Browse files
committed
Updated context to handle ubuntu and debian os names.
Replicates kaizendorks#114
1 parent 6aab1e9 commit 6af3094

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pymongo_inmemory/context.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,19 @@ def __str__(self):
150150
def _build_operating_system_info(self, os_name=None):
151151
os_name = conf("operating_system", os_name)
152152
if os_name is None:
153-
_mapping = {"Darwin": "osx", "Linux": "linux", "Windows": "windows"}
154-
os_name = _mapping.get(platform.system())
153+
# Fix for using platform.system() yields will yield 'linux'
154+
platform_uname = platform.uname().version.lower()
155+
is_ubuntu = 'ubuntu' in platform_uname
156+
is_debian = 'debian' in platform_uname
157+
if is_ubuntu:
158+
system = 'ubuntu'
159+
elif is_debian:
160+
system = 'debian'
161+
else:
162+
system = platform.system()
163+
164+
_mapping = {"Darwin": "osx", "Linux": "linux", "Windows": "windows", 'ubuntu': 'ubuntu', 'debian': 'debian'}
165+
os_name = _mapping.get(system)
155166
if os_name is None:
156167
raise OperatingSystemNotFound("Can't determine operating system.")
157168
return os_name

tests/unit/test_context.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import hashlib
2+
from platform import uname_result
23

34
from pymongo_inmemory import context
45

@@ -31,7 +32,12 @@ def system():
3132
def conf(*args, **kwargs):
3233
return
3334

35+
def uname():
36+
# noinspection PyArgumentList
37+
return uname_result('', '', '', '', '')
38+
3439
monkeypatch.setattr(context.platform, "system", system)
40+
monkeypatch.setattr(context.platform, "uname", uname)
3541
monkeypatch.setattr(context, "conf", conf)
3642
with pytest.raises(context.OperatingSystemNotFound):
3743
context.Context()

0 commit comments

Comments
 (0)