-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_environment_empty.py
54 lines (41 loc) · 1.53 KB
/
test_environment_empty.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from unittest import mock
import pytest
from hipercow import root
from hipercow.environment import environment_engine
from hipercow.environment_engines import Empty
def test_empty_environment_has_no_path_but_always_exists(tmp_path):
root.init(tmp_path)
r = root.open_root(tmp_path)
env = Empty(r, "empty")
assert env.exists()
with pytest.raises(Exception, match="The empty environment has no path"):
env.path()
def test_can_load_empty_engine(tmp_path):
root.init(tmp_path)
r = root.open_root(tmp_path)
assert isinstance(environment_engine(r, "empty"), Empty)
assert isinstance(environment_engine(r, "default"), Empty)
def test_empty_environment_cannot_be_created(tmp_path):
root.init(tmp_path)
r = root.open_root(tmp_path)
env = Empty(r, "empty")
with pytest.raises(Exception, match="Can't create the empty environment!"):
env.create()
def test_empty_environment_cannot_be_provisioned(tmp_path):
root.init(tmp_path)
r = root.open_root(tmp_path)
env = Empty(r, "empty")
with pytest.raises(Exception, match="Can't provision the empty"):
env.provision([])
def test_can_run_command_in_empty_env(tmp_path, mocker):
mock_run = mock.MagicMock()
mocker.patch("subprocess.run", mock_run)
root.init(tmp_path)
r = root.open_root(tmp_path)
env = Empty(r, "empty")
env.run(["some", "command"])
assert mock_run.call_count == 1
assert mock_run.mock_calls[0] == mock.call(
["some", "command"], env=os.environ, check=False
)