def test_configuration_get_section(): path = os.path.join(ROOT, 'config.json') config = ConfigurationBuilder() \ .add_json_file(path) \ .add_json_file('test.json', optional=True) \ .build() section = config.get_section('Nested') assert isinstance(section, IConfiguration) assert section.to_dict() == {"Bar": "foo", "Foo": "zoo"}
def test_configuration_builder_parsing(): path = os.path.join(ROOT, 'config.json') config = ConfigurationBuilder() \ .add_json_file(path) \ .add_json_file('test.json', optional=True) \ .build() assert config.parse_value('value', int) == 111 assert config.parse_value('json', json) == {'x': None} assert config.parse_value('time', timedelta) == timedelta(seconds=15, hours=123)
def test_configuration_builder_with_overwritten_env(): with env_var('foo-key', 'test'): path = os.path.join(ROOT, 'config.json') config = ConfigurationBuilder() \ .add_json_file(path) \ .add_environment_variables() \ .build() assert config['foo-key'] == 'test'
def test_configuration_builder_with_env(): with env_var('Nested__Bar', 'abc'): path = os.path.join(ROOT, 'config.json') config = ConfigurationBuilder() \ .add_json_file(path) \ .add_environment_variables() \ .build() assert config['Nested:Bar'] == 'abc'
def test_configuration_builder(): path = os.path.join(ROOT, 'config.json') config = ConfigurationBuilder() \ .add_json_file(path) \ .add_json_file('test.json', optional=True) \ .build() assert isinstance(config, IConfiguration) assert config['foo-key'] == 'bar-value'
def test_configuration_get_section_nested(): config = ConfigurationBuilder() \ .add_dict({'foo': {'bar': {'zoo': 1, 'test': 2}}}) \ .build() assert config.get_section('foo:bar').to_dict() == {'zoo': '1', 'test': '2'} assert config.get_section('foo:b').to_dict() == {}
def test_command_line(): config = ConfigurationBuilder() \ .add_command_line(['--test=11', '--foo', 'bar']) \ .build() assert config['test'] == '11' assert config['foo'] == 'bar'