[Checkins] SVN: martian/trunk/ Move fake_import and FakeModule into a testing module.

Martijn Faassen faassen at infrae.com
Thu Jun 5 12:45:06 EDT 2008


Log message for revision 87169:
  Move fake_import and FakeModule into a testing module.
  

Changed:
  U   martian/trunk/CHANGES.txt
  A   martian/trunk/src/martian/testing.py
  U   martian/trunk/src/martian/tests/test_all.py

-=-
Modified: martian/trunk/CHANGES.txt
===================================================================
--- martian/trunk/CHANGES.txt	2008-06-05 12:21:59 UTC (rev 87168)
+++ martian/trunk/CHANGES.txt	2008-06-05 16:45:04 UTC (rev 87169)
@@ -9,6 +9,9 @@
 
 * Add a ``validateClass`` validate function for directives.
 
+* Moved ``FakeModule`` and ``fake_import`` into a ``martian.testing``
+  module so that they can be reused by external packages.
+
 0.9.7 (2008-05-29)
 ==================
 

Copied: martian/trunk/src/martian/testing.py (from rev 87168, martian/trunk/src/martian/tests/test_all.py)
===================================================================
--- martian/trunk/src/martian/testing.py	                        (rev 0)
+++ martian/trunk/src/martian/testing.py	2008-06-05 16:45:04 UTC (rev 87169)
@@ -0,0 +1,46 @@
+import new
+
+class FakeModule(object):
+    pass
+
+def fake_import(fake_module):
+    module = new.module(fake_module.__name__)
+    glob = {}
+    for name in dir(fake_module):
+        if name.startswith('__') and '.' not in name:
+            continue
+        obj = getattr(fake_module, name)
+        glob[name] = obj
+        try:
+            obj = obj.im_func
+        except AttributeError:
+            pass
+        __module__ = None
+        try:
+            __module__ == obj.__dict__.get('__module__')
+        except AttributeError:
+            try:
+                __module__ = obj.__module__
+            except AttributeError:
+                pass
+        if __module__ is None or __module__ == '__builtin__':
+            try:
+                obj.__module__ = module.__name__
+            except AttributeError:
+                pass
+        setattr(module, name, obj)
+
+    # provide correct globals for functions
+    for name in dir(module):
+        if name.startswith('__'):
+            continue
+        obj = getattr(module, name)
+        try:
+            code = obj.func_code
+            new_func = new.function(code, glob, name)
+            new_func.__module__ = module.__name__
+            setattr(module, name, new_func)
+            glob[name] = new_func
+        except AttributeError:
+            pass
+    return module

Modified: martian/trunk/src/martian/tests/test_all.py
===================================================================
--- martian/trunk/src/martian/tests/test_all.py	2008-06-05 12:21:59 UTC (rev 87168)
+++ martian/trunk/src/martian/tests/test_all.py	2008-06-05 16:45:04 UTC (rev 87169)
@@ -1,52 +1,7 @@
 import unittest
 from zope.testing import doctest
-import new, types
+from martian.testing import FakeModule, fake_import
 
-class FakeModule(object):
-    pass
-
-def fake_import(fake_module):
-    module = new.module(fake_module.__name__)
-    glob = {}
-    for name in dir(fake_module):
-        if name.startswith('__') and '.' not in name:
-            continue
-        obj = getattr(fake_module, name)
-        glob[name] = obj
-        try:
-            obj = obj.im_func
-        except AttributeError:
-            pass
-        __module__ = None
-        try:
-            __module__ == obj.__dict__.get('__module__')
-        except AttributeError:
-            try:
-                __module__ = obj.__module__
-            except AttributeError:
-                pass
-        if __module__ is None or __module__ == '__builtin__':
-            try:
-                obj.__module__ = module.__name__
-            except AttributeError:
-                pass
-        setattr(module, name, obj)
-
-    # provide correct globals for functions
-    for name in dir(module):
-        if name.startswith('__'):
-            continue
-        obj = getattr(module, name)
-        try:
-            code = obj.func_code
-            new_func = new.function(code, glob, name)
-            new_func.__module__ = module.__name__
-            setattr(module, name, new_func)
-            glob[name] = new_func
-        except AttributeError:
-            pass
-    return module
-
 optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
 
 globs = dict(FakeModule=FakeModule, fake_import=fake_import)



More information about the Checkins mailing list