[pygobject] Fix help() for GI modules



commit c0607d970fc59528ca27d518282cf2871b92e909
Author: Martin Pitt <martinpitt gnome org>
Date:   Mon Jul 16 16:00:40 2012 +0200

    Fix help() for GI modules
    
    Derive DynamicModule from types.ModuleType, so that the inspect modules'
    ismodule() actually succeeds on those and generates useful help on a GI
    repository module.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679804

 gi/module.py     |    3 ++-
 tests/test_gi.py |   15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index 2d26823..2d02c9a 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -23,6 +23,7 @@
 from __future__ import absolute_import
 
 import sys
+import types
 
 _have_py3 = (sys.version_info.major >= 3)
 
@@ -228,7 +229,7 @@ class IntrospectionModule(object):
         return list(result)
 
 
-class DynamicModule(object):
+class DynamicModule(types.ModuleType):
     def __init__(self, namespace):
         self._namespace = namespace
         self._introspection_module = None
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 9d014ee..62ed357 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -10,6 +10,8 @@ import shutil
 import os
 import locale
 import subprocess
+from io import StringIO
+
 from gi.repository import GObject, GLib
 
 from gi.repository import GIMarshallingTests
@@ -2274,3 +2276,16 @@ class TestModule(unittest.TestCase):
         for item_name in _dir:
             item = getattr(GIMarshallingTests, item_name)
             self.assertTrue(hasattr(item, '__class__'))
+
+    def test_help(self):
+        orig_stdout = sys.stdout
+        try:
+            sys.stdout = StringIO()
+            help(GIMarshallingTests)
+            output = sys.stdout.getvalue()
+        finally:
+            sys.stdout = orig_stdout
+
+        self.assertTrue('SimpleStruct' in output, output)
+        self.assertTrue('Interface2' in output, output)
+        self.assertTrue('method_array_inout' in output, output)



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