def update_from_file(): config_filename = join(dirname(__file__), 'test.cfg') config = Config() config.update_from_file(config_filename) assert config['debug'] is True assert config['database_uri'] == 'sqlite://' assert '_hidden' not in config # should not overwrite config['debug'] = False del config['database_uri'] config.update_from_file(config_filename) assert config['debug'] is False assert config['database_uri'] == 'sqlite://' # should overwrite config['debug'] = False del config['database_uri'] config.update_from_file(config_filename, overwrite=True) assert config['debug'] is True assert config['database_uri'] == 'sqlite://'
def update_from_object(): class config_object: debug = True database_uri = 'sqlite://' _hidden = 123 config = Config() config.update_from_object(config_object) assert config['debug'] is True assert config['database_uri'] == 'sqlite://' assert '_hidden' not in config # should not overwrite config['debug'] = False del config['database_uri'] config.update_from_object(config_object) assert config['debug'] is False assert config['database_uri'] == 'sqlite://' # should overwrite config['debug'] = False del config['database_uri'] config.update_from_object(config_object, overwrite=True) assert config['debug'] is True assert config['database_uri'] == 'sqlite://'
def update_unless_exists(): config = Config(a=1, b=2, c=3) config.update_unless_exists({'b': 1, 'd': 2, 'e': 3}, c=4, f=5) assert dict(config) == {'a': 1, 'b': 2, 'c': 3, 'd': 2, 'e': 3, 'f': 5}