Exemple #1
0
 def test_write(self):
     ''' Testing a simple write '''
     yed = Yedit('yedit_test.yml')
     yed.put('key1', 1)
     yed.write()
     self.assertTrue('key1' in yed.yaml_dict)
     self.assertEqual(yed.yaml_dict['key1'], 1)
Exemple #2
0
 def test_pop_list_item_2(self):
     '''test dict value with none value'''
     z = list(range(10))
     yed = Yedit(content=z, separator=':')
     yed.pop('', 5)
     z.pop(5)
     self.assertTrue(z == yed.yaml_dict)
Exemple #3
0
 def test_delete_a(self):
     '''Testing a simple delete '''
     yed = Yedit('yedit_test.yml')
     yed.delete('a')
     yed.write()
     yed.load()
     self.assertTrue('a' not in yed.yaml_dict)
Exemple #4
0
 def test_write_x_y_z(self):
     '''Testing a write of multilayer key'''
     yed = Yedit('yedit_test.yml')
     yed.put('x.y.z', 'modified')
     yed.write()
     yed.load()
     self.assertEqual(yed.get('x.y.z'), 'modified')
Exemple #5
0
 def test_add_item_to_dict(self):
     '''Testing update to dict'''
     yed = Yedit("yedit_test.yml", separator=':')
     yed.put('x:y:z', {'a': 1, 'b': 2})
     yed.update('x:y:z', {'c': 3, 'd': 4})
     self.assertTrue(yed.get('x:y:z') == {'a': 1, 'b': 2, 'c': 3, 'd': 4})
     self.assertTrue(yed.exists('x:y:z', {'c': 3}))
Exemple #6
0
 def test_delete_b_c(self):
     '''Testing delete of layered key '''
     yed = Yedit('yedit_test.yml', separator=':')
     yed.delete('b:c')
     yed.write()
     yed.load()
     self.assertTrue('b' in yed.yaml_dict)
     self.assertFalse('c' in yed.yaml_dict['b'])
Exemple #7
0
 def test_update_to_list(self):
     '''Testing update to list'''
     yed = Yedit("yedit_test.yml", separator=':')
     yed.put('x:y:z', [1, 2, 3])
     yed.update('x:y:z', [5, 6])
     self.assertTrue(yed.get('x:y:z') == [1, 2, 3, [5, 6]])
     self.assertTrue(yed.exists('x:y:z', [5, 6]))
     self.assertFalse(yed.exists('x:y:z', 4))
Exemple #8
0
 def test_append_twice_to_list(self):
     '''Testing append to list'''
     yed = Yedit("yedit_test.yml", separator=':')
     yed.put('x:y:z', [1, 2, 3])
     yed.append('x:y:z', [5, 6])
     yed.append('x:y:z', [5, 6])
     self.assertTrue(yed.get('x:y:z') == [1, 2, 3, [5, 6], [5, 6]])
     self.assertFalse(yed.exists('x:y:z', 4))
Exemple #9
0
 def test_delete_b_c(self):
     '''Testing delete of layered key '''
     yed = Yedit('yedit_test.yml')
     yed.delete('b:c')
     yed.write()
     yed.load()
     self.assertTrue(yed.yaml_dict.has_key('b'))
     self.assertFalse(yed.yaml_dict['b'].has_key('c'))
Exemple #10
0
 def test_update_to_list_with_curr_value(self):
     '''Testing update to list with index'''
     yed = Yedit("yedit_test.yml", separator=':')
     yed.put('x:y:z', [1, 2, 3])
     yed.update('x:y:z', [5, 6], curr_value=3)
     self.assertTrue(yed.get('x:y:z') == [1, 2, [5, 6]])
     self.assertTrue(yed.exists('x:y:z', [5, 6]))
     self.assertFalse(yed.exists('x:y:z', 4))
Exemple #11
0
 def test_update_to_list_with_index(self):
     '''Testing update to list with index'''
     yed = Yedit("yedit_test.yml")
     yed.put('x:y:z', [1, 2, 3])
     yed.update('x:y:z', [5, 6], index=2)
     self.assertTrue(yed.get('x:y:z') == [1, 2, [5, 6]])
     self.assertTrue(yed.exists('x:y:z', [5, 6]))
     self.assertFalse(yed.exists('x:y:z', 4))
Exemple #12
0
 def test_create_content(self):
     '''Testing a create with content '''
     content = {"foo": "bar"}
     yed = Yedit("yedit_test.yml", content)
     yed.write()
     yed.load()
     self.assertTrue('foo' in yed.yaml_dict)
     self.assertTrue(yed.yaml_dict['foo'], 'bar')
Exemple #13
0
 def test_create(self):
     '''Testing a create '''
     os.unlink(YeditTest.filename)
     yed = Yedit('yedit_test.yml')
     yed.create('foo', 'bar')
     yed.write()
     yed.load()
     self.assertTrue('foo' in yed.yaml_dict)
     self.assertTrue(yed.yaml_dict['foo'] == 'bar')
Exemple #14
0
 def test_append_twice_to_list(self):
     '''Testing append to list'''
     yed = Yedit("yedit_test.yml", separator=':')
     yed.put('x:y:z', [1, 2, 3])
     yed.append('x:y:z', [5, 6])
     yed.append('x:y:z', [5, 6])
     self.assertTrue(yed.get('x:y:z') == [1, 2, 3, [5, 6], [5, 6]])
     # pylint: disable=maybe-no-member
     self.assertTrue(2 == yed.get('x:y:z').count([5, 6]))
     self.assertFalse(yed.exists('x:y:z', 4))
Exemple #15
0
 def test_dict_array_dict_remove(self):
     '''Testing multilevel delete'''
     yed = Yedit("yedit_test.yml", separator=':')
     yed.put('b:c:d[0]', [{'x': {'y': 'inject'}}])
     yed.delete('b:c:d[0]:[0]:x:y')
     self.assertTrue('b' in yed.yaml_dict)
     self.assertTrue('c' in yed.yaml_dict['b'])
     self.assertTrue('d' in yed.yaml_dict['b']['c'])
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'], list))
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0], list))
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0][0], dict))
     self.assertFalse('y' in yed.yaml_dict['b']['c']['d'][0][0]['x'])
 def test_dict_array_dict_remove(self):
     '''Testing multilevel delete'''
     yed = Yedit("yedit_test.yml")
     yed.put('b.c.d[0]', [{'x': {'y': 'inject'}}])
     yed.delete('b.c.d[0].[0].x.y')
     self.assertTrue(yed.yaml_dict.has_key('b'))
     self.assertTrue(yed.yaml_dict['b'].has_key('c'))
     self.assertTrue(yed.yaml_dict['b']['c'].has_key('d'))
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'], list))
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0], list))
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0][0], dict))
     self.assertFalse(yed.yaml_dict['b']['c']['d'][0][0]['x'].has_key('y'))
Exemple #17
0
 def test_dict_array_dict_replace(self):
     '''Testing multilevel delete'''
     yed = Yedit("yedit_test.yml")
     yed.put('b:c:d[0]', [{'x': {'y': 'inject'}}])
     yed.put('b:c:d[0]:[0]:x:y', 'testing')
     self.assertTrue(yed.yaml_dict.has_key('b'))
     self.assertTrue(yed.yaml_dict['b'].has_key('c'))
     self.assertTrue(yed.yaml_dict['b']['c'].has_key('d'))
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'], list))
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0], list))
     self.assertTrue(isinstance(yed.yaml_dict['b']['c']['d'][0][0], dict))
     self.assertTrue(yed.yaml_dict['b']['c']['d'][0][0]['x'].has_key('y'))
     self.assertTrue(yed.yaml_dict['b']['c']['d'][0][0]['x']['y'], 'testing')
Exemple #18
0
 def test_append_base_list(self):
     '''test removing list entry'''
     content = [{'a': {'b': [{'c': 3}]}}]
     yed = Yedit(content=content)
     yed.put("[1]", [{"next": "something"}])
     self.assertTrue(yed.yaml_dict, [{
         'a': {
             'b': [{
                 'c': 3
             }]
         }
     }, {
         "next": "something"
     }])
Exemple #19
0
 def test_pop_dict_key(self):
     '''test dict value with none value'''
     yed = Yedit(content={'a': {'b': {'c': 1, 'd': 2}}}, separator='#')
     yed.pop('a#b', 'c')
     self.assertTrue({'a': {'b': {'d': 2}}} == yed.yaml_dict)
Exemple #20
0
 def test_first_level_array_update(self):
     '''test update on top level array'''
     yed = Yedit(content=[{'a': 1}, {'b': 2}, {'b': 3}], separator=':')
     yed.update('', {'c': 4})
     self.assertTrue({'c': 4} in yed.get(''))
Exemple #21
0
 def test_first_level_array_delete(self):
     '''test remove top level key'''
     yed = Yedit(content=[{'a': 1}, {'b': 2}, {'b': 3}])
     yed.delete('')
     self.assertTrue({'b': 3} not in yed.get(''))
Exemple #22
0
 def test_first_level_array_get(self):
     '''test dict value with none value'''
     yed = Yedit(content=[{'a': 1}, {'b': 2}, {'b': 3}])
     yed.get('')
     self.assertTrue([{'a': 1}, {'b': 2}, {'b': 3}] == yed.yaml_dict)
Exemple #23
0
 def test_pop_list_item(self):
     '''test dict value with none value'''
     yed = Yedit(content=[{'a': 1}, {'b': 2}, {'b': 3}], separator=':')
     yed.pop('', {'b': 2})
     self.assertTrue([{'a': 1}, {'b': 3}] == yed.yaml_dict)
Exemple #24
0
 def test_load(self):
     ''' Testing a get '''
     yed = Yedit('yedit_test.yml')
     self.assertEqual(yed.yaml_dict, self.data)
Exemple #25
0
 def setUp(self):
     ''' setup method will create a file and set to known configuration '''
     yed = Yedit(YeditTest.filename)
     yed.yaml_dict = YeditTest.data
     yed.write()
Exemple #26
0
 def test_setting_separator(self):
     '''test editing top level with not list or dict'''
     yed = Yedit(content={'a': {'b': 12}})
     yed.separator = ':'
     self.assertEqual(yed.separator, ':')
Exemple #27
0
 def test_empty_key_with_int_value(self):
     '''test editing top level with not list or dict'''
     yed = Yedit(content={'a': {'b': 12}})
     result = yed.put('', 'b')
     self.assertFalse(result[0])
Exemple #28
0
 def test_creating_new_objects_with_trailing_list(self):
     '''test creating new object(s) where the final piece is a list'''
     yed = Yedit(content={'a': {'b': 12}})
     with self.assertRaises(YeditException):
         yed.put('new.stuff.here[0]', 'item')
Exemple #29
0
 def test_creating_new_objects_with_embedded_list(self):
     '''test creating new objects with an embedded list in the creation path'''
     yed = Yedit(content={'a': {'b': 12}})
     with self.assertRaises(YeditException):
         yed.put('new.stuff[0].here', 'value')
Exemple #30
0
 def test_accessing_path_with_unexpected_objects(self):
     '''test providing source path objects that differ from current object state'''
     yed = Yedit(content={'a': {'b': {'c': ['d', 'e']}}})
     with self.assertRaises(YeditException):
         yed.put('a.b.c.d', 'x')