def test_save_and_load_interoperate(self): logfile = self.make_file(name='test.log') saved_file = self.make_file() Config.save({'logfile': logfile}, saved_file) loaded_config = Config.load(saved_file) self.assertEqual(logfile, loaded_config['logfile'])
def test_save_defaults_to_default_filename(self): logfile = self.make_file(name='test.log') filename = self.make_file(name="config.yaml") self.patch(Config, 'DEFAULT_FILENAME', filename) Config.save({'logfile': logfile}) self.assertEqual(logfile, Config.load(filename)['logfile'])
def test_save_saves_yaml_file(self): config = {'logfile': self.make_file()} saved_file = self.make_file() Config.save(config, saved_file) with open(saved_file, 'rb') as written_file: loaded_config = yaml.load(written_file) self.assertEqual(config, loaded_config)
def test_create_backup_creates_backup(self): logfile = self.make_file(name='test.log') filename = self.make_file(name="config.yaml") config = {'logfile': logfile} yaml_config = yaml.safe_dump(config) self.patch(Config, 'DEFAULT_FILENAME', filename) Config.save(config) Config.create_backup('test') backup_name = "%s.%s.bak" % (filename, 'test') self.assertThat(backup_name, FileContains(yaml_config))