6
6
7
7
from theano import configdefaults , configparser
8
8
from theano .configdefaults import default_blas_ldflags
9
- from theano .configparser import THEANO_FLAGS_DICT , AddConfigVar , ConfigParam
9
+ from theano .configparser import ConfigParam
10
10
11
11
12
12
def test_invalid_default ():
13
13
# Ensure an invalid default value found in the Theano code only causes
14
14
# a crash if it is not overridden by the user.
15
15
16
+ root = configdefaults .config
17
+
16
18
def validate (val ):
17
19
if val == "invalid" :
18
20
raise ValueError ("Test-triggered" )
19
21
20
22
with pytest .raises (ValueError , match = "Test-triggered" ):
21
23
# This should raise a ValueError because the default value is
22
24
# invalid.
23
- AddConfigVar (
25
+ root . add (
24
26
"T_config__test_invalid_default_a" ,
25
27
doc = "unittest" ,
26
28
configparam = ConfigParam ("invalid" , validate = validate ),
27
29
in_c_key = False ,
28
30
)
29
31
30
- THEANO_FLAGS_DICT ["T_config__test_invalid_default_b" ] = "ok"
32
+ root . _flags_dict ["T_config__test_invalid_default_b" ] = "ok"
31
33
# This should succeed since we defined a proper value, even
32
34
# though the default was invalid.
33
- AddConfigVar (
35
+ root . add (
34
36
"T_config__test_invalid_default_b" ,
35
37
doc = "unittest" ,
36
38
configparam = ConfigParam ("invalid" , validate = validate ),
@@ -39,7 +41,7 @@ def validate(val):
39
41
40
42
# TODO We should remove these dummy options on test exit.
41
43
# Check that the flag has been removed
42
- assert "T_config__test_invalid_default_b" not in THEANO_FLAGS_DICT
44
+ assert "T_config__test_invalid_default_b" not in root . _flags_dict
43
45
44
46
45
47
@patch ("theano.configdefaults.try_blas_flag" , return_value = None )
@@ -84,20 +86,19 @@ def test_config_param_apply_and_validation():
84
86
def test_config_hash ():
85
87
# TODO: use custom config instance for the test
86
88
root = configparser .config
87
- configparser . AddConfigVar (
89
+ root . add (
88
90
"test_config_hash" ,
89
91
"A config var from a test case." ,
90
92
configparser .StrParam ("test_default" ),
91
- root = root ,
92
93
)
93
94
94
- h0 = configparser .get_config_hash ()
95
+ h0 = root .get_config_hash ()
95
96
96
97
with configparser .change_flags (test_config_hash = "new_value" ):
97
98
assert root .test_config_hash == "new_value"
98
- h1 = configparser .get_config_hash ()
99
+ h1 = root .get_config_hash ()
99
100
100
- h2 = configparser .get_config_hash ()
101
+ h2 = root .get_config_hash ()
101
102
assert h1 != h0
102
103
assert h2 == h0
103
104
@@ -141,11 +142,10 @@ def test_deviceparam(self):
141
142
def test_config_context ():
142
143
# TODO: use custom config instance for the test
143
144
root = configparser .config
144
- configparser . AddConfigVar (
145
+ root . add (
145
146
"test_config_context" ,
146
147
"A config var from a test case." ,
147
148
configparser .StrParam ("test_default" ),
148
- root = root ,
149
149
)
150
150
assert hasattr (root , "test_config_context" )
151
151
assert root .test_config_context == "test_default"
@@ -156,8 +156,9 @@ def test_config_context():
156
156
157
157
158
158
def test_no_more_dotting ():
159
+ root = configparser .config
159
160
with pytest .raises (ValueError , match = "Dot-based" ):
160
- AddConfigVar (
161
+ root . add (
161
162
"T_config.something" ,
162
163
doc = "unittest" ,
163
164
configparam = ConfigParam ("invalid" ),
0 commit comments