diff options
Diffstat (limited to 'tests/test_overrides.py')
-rw-r--r-- | tests/test_overrides.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_overrides.py b/tests/test_overrides.py index dd2aa6a..e1af1f1 100644 --- a/tests/test_overrides.py +++ b/tests/test_overrides.py @@ -4,6 +4,8 @@ import unittest import gi.overrides +import gi.module + try: from gi.repository import Regress Regress # pyflakes @@ -27,3 +29,30 @@ class TestRegistry(unittest.TestCase): # Regress override is in tests/gi/overrides, separate from gi/overrides # https://bugzilla.gnome.org/show_bug.cgi?id=680913 self.assertEqual(Regress.REGRESS_OVERRIDE, 42) + + +class TestModule(unittest.TestCase): + # Tests for gi.module + + def test_get_introspection_module_caching(self): + # This test attempts to minimize side effects by + # using a DynamicModule directly instead of going though: + # from gi.repository import Foo + + # Clear out introspection module cache before running this test. + old_modules = gi.module._introspection_modules + gi.module._introspection_modules = {} + + mod_name = 'GIMarshallingTests' + mod1 = gi.module.get_introspection_module(mod_name) + mod2 = gi.module.get_introspection_module(mod_name) + self.assertTrue(mod1 is mod2) + + # Using a DynamicModule will use get_introspection_module internally + # in its _load method. + mod_overridden = gi.module.DynamicModule(mod_name) + mod_overridden._load() + self.assertTrue(mod1 is mod_overridden._introspection_module) + + # Restore the previous cache + gi.module._introspection_modules = old_modules |