本文整理汇总了Python中pyon.util.containers.DotDict.lock方法的典型用法代码示例。如果您正苦于以下问题:Python DotDict.lock方法的具体用法?Python DotDict.lock怎么用?Python DotDict.lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.util.containers.DotDict
的用法示例。
在下文中一共展示了DotDict.lock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dotdict_copy
# 需要导入模块: from pyon.util.containers import DotDict [as 别名]
# 或者: from pyon.util.containers.DotDict import lock [as 别名]
def test_dotdict_copy(self):
d = DotDict({"foo": "bar"})
d2 = copy.copy(d)
self.assertTrue(hasattr(d2, "foo"))
self.assertEqual("bar", d2.foo)
# output_streams = copy(self.CFG.get_safe('process.publish_streams'))
v = "a12345"
CFG = DotDict()
CFG.process.publish_streams.salinity = v
print "CFG =", CFG
self.assertTrue(hasattr(CFG.process.publish_streams, "salinity"))
self.assertEqual(v, CFG.process.publish_streams.salinity)
self.assertEqual(v, CFG.get_safe("process.publish_streams").salinity)
self.assertEqual(v, copy.copy(CFG.get_safe("process.publish_streams")).salinity)
output_streams = copy.copy(CFG.get_safe("process.publish_streams"))
print "output_streams =", output_streams
self.assertTrue(hasattr(output_streams, "salinity"))
print "output_streams.salinity =", output_streams.salinity
self.assertEqual(v, output_streams.salinity)
first_stream = output_streams.popitem()
print "first_stream =", first_stream
self.assertEqual(v, first_stream[1])
d.lock()
dl = copy.copy(d)
self.assertTrue(hasattr(dl, "foo"))
self.assertEqual("bar", dl.foo)
with self.assertRaises(AttributeError):
d.foo2 = "nope"
示例2: test_dot_dict_constant
# 需要导入模块: from pyon.util.containers import DotDict [as 别名]
# 或者: from pyon.util.containers.DotDict import lock [as 别名]
def test_dot_dict_constant(self):
d = DotDict({"foo": "bar"})
self.assertEqual("bar", d.foo)
d.foo = "somethingnew"
self.assertEqual("somethingnew", d.foo)
# DotDict only checks that an assignment operation is happening when it creates dummy entries
# ... it doesn't check that the dummy entry is on the left hand side of the assignment
k = d.foo1
self.assertIn("foo1", dir(d))
d.lock()
# test assigning directly to a locked dict
with self.assertRaises(AttributeError):
d.foo = "somethingelse"
self.assertEqual("somethingnew", d.foo)
# test dummy-creation-on-assignment loophole
with self.assertRaises(AttributeError):
k = d.foo2
self.assertNotIn("foo2", dir(d))
# test alternate dummy creation method: calling a function with it
with self.assertRaises(AttributeError):
k = lambda _: True
k(d.foo3)
self.assertNotIn("foo3", dir(d))
self.assertNotIn(DICT_LOCKING_ATTR, dir(d))