当前位置: 首页>>代码示例>>Python>>正文


Python DotDict.lock方法代码示例

本文整理汇总了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"
开发者ID:ateranishi,项目名称:pyon,代码行数:34,代码来源:test_containers.py

示例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))
开发者ID:ateranishi,项目名称:pyon,代码行数:32,代码来源:test_containers.py


注:本文中的pyon.util.containers.DotDict.lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。