def test_restore(self): with open(self.filename, 'w') as fh: yaml.dump(self.test_data, fh) keys = [yamlstore.YamlKey('one', 'a'), yamlstore.YamlKey('three', 'c')] state_data = self.store.restore(keys) assert_equal(self.store.buffer, self.test_data) expected = {keys[0]: 1, keys[1]: 3} assert_equal(expected, state_data)
def test_save(self): expected = {'one': {'five': 'dataz'}, 'two': {'seven': 'stars'}} key_value_pairs = [(yamlstore.YamlKey('one', 'five'), 'barz')] # Save first self.store.save(key_value_pairs) # Save second key_value_pairs = [(yamlstore.YamlKey('two', 'seven'), 'stars'), (yamlstore.YamlKey('one', 'five'), 'dataz')] self.store.save(key_value_pairs) assert_equal(self.store.buffer, expected) with open(self.filename, 'r') as fh: actual = yaml.load(fh) assert_equal(actual, expected)
def test_restore_missing_type_key(self): with open(self.filename, 'w') as fh: yaml.dump(self.test_data, fh) keys = [yamlstore.YamlKey('seven', 'a')] state_data = self.store.restore(keys) assert_equal(self.store.buffer, self.test_data) assert_equal({}, state_data)
def test_delete(self): expected = {'state_a': {'five': 'barz'}} key_value_pairs = [ (yamlstore.YamlKey('state_a', 'five'), 'barz'), (yamlstore.YamlKey('state_c', 'five'), 'delete_all_c'), (yamlstore.YamlKey('state_a', 'six'), 'delete_one_a'), ] # Save first self.store.save(key_value_pairs) # Save second key_value_pairs = [ (yamlstore.YamlKey('state_c', 'five'), None), (yamlstore.YamlKey('state_a', 'six'), None), ] self.store.save(key_value_pairs) assert_equal(self.store.buffer, expected) with open(self.filename, 'r') as fh: actual = yaml.load(fh) assert_equal(actual, expected)