Commit 7aca9578 authored by Daniel Drake's avatar Daniel Drake Committed by Simon Feltman
Browse files

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
parent a15333a3
......@@ -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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment