本文整理匯總了Python中salt.utils.odict.OrderedDict.copy方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.copy方法的具體用法?Python OrderedDict.copy怎麽用?Python OrderedDict.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類salt.utils.odict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.copy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_compare_sls_vs_yaml_with_jinja
# 需要導入模塊: from salt.utils.odict import OrderedDict [as 別名]
# 或者: from salt.utils.odict.OrderedDict import copy [as 別名]
def test_compare_sls_vs_yaml_with_jinja(self):
tpl = '{{ data }}'
env = jinja2.Environment()
src = '{foo: 1, bar: 2, baz: {qux: true}}'
sls_src = env.from_string(tpl).render(data=yamlex.deserialize(src))
yml_src = env.from_string(tpl).render(data=yaml.deserialize(src))
sls_data = yamlex.deserialize(sls_src)
yml_data = yaml.deserialize(yml_src)
# ensure that sls & yaml have the same base
assert isinstance(sls_data, dict)
assert isinstance(yml_data, dict)
# The below has been commented out because something the loader test
# is modifying the yaml renderer to render things to unicode. Without
# running the loader test, the below passes. Even reloading the module
# from disk does not reset its internal state (per the Python docs).
##
#assert sls_data == yml_data
# ensure that sls is ordered, while yaml not
assert isinstance(sls_data, OrderedDict)
assert not isinstance(yml_data, OrderedDict)
# prove that yaml does not handle well with OrderedDict
# while sls is jinja friendly.
obj = OrderedDict([
('foo', 1),
('bar', 2),
('baz', {'qux': True})
])
sls_obj = yamlex.deserialize(yamlex.serialize(obj))
try:
yml_obj = yaml.deserialize(yaml.serialize(obj))
except SerializationError:
# BLAAM! yaml was unable to serialize OrderedDict,
# but it's not the purpose of the current test.
yml_obj = obj.copy()
sls_src = env.from_string(tpl).render(data=sls_obj)
yml_src = env.from_string(tpl).render(data=yml_obj)
final_obj = yaml.deserialize(sls_src)
assert obj == final_obj
# BLAAM! yml_src is not valid !
final_obj = OrderedDict(yaml.deserialize(yml_src))
assert obj != final_obj
示例2: test_compare_sls_vs_yaml_with_jinja
# 需要導入模塊: from salt.utils.odict import OrderedDict [as 別名]
# 或者: from salt.utils.odict.OrderedDict import copy [as 別名]
def test_compare_sls_vs_yaml_with_jinja(self):
tpl = '{{ data }}'
env = jinja2.Environment()
src = '{foo: 1, bar: 2, baz: {qux: true}}'
sls_src = env.from_string(tpl).render(data=sls.deserialize(src))
yml_src = env.from_string(tpl).render(data=yaml.deserialize(src))
sls_data = sls.deserialize(sls_src)
yml_data = yaml.deserialize(yml_src)
# ensure that sls & yaml have the same base
assert isinstance(sls_data, dict)
assert isinstance(yml_data, dict)
assert sls_data == yml_data
# ensure that sls is ordered, while yaml not
assert isinstance(sls_data, OrderedDict)
assert not isinstance(yml_data, OrderedDict)
# prove that yaml does not handle well with OrderedDict
# while sls is jinja friendly.
obj = OrderedDict([
('foo', 1),
('bar', 2),
('baz', {'qux': True})
])
sls_obj = sls.deserialize(sls.serialize(obj))
try:
yml_obj = yaml.deserialize(yaml.serialize(obj))
except SerializationError:
# BLAAM! yaml was unable to serialize OrderedDict,
# but it's not the purpose of the current test.
yml_obj = obj.copy()
sls_src = env.from_string(tpl).render(data=sls_obj)
yml_src = env.from_string(tpl).render(data=yml_obj)
final_obj = yaml.deserialize(sls_src)
assert obj == final_obj
# BLAAM! yml_src is not valid !
final_obj = yaml.deserialize(yml_src)
assert obj != final_obj