示例#1
0
    def testImportKeywords(self):
        import imports.enum.super
        self.assertEqual(imports.enum.super.var, 1)
        self.assertEqual(imports.enum.super.function(), 2)

        from imports import enumerate
        self.assertEqual(enumerate.list, 1)

        from imports.enumerate import dict
        self.assertEqual(dict(), (1,2))
示例#2
0
    def testImportKeywords(self):
        import imports.enum.super
        self.assertEqual(imports.enum.super.var, 1)
        self.assertEqual(imports.enum.super.function(), 2)

        from imports import enumerate
        self.assertEqual(enumerate.list, 1)

        from imports.enumerate import dict
        self.assertEqual(dict(), (1, 2))
示例#3
0
    def test__new__Method(self):
        c = OtherClass1()
        self.assertEqual(c.__class__.__name__, 'ObjectClass')
        self.assertEqual(c.prop, 1)
        c = OtherSubclass1()
        self.assertEqual(
            c.__class__.__name__, 'ObjectClass',
            "Issue #414: __new__ method on superclass not called")
        c = OtherClass2()
        self.assertEqual(c.__class__.__name__, 'OtherClass2')
        try:
            prop = c.prop
            self.fail(
                "failed to raise an error on c.prop (improperly follows explicit __new__ with implicit __init__)"
            )
        except:
            self.assertTrue(True)
        self.assertTrue(c.init, "OtherClass2.__init__() is not executed")
        try:
            c = OtherClass3(41, 42)
            self.assertTrue(True)
        except:
            self.fail("Issue #417: __new__ method fails for lack of arguments")
        self.assertEqual(
            c.y if hasattr(c, "y") else 0, 42,
            "Issue #417: __new__ method not passed constructor arguments.")

        try:
            c = OtherClass3()
            self.fail(
                "Issue #418: __new__ method doesn't fail for lack of arguments"
            )
        except:
            self.assertTrue(True)
        try:
            c = OtherClass4()
        except TypeError:
            self.fail("TypeError on OtherClass4()")
        c = OtherSubclass4(1, 2, c=3, d=4)
        try:
            self.assertEqual(c.args, (1, 2))
        except AttributeError:
            self.fail("c.args is not defined")
        try:
            self.assertEqual(c.kwargs, dict(c=3, d=4))
        except AttributeError:
            self.fail("c.kwargs is not defined")
        instance = MultiBase.__new__(MultiInherit1)
        self.assertEqual(instance.name, 'MultiInherit1')
        instance = MultiInherit1.__new__(MultiBase)
        self.assertEqual(instance.name, 'MultiBase')
        instance = object.__new__(MultiInherit1, **{})
        self.assertEqual(instance.name, 'MultiInherit1')
示例#4
0
    def test__new__Method(self):
        c = OtherClass1()
        self.assertEqual(c.__class__.__name__, 'ObjectClass')
        self.assertEqual(c.prop, 1)
        c = OtherSubclass1()
        self.assertEqual(c.__class__.__name__, 'ObjectClass', "Issue #414: __new__ method on superclass not called")
        c = OtherClass2()
        self.assertEqual(c.__class__.__name__, 'OtherClass2')
        try:
            prop = c.prop
            self.fail("failed to raise an error on c.prop (improperly follows explicit __new__ with implicit __init__)")
        except:
            self.assertTrue(True)
        self.assertTrue(c.init, "OtherClass2.__init__() is not executed")
        try:
            c = OtherClass3(41, 42)
            self.assertTrue(True)
        except:
            self.fail("Issue #417: __new__ method fails for lack of arguments")
        self.assertEqual(c.y if hasattr(c,"y") else 0, 42, "Issue #417: __new__ method not passed constructor arguments.")

        try:
            c = OtherClass3()
            self.fail("Issue #418: __new__ method doesn't fail for lack of arguments")
        except:
            self.assertTrue(True)
        try:
            c = OtherClass4()
        except TypeError:
            self.fail("TypeError on OtherClass4()")
        c = OtherSubclass4(1, 2, c=3, d=4)
        try:
            self.assertEqual(c.args, (1,2))
        except AttributeError:
            self.fail("c.args is not defined")
        try:
            self.assertEqual(c.kwargs, dict(c=3, d=4))
        except AttributeError:
            self.fail("c.kwargs is not defined")
        instance = MultiBase.__new__(MultiInherit1)
        self.assertEqual(instance.name, 'MultiInherit1')
        instance = MultiInherit1.__new__(MultiBase)
        self.assertEqual(instance.name, 'MultiBase')
        instance = object.__new__(MultiInherit1, **{})
        self.assertEqual(instance.name, 'MultiInherit1')