示例#1
0
文件: tests.py 项目: giampaolo/confix
    def test_envvars_case_sensitive(self):
        @register(self.section)
        class config:
            foo = 1
            bar = 2
            APPLE = 3

        # non-uppercase env vars are supposed to be ignored
        os.environ['FoO'] = '10'
        os.environ['BAR'] = '20'
        os.environ['APPLE'] = '30'
        parse_with_envvars(case_sensitive=True)
        assert config.foo == 1
        assert config.bar == 2
        assert config.APPLE == 30
示例#2
0
文件: tests.py 项目: giampaolo/confix
    def test_envvars_type_mismatch(self):
        @register(self.section)
        class config:
            some_int = 1
            some_float = 0.1
            some_bool = True

        # int
        os.environ['SOME_INT'] = 'foo'
        with self.assertRaises(TypesMismatchError) as cm:
            parse_with_envvars()
        assert cm.exception.section == self.section
        assert cm.exception.key == 'some_int'
        assert cm.exception.default_value == 1
        assert cm.exception.new_value == 'foo'
        del os.environ['SOME_INT']

        # float
        os.environ['SOME_FLOAT'] = 'foo'
        with self.assertRaises(TypesMismatchError) as cm:
            parse_with_envvars()
        assert cm.exception.section == self.section
        assert cm.exception.key == 'some_float'
        assert cm.exception.default_value == 0.1
        assert cm.exception.new_value == 'foo'
        del os.environ['SOME_FLOAT']

        # bool
        os.environ['SOME_BOOL'] = 'foo'
        with self.assertRaises(TypesMismatchError) as cm:
            parse_with_envvars()
        assert cm.exception.section == self.section
        assert cm.exception.key == 'some_bool'
        assert cm.exception.default_value is True
        assert cm.exception.new_value == 'foo'
示例#3
0
文件: tests.py 项目: giampaolo/confix
 def parse_with_envvars(self, *args, **kwargs):
     parse_with_envvars(*args, **kwargs)