Esempio n. 1
0
    def test_self_referencing_interface(self):
        class TreeNode(Interface):
            pass

        TreeNode.add_attribute('left', optional(TreeNode))
        TreeNode.add_attribute('right', optional(TreeNode))

        class TreeNodeImplementation:
            def __init__(self):
                self.left = None
                self.right = None

        tree = TreeNodeImplementation()
        tree.left = TreeNodeImplementation()
        tree.right = TreeNodeImplementation()

        self.assertIsInstance(tree, TreeNode)

        tree.left = 1
        self.assertNotIsInstance(tree, TreeNode)
Esempio n. 2
0
 def test_optional(self):
     self.assertIsInstance(1, optional(int))
     self.assertIsInstance(None, optional(int))
     self.assertNotIsInstance('string', optional(int))
Esempio n. 3
0
 def test(a: optional(int)):
     return a