File: test_config.py

package info (click to toggle)
theano 1.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 30,752 kB
  • sloc: python: 141,182; ansic: 9,505; makefile: 259; sh: 214; pascal: 81
file content (44 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download | duplicates (2)
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
"""
Test config options.
"""
from __future__ import absolute_import, print_function, division
import unittest
from theano.configparser import AddConfigVar, ConfigParam, THEANO_FLAGS_DICT


class T_config(unittest.TestCase):

    def test_invalid_default(self):
        # Ensure an invalid default value found in the Theano code only causes
        # a crash if it is not overridden by the user.

        def filter(val):
            if val == 'invalid':
                raise ValueError()
            else:
                return val

        try:
            # This should raise a ValueError because the default value is
            # invalid.
            AddConfigVar(
                'T_config.test_invalid_default_a',
                doc='unittest',
                configparam=ConfigParam('invalid', filter=filter),
                in_c_key=False)
            assert False
        except ValueError:
            pass

        THEANO_FLAGS_DICT['T_config.test_invalid_default_b'] = 'ok'
        # This should succeed since we defined a proper value, even
        # though the default was invalid.
        AddConfigVar('T_config.test_invalid_default_b',
                     doc='unittest',
                     configparam=ConfigParam('invalid', filter=filter),
                     in_c_key=False)

        # Check that the flag has been removed
        assert 'T_config.test_invalid_default_b' not in THEANO_FLAGS_DICT

        # TODO We should remove these dummy options on test exit.