[pygobject] tests: Add tests for MRO override



commit 7aca95781fc76f3e820e63325ccc07d128a60075
Author: Daniel Drake <dsd laptop org>
Date:   Wed Jul 10 10:45:47 2013 -0600

    tests: Add tests for MRO override
    
    Add tests for the MRO override to prevent against unintended
    behaviour changes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703829

 tests/test_gi.py |   66 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 50 insertions(+), 16 deletions(-)
---
diff --git a/tests/test_gi.py b/tests/test_gi.py
index f01dbb6..1d56fae 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2307,22 +2307,6 @@ class TestInterfaces(unittest.TestCase):
         self.assertEqual(instance.val, None)
         self.assertEqual(instance.val2, 42)
 
-    def test_mro(self):
-        # there was a problem with Python bailing out because of
-        # http://en.wikipedia.org/wiki/Diamond_problem with interfaces,
-        # which shouldn't really be a problem.
-
-        class TestInterfaceImpl(GObject.GObject, GIMarshallingTests.Interface):
-            pass
-
-        class TestInterfaceImpl2(GIMarshallingTests.Interface,
-                                 TestInterfaceImpl):
-            pass
-
-        class TestInterfaceImpl3(self.TestInterfaceImpl,
-                                 GIMarshallingTests.Interface2):
-            pass
-
     def test_type_mismatch(self):
         obj = GIMarshallingTests.Object()
 
@@ -2387,6 +2371,56 @@ class TestInterfaces(unittest.TestCase):
                 self.assertTrue('GIMarshallingTests.Object' in str(e), e)
 
 
+class TestMRO(unittest.TestCase):
+    def test_mro(self):
+        # check that our own MRO calculation matches what we would expect
+        # from Python's own C3 calculations
+        class A(object):
+            pass
+
+        class B(A):
+            pass
+
+        class C(A):
+            pass
+
+        class D(B, C):
+            pass
+
+        class E(D, GIMarshallingTests.Object):
+            pass
+
+        expected = (E, D, B, C, A, GIMarshallingTests.Object,
+                    GObject.Object, GObject.Object.__base__, gi._gobject.GObject,
+                    object)
+        self.assertEqual(expected, E.__mro__)
+
+    def test_interface_collision(self):
+        # there was a problem with Python bailing out because of
+        # http://en.wikipedia.org/wiki/Diamond_problem with interfaces,
+        # which shouldn't really be a problem.
+
+        class TestInterfaceImpl(GObject.GObject, GIMarshallingTests.Interface):
+            pass
+
+        class TestInterfaceImpl2(GIMarshallingTests.Interface,
+                                 TestInterfaceImpl):
+            pass
+
+        class TestInterfaceImpl3(TestInterfaceImpl,
+                                 GIMarshallingTests.Interface2):
+            pass
+
+    def test_old_style_mixin(self):
+        # Note: Old style classes don't exist in Python 3
+        class Mixin:
+            pass
+
+        # Dynamically create a new gi based class with an old
+        # style mixin.
+        type('GIWithOldStyleMixin', (GIMarshallingTests.Object, Mixin), {})
+
+
 class TestInterfaceClash(unittest.TestCase):
 
     def test_clash(self):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]