test_config.py
2.65 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
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
from sklearn import get_config, set_config, config_context
from sklearn.utils._testing import assert_raises
def test_config_context():
assert get_config() == {'assume_finite': False, 'working_memory': 1024,
'print_changed_only': True,
'display': 'text'}
# Not using as a context manager affects nothing
config_context(assume_finite=True)
assert get_config()['assume_finite'] is False
with config_context(assume_finite=True):
assert get_config() == {'assume_finite': True, 'working_memory': 1024,
'print_changed_only': True,
'display': 'text'}
assert get_config()['assume_finite'] is False
with config_context(assume_finite=True):
with config_context(assume_finite=None):
assert get_config()['assume_finite'] is True
assert get_config()['assume_finite'] is True
with config_context(assume_finite=False):
assert get_config()['assume_finite'] is False
with config_context(assume_finite=None):
assert get_config()['assume_finite'] is False
# global setting will not be retained outside of context that
# did not modify this setting
set_config(assume_finite=True)
assert get_config()['assume_finite'] is True
assert get_config()['assume_finite'] is False
assert get_config()['assume_finite'] is True
assert get_config() == {'assume_finite': False, 'working_memory': 1024,
'print_changed_only': True,
'display': 'text'}
# No positional arguments
assert_raises(TypeError, config_context, True)
# No unknown arguments
assert_raises(TypeError, config_context(do_something_else=True).__enter__)
def test_config_context_exception():
assert get_config()['assume_finite'] is False
try:
with config_context(assume_finite=True):
assert get_config()['assume_finite'] is True
raise ValueError()
except ValueError:
pass
assert get_config()['assume_finite'] is False
def test_set_config():
assert get_config()['assume_finite'] is False
set_config(assume_finite=None)
assert get_config()['assume_finite'] is False
set_config(assume_finite=True)
assert get_config()['assume_finite'] is True
set_config(assume_finite=None)
assert get_config()['assume_finite'] is True
set_config(assume_finite=False)
assert get_config()['assume_finite'] is False
# No unknown arguments
assert_raises(TypeError, set_config, do_something_else=True)