[e5f1db]: / tests / utils / test_utils_available.py

Download this file

40 lines (25 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from ehrapy._compat import _check_module_importable, _shell_command_accessible
def test_check_module_importable_true():
assert _check_module_importable("math") is True
def test_check_module_importable_false():
assert _check_module_importable("nonexistentmodule12345") is False
def test_shell_command_accessible_true(monkeypatch):
def mock_popen(*args, **kwargs):
class MockProcess:
def __init__(self):
self.returncode = 0
def communicate(self):
return ("output", "")
return MockProcess()
monkeypatch.setattr("subprocess.Popen", mock_popen)
assert _shell_command_accessible(["echo", "hello"]) is True
def test_shell_command_accessible_false(monkeypatch):
def mock_popen(*args, **kwargs):
class MockProcess:
def __init__(self):
self.returncode = 1
def communicate(self):
return ("", "error")
return MockProcess()
monkeypatch.setattr("subprocess.Popen", mock_popen)
assert _shell_command_accessible(["nonexistentcommand"]) is False