-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_configure.py
91 lines (76 loc) · 2.53 KB
/
test_configure.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pytest
from hipercow import root
from hipercow.configure import (
_write_configuration,
configure,
show_configuration,
unconfigure,
)
from hipercow.driver import list_drivers, load_driver, load_driver_optional
from hipercow.example import ExampleDriver
def test_no_drivers_are_available_by_default(tmp_path):
path = tmp_path / "ex"
root.init(path)
r = root.open_root(path)
assert list_drivers(r) == []
assert load_driver_optional(r, None) is None
with pytest.raises(Exception, match="No driver configured"):
load_driver(r, None)
with pytest.raises(Exception, match="No such driver 'example'"):
load_driver(r, "example")
def test_can_configure_driver(tmp_path):
path = tmp_path / "ex"
root.init(path)
r = root.open_root(path)
configure(r, "example")
assert list_drivers(r) == ["example"]
assert isinstance(load_driver(r, None), ExampleDriver)
def test_can_unconfigure_driver(tmp_path):
path = tmp_path / "ex"
root.init(path)
r = root.open_root(path)
configure(r, "example")
assert list_drivers(r) == ["example"]
unconfigure(r, "example")
assert list_drivers(r) == []
unconfigure(r, "example")
assert list_drivers(r) == []
def test_throw_if_unknown_driver(tmp_path):
path = tmp_path / "ex"
root.init(path)
r = root.open_root(path)
with pytest.raises(Exception, match="No such driver 'other'"):
configure(r, "other")
def test_can_reconfigure_driver(tmp_path, capsys):
path = tmp_path / "ex"
root.init(path)
r = root.open_root(path)
capsys.readouterr()
configure(r, "example")
str1 = capsys.readouterr().out
assert str1.startswith("Configured hipercow to use 'example'")
configure(r, "example")
str2 = capsys.readouterr().out
assert str2.startswith("Updated configuration for 'example'")
def test_get_default_driver(tmp_path):
path = tmp_path / "ex"
root.init(path)
r = root.open_root(path)
a = ExampleDriver(r)
a.name = "a"
b = ExampleDriver(r)
b.name = "b"
_write_configuration(r, a)
_write_configuration(r, b)
with pytest.raises(Exception, match="More than one candidate driver"):
load_driver(r, None)
def test_can_show_configuration(tmp_path, capsys):
path = tmp_path / "ex"
root.init(path)
r = root.open_root(path)
configure(r, "example")
capsys.readouterr()
capsys.readouterr()
show_configuration(r, None)
out = capsys.readouterr().out
assert out == "Configuration for 'example'\n(no configuration)\n"