1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
10 from gi.repository import Regress
16 class TestRegistry(unittest.TestCase):
17 def test_non_gi(self):
22 gi.overrides.override(MyClass)
23 self.fail('unexpected success of overriding non-GI class')
24 except TypeError as e:
25 self.assertTrue('Can not override a type MyClass' in str(e))
27 @unittest.skipUnless(Regress, 'built without cairo support')
28 def test_separate_path(self):
29 # Regress override is in tests/gi/overrides, separate from gi/overrides
30 # https://bugzilla.gnome.org/show_bug.cgi?id=680913
31 self.assertEqual(Regress.REGRESS_OVERRIDE, 42)
34 class TestModule(unittest.TestCase):
37 def test_get_introspection_module_caching(self):
38 # This test attempts to minimize side effects by
39 # using a DynamicModule directly instead of going though:
40 # from gi.repository import Foo
42 # Clear out introspection module cache before running this test.
43 old_modules = gi.module._introspection_modules
44 gi.module._introspection_modules = {}
46 mod_name = 'GIMarshallingTests'
47 mod1 = gi.module.get_introspection_module(mod_name)
48 mod2 = gi.module.get_introspection_module(mod_name)
49 self.assertTrue(mod1 is mod2)
51 # Using a DynamicModule will use get_introspection_module internally
52 # in its _load method.
53 mod_overridden = gi.module.DynamicModule(mod_name)
54 mod_overridden._load()
55 self.assertTrue(mod1 is mod_overridden._introspection_module)
57 # Restore the previous cache
58 gi.module._introspection_modules = old_modules