예제 #1
0
    def test_defaults_and_env(self):
        config = Config({'present': 'dp', 'absent': 'da'})

        environ = {'ENV_PRESENT': '1'}

        config.merge(environ, {
            convert('ENV_PRESENT', int): 'present',
            convert('ENV_ABSENT', int): 'absent',
        })

        compare(config.present, expected=1)
        compare(config.absent, expected='da')
예제 #2
0
    def test_defaults_and_env(self):
        config = Config({'present': 'dp', 'absent': 'da'})

        environ = {'ENV_PRESENT': '1'}

        config.merge(
            environ, {
                convert('ENV_PRESENT', int): 'present',
                convert('ENV_ABSENT', int): 'absent',
            })

        compare(config.present, expected=1)
        compare(config.absent, expected='da')
예제 #3
0
 def test_mapping_type_conversion(self):
     config = Config({'x': 0})
     data = {'y': '1'}
     config.merge(data, mapping={
         convert(source['y'], int): target['x']
     })
     compare(config.data, expected={'x': 1})
예제 #4
0
 def test_mapping_type_conversion(self):
     config = Config({'x': 0})
     data = {'y': '1'}
     config.merge(data, mapping={
         convert(source['y'], int): target['x']
     })
     compare(config.data, expected={'x': 1})
예제 #5
0
 def test_str_nested(self):
     compare(
         str(
             required(convert(source['foo'].y,
                              int)).insert(0).append().merge()),
         expected=
         ("required(convert(source['foo'].y, int)).insert(0).append().merge()"
          ))
예제 #6
0
    def test_mapping_extensive_conversation(self):
        config = Config({'a': 0})
        data = {'x': 2, 'y': -1}

        def best(possible):
            return max(possible.values())

        config.merge(data, mapping={
            convert(source, best): target['a']
        })

        compare(config.data, expected={'a': 2})
예제 #7
0
    def test_mapping_extensive_conversation(self):
        config = Config({'a': 0})
        data = {'x': 2, 'y': -1}

        def best(possible):
            return max(possible.values())

        config.merge(data, mapping={
            convert(source, best): target['a']
        })

        compare(config.data, expected={'a': 2})
예제 #8
0
 def test_ensure_on_convert(self):
     data = '1'
     with ShouldRaise(TypeError('Cannot use convert() as target')):
         store(data, convert(target, int).x, 'y')
예제 #9
0
 def test_convert_not_present(self):
     data = {}
     compare(load(data, convert('x', int)), expected=NotPresent('x'))
예제 #10
0
 def test_convert_string(self):
     data = Namespace(x='1')
     compare(load(data, convert('x', int)), expected=1)
예제 #11
0
 def test_convert(self):
     data = Namespace(x='1')
     compare(load(data, convert(source.x, int)), expected=1)
예제 #12
0
 def test_ensure_on_convert(self):
     data = '1'
     with ShouldRaise(TypeError('Cannot use convert() as target')):
         store(data, convert(target, int).x, 'y')
예제 #13
0
 def test_convert_not_present(self):
     data = {}
     compare(load(data, convert('x', int)), expected=NotPresent('x'))
예제 #14
0
 def test_convert_string(self):
     data = Namespace(x='1')
     compare(load(data, convert('x', int)), expected=1)
예제 #15
0
 def test_convert_no_name(self):
     o = object()
     compare(str(convert(source, o)),
             expected=("convert(source, {!r})".format(o)))
예제 #16
0
 def test_str_nested(self):
     compare(str(
         required(convert(source['foo'].y, int)).insert(0).append().merge()
     ), expected=(
         "required(convert(source['foo'].y, int)).insert(0).append().merge()"
     ))
예제 #17
0
 def test_convert_no_name(self):
     o = object()
     compare(str(convert(source, o)), expected=(
         "convert(source, {!r})".format(o)
     ))
예제 #18
0
 def test_convert(self):
     data = Namespace(x='1')
     compare(load(data, convert(source.x, int)), expected=1)