當前位置: 首頁>>代碼示例>>Python>>正文


Python samples.Thing類代碼示例

本文整理匯總了Python中samples.Thing的典型用法代碼示例。如果您正苦於以下問題:Python Thing類的具體用法?Python Thing怎麽用?Python Thing使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Thing類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_thing_with_module

    def test_thing_with_module(self):
        obj = Thing('with-module')
        obj.themodule = os

        flattened = self.pickler.flatten(obj)
        inflated = self.unpickler.restore(flattened)
        self.assertEqual(inflated.themodule, os)
開發者ID:eoghanmurray,項目名稱:jsonpickle_prev,代碼行數:7,代碼來源:jsonpickle_test.py

示例2: test_recursive

    def test_recursive(self):
        """create a recursive structure and test that we can handle it
        """
        parent = Thing('parent')
        child = Thing('child')
        child.sibling = Thing('sibling')

        parent.self = parent
        parent.child = child
        parent.child.twin = child
        parent.child.parent = parent
        parent.child.sibling.parent = parent

        cloned = jsonpickle.decode(jsonpickle.encode(parent))

        self.assertEqual(parent.name,
                         cloned.name)
        self.assertEqual(parent.child.name,
                         cloned.child.name)
        self.assertEqual(parent.child.sibling.name,
                         cloned.child.sibling.name)
        self.assertEqual(cloned,
                         cloned.child.parent)
        self.assertEqual(cloned,
                         cloned.child.sibling.parent)
        self.assertEqual(cloned,
                         cloned.child.twin.parent)
        self.assertEqual(cloned.child,
                         cloned.child.twin)
開發者ID:eoghanmurray,項目名稱:jsonpickle_prev,代碼行數:29,代碼來源:jsonpickle_test.py

示例3: test_thing_with_submodule

    def test_thing_with_submodule(self):
        from distutils import sysconfig

        obj = Thing('with-submodule')
        obj.submodule = sysconfig

        flattened = self.pickler.flatten(obj)
        inflated = self.unpickler.restore(flattened)
        self.assertEqual(inflated.submodule, sysconfig)
開發者ID:eoghanmurray,項目名稱:jsonpickle_prev,代碼行數:9,代碼來源:jsonpickle_test.py

示例4: test_list_item_reference

    def test_list_item_reference(self):
        thing = Thing('parent')
        thing.child = Thing('child')
        thing.child.refs = [thing]

        encoded = jsonpickle.encode(thing)
        decoded = jsonpickle.decode(encoded)

        self.assertEqual(id(decoded.child.refs[0]), id(decoded))
開發者ID:edmund-huber,項目名稱:jsonpickle,代碼行數:9,代碼來源:jsonpickle_test.py

示例5: test_class_reference

    def test_class_reference(self):
        """This test ensures that users can store references to classes.
        """
        obj = Thing("object-with-class-reference")

        # reference the 'Thing' class (not an instance of the class)
        obj.classref = Thing

        flattened = self.pickler.flatten(obj)
        self.assertEqual(flattened["classref"], {tags.TYPE: "samples.Thing"})

        inflated = self.unpickler.restore(flattened)
        self.assertEqual(inflated.classref, Thing)
開發者ID:,項目名稱:,代碼行數:13,代碼來源:

示例6: test_type_reference

    def test_type_reference(self):
        """This test ensures that users can store references to types.
        """
        obj = Thing("object-with-type-reference")

        # reference the built-in 'object' type
        obj.typeref = object

        flattened = self.pickler.flatten(obj)
        self.assertEqual(flattened["typeref"], {tags.TYPE: "__builtin__.object"})

        inflated = self.unpickler.restore(flattened)
        self.assertEqual(inflated.typeref, object)
開發者ID:,項目名稱:,代碼行數:13,代碼來源:

示例7: test_class

    def test_class(self):
        inst = Thing('test name')
        inst.child = Thing('child name')

        flattened = self.pickler.flatten(inst)
        self.assertEqual('test name', flattened['name'])
        child = flattened['child']
        self.assertEqual('child name', child['name'])

        inflated = self.unpickler.restore(flattened)
        self.assertEqual('test name', inflated.name)
        self.assertTrue(type(inflated) is Thing)
        self.assertEqual('child name', inflated.child.name)
        self.assertTrue(type(inflated.child) is Thing)
開發者ID:eoghanmurray,項目名稱:jsonpickle_prev,代碼行數:14,代碼來源:jsonpickle_test.py

示例8: test_reference_to_list

    def test_reference_to_list(self):
        thing = Thing('parent')
        thing.a = [1]
        thing.b = thing.a
        thing.b.append(thing.a)
        thing.b.append([thing.a])

        encoded = jsonpickle.encode(thing)
        decoded = jsonpickle.decode(encoded)

        self.assertEqual(decoded.a[0], 1)
        self.assertEqual(decoded.b[0], 1)
        self.assertEqual(id(decoded.a), id(decoded.b))
        self.assertEqual(id(decoded.a), id(decoded.a[1]))
        self.assertEqual(id(decoded.a), id(decoded.a[2][0]))
開發者ID:edmund-huber,項目名稱:jsonpickle,代碼行數:15,代碼來源:jsonpickle_test.py


注:本文中的samples.Thing類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。