def test_save_config_to_readonly_file_with_logger(*args, **kwargs): with tempfile.NamedTemporaryFile() as tmpfile: environ = {'COFFER_CONFIG': tmpfile.name} with mock.patch('os.environ', environ): cfg = config.load_config() assert_config_equals(cfg, config._defaults) cfg.add_section('test') cfg.set('test', 'test', 'test') with tempfile.NamedTemporaryFile() as tmpfile: os.chmod(tmpfile.name, ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)) environ = {'COFFER_CONFIG': tmpfile.name} with mock.patch('os.environ', environ): config.save_config(cfg, logger=LoggerDecoy()) loaded_cfg = config.load_config() assert_config_equals(loaded_cfg, config._defaults)
def test_load_custom_config(*args, **kwargs): with tempfile.NamedTemporaryFile() as tmpfile: tmpfile.write(b'[interactive]\nprompt = test>\n') custom_cfg_dict = {'interactive': {'prompt': 'test>'}} custom_cfg_dict.update(config._defaults) environ = {'COFFER_CONFIG': tmpfile.name} with mock.patch('os.environ', environ): cfg = config.load_config() assert_config_equals(cfg, custom_cfg_dict)
def test_save_config_to_non_existent_file(*args, **kwargs): with tempfile.NamedTemporaryFile() as tmpfile: environ = {'COFFER_CONFIG': tmpfile.name} with mock.patch('os.environ', environ): cfg = config.load_config() assert_config_equals(cfg, config._defaults) cfg.add_section('test') cfg.set('test', 'test', 'test') with tempfile.NamedTemporaryFile() as tmpfile: filename = tmpfile.name ok_(not os.path.exists(filename), '{} exists'.format(filename)) environ = {'COFFER_CONFIG': filename} with mock.patch('os.environ', environ): config.save_config(cfg) loaded_cfg = config.load_config() assert_config_equals(loaded_cfg, config._defaults)
def test_save_config_with_modifications(*args, **kwargs): with tempfile.NamedTemporaryFile() as tmpfile: environ = {'COFFER_CONFIG': tmpfile.name} with mock.patch('os.environ', environ): cfg = config.load_config() assert_config_equals(cfg, config._defaults) cfg.add_section('test') cfg.set('test', 'test', 'test') with tempfile.NamedTemporaryFile() as tmpfile: environ = {'COFFER_CONFIG': tmpfile.name} with mock.patch('os.environ', environ): config.save_config(cfg) loaded_cfg = config.load_config() new_dict = {'test': {'test': 'test'}} new_dict.update(config._defaults) assert_config_equals(loaded_cfg, new_dict)
def test_load_default_config(*args, **kwargs): with tempfile.NamedTemporaryFile() as tmpfile: environ = {'COFFER_CONFIG': tmpfile.name} with mock.patch('os.environ', environ): cfg = config.load_config() assert_config_equals(cfg, config._defaults)