本文整理汇总了Python中yedit.Yedit.put方法的典型用法代码示例。如果您正苦于以下问题:Python Yedit.put方法的具体用法?Python Yedit.put怎么用?Python Yedit.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yedit.Yedit
的用法示例。
在下文中一共展示了Yedit.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_item_to_dict
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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}))
示例2: test_write
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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)
示例3: test_write_x_y_z
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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')
示例4: test_update_to_list
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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))
示例5: test_append_twice_to_list
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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))
示例6: test_update_to_list_with_curr_value
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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))
示例7: test_dict_array_dict_remove
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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'])
示例8: test_dict_array_dict_remove
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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'))
示例9: test_empty_key_with_int_value
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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])
示例10: test_creating_new_objects_with_trailing_list
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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')
示例11: test_creating_new_objects_with_embedded_list
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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')
示例12: test_accessing_path_with_unexpected_objects
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
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')
示例13: test_keys_with_underscore
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
def test_keys_with_underscore(self):
'''test dict value with none value'''
yed = Yedit("yedit_test.yml", separator=':')
yed.put('z_:y_y', {'test': '{{test}}'})
self.assertTrue(yed.get('z_:y_y') == {'test': '{{test}}'})
示例14: test_adding_yaml_variable
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
def test_adding_yaml_variable(self):
'''test dict value with none value'''
yed = Yedit("yedit_test.yml", separator=':')
yed.put('z:y', '{{test}}')
self.assertTrue(yed.get('z:y') == '{{test}}')
示例15: test_dict_array_dict_access
# 需要导入模块: from yedit import Yedit [as 别名]
# 或者: from yedit.Yedit import put [as 别名]
def test_dict_array_dict_access(self):
'''Testing a create with content'''
yed = Yedit("yedit_test.yml", separator=':')
yed.put('b:c:d[0]', [{'x': {'y': 'inject'}}])
self.assertTrue(yed.get('b:c:d[0]:[0]:x:y') == 'inject')