1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
11 from gi.repository import Regress
17 class TestRegistry(unittest.TestCase):
18 def test_non_gi(self):
23 gi.overrides.override(MyClass)
24 self.fail('unexpected success of overriding non-GI class')
25 except TypeError as e:
26 self.assertTrue('Can not override a type MyClass' in str(e))
28 @unittest.skipUnless(Regress, 'built without cairo support')
29 def test_separate_path(self):
30 # Regress override is in tests/gi/overrides, separate from gi/overrides
31 # https://bugzilla.gnome.org/show_bug.cgi?id=680913
32 self.assertEqual(Regress.REGRESS_OVERRIDE, 42)
35 class TestModule(unittest.TestCase):
38 def test_get_introspection_module_caching(self):
39 # This test attempts to minimize side effects by
40 # using a DynamicModule directly instead of going though:
41 # from gi.repository import Foo
43 # Clear out introspection module cache before running this test.
44 old_modules = gi.module._introspection_modules
45 gi.module._introspection_modules = {}
47 mod_name = 'GIMarshallingTests'
48 mod1 = gi.module.get_introspection_module(mod_name)
49 mod2 = gi.module.get_introspection_module(mod_name)
50 self.assertTrue(mod1 is mod2)
52 # Using a DynamicModule will use get_introspection_module internally
53 # in its _load method.
54 mod_overridden = gi.module.DynamicModule(mod_name)
55 mod_overridden._load()
56 self.assertTrue(mod1 is mod_overridden._introspection_module)
58 # Restore the previous cache
59 gi.module._introspection_modules = old_modules
62 class TestImporter(unittest.TestCase):
63 def test_invalid_repository_module_name(self):
64 with self.assertRaises(ImportError) as context:
65 from gi.repository import InvalidGObjectRepositoryModuleName
66 InvalidGObjectRepositoryModuleName # pyflakes
68 exception_string = str(context.exception)
70 self.assertTrue('InvalidGObjectRepositoryModuleName' in exception_string)
72 # The message of the custom exception in gi/importer.py is eaten in Python 2.7
73 if sys.version_info.major < 3:
74 self.assertTrue('introspection typelib' not in exception_string)
76 self.assertTrue('introspection typelib' in exception_string)