示例#1
0
文件: tests.py 项目: giampaolo/confix
    def test_hidden_key(self):
        @register()
        class config:
            foo = 1
            _hidden = 2

        parse()
        assert get_parsed_conf() == {'foo': 1}
示例#2
0
文件: tests.py 项目: giampaolo/confix
    def test_root_only(self):
        @register()
        class root_conf:
            root_value = 1

        self.assertRaises(NotParsedError, get_parsed_conf)
        parse()
        assert get_parsed_conf() == {'root_value': 1}
示例#3
0
文件: tests.py 项目: giampaolo/confix
    def test_sub_plus_root(self):
        @register('sub')
        class sub_conf:
            sub_value = 1

        @register()
        class root_conf:
            root_value = 1

        parse()
        assert get_parsed_conf() == {'root_value': 1, 'sub': {'sub_value': 1}}
示例#4
0
文件: tests.py 项目: giampaolo/confix
    def test_register_after_parse(self):
        @register()
        class config:
            foo = 1

        parse()

        with warnings.catch_warnings(record=True) as ws:
            @register(section="unparsed")
            class unparsed_config:
                bar = 1

        assert len(ws) == 1
        assert 'configuration class defined after parse' in \
            str(ws[0].message)
        assert ws[0].category is UserWarning
        # global conf will not include this
        assert get_parsed_conf() == {'foo': 1}
        # but it's still a magic object
        assert dict(unparsed_config) == {'bar': 1}