Ejemplo n.º 1
0
    def test_add_subconfig_adds_config_as_attribute(self):
        main_config = Config()
        sub_config = Config({"abc": "123"})

        main_config.add_subconfig('mysubconfig', sub_config)
        assert 'mysubconfig' in main_config._subconfigs
        assert main_config._subconfigs['mysubconfig'] == sub_config

        assert hasattr(main_config, 'mysubconfig')
        assert main_config.mysubconfig == sub_config
Ejemplo n.º 2
0
    def test_add_subconfig_adds_config_as_attribute(self):
        main_config = Config()
        sub_config = Config({"abc": "123"})

        main_config.add_subconfig('mysubconfig', sub_config)
        assert 'mysubconfig' in main_config._subconfigs
        assert main_config._subconfigs['mysubconfig'] == sub_config

        assert hasattr(main_config, 'mysubconfig')
        assert main_config.mysubconfig == sub_config
Ejemplo n.º 3
0
    def test_load_method_forces_subconfig_adapters_loading(self):
        main_config = Config()

        subconfig = Config()
        subconfig_env_adapter = Env("TEST")
        subconfig.register(subconfig_env_adapter)

        main_config.add_subconfig('test_subconfig', subconfig)

        os.environ["TEST"] = "test"

        assert hasattr(main_config, 'test_subconfig')
        assert main_config.test_subconfig == subconfig
        assert not main_config.test_subconfig

        main_config.load()

        assert 'TEST' in main_config.test_subconfig
        assert main_config.test_subconfig['TEST'] == 'test'

        del os.environ["TEST"]
Ejemplo n.º 4
0
    def test_load_method_forces_subconfig_adapters_loading(self):
        main_config = Config()

        subconfig = Config()
        subconfig_env_adapter = Env("TEST")
        subconfig.register(subconfig_env_adapter)

        main_config.add_subconfig('test_subconfig', subconfig)

        os.environ["TEST"] = "test"

        assert hasattr(main_config, 'test_subconfig')
        assert main_config.test_subconfig == subconfig
        assert not main_config.test_subconfig

        main_config.load()

        assert 'TEST' in main_config.test_subconfig
        assert main_config.test_subconfig['TEST'] == 'test'

        del os.environ["TEST"]
Ejemplo n.º 5
0
    def test_add_subconfig_with_invalid_type_raises(self):
        config = Config()

        with pytest.raises(TypeError):
            config.add_subconfig(config)
Ejemplo n.º 6
0
    def test_add_subconfig_with_invalid_type_raises(self):
        config = Config()

        with pytest.raises(TypeError):
            config.add_subconfig(config)