Commits

Jason Pellerin  committed 5e6499c

Cleaned up implementation a bit

  • Participants
  • Parent commits 52a09ca
  • Branches 145-imported-test-fixtures

Comments (0)

Files changed (3)

File nose/loader.py

 from nose.importer import Importer, add_path, remove_path
 from nose.selector import defaultSelector, TestAddress
 from nose.util import cmp_lineno, getpackage, isclass, isgenerator, ispackage, \
-    match_last, resolve_name
+    match_last, resolve_name, transplant_func, transplant_class
 from nose.suite import ContextSuiteFactory, ContextList, LazySuite
 
-# FIXME should be in util?
-from nose.tools import transplant, transplant_class
 
 log = logging.getLogger(__name__)
 #log.setLevel(logging.DEBUG)
                     return MethodTestCase(obj)
         elif isfunction(obj):
             if parent and obj.__module__ != parent.__name__:
-                obj = transplant(parent.__name__)(obj)
+                obj = transplant_func(obj, parent.__name__)
             if isgenerator(obj):
                 return self.loadTestsFromGenerator(obj, parent)
             else:

File nose/tools.py

     func.__test__ = False
     return func
 
-
-def transplant(module):
-    """
-    Make a function imported from module A appear as if it is located
-    in module B.
-
-    >>> from nose.util import resolve_name
-    >>> resolve_name.__module__
-    'nose.util'
-    >>> rn = transplant(__name__)(resolve_name)
-    >>> rn.__module__
-    'nose.tools'
-
-    The original function is not modified
-
-    >>> resolve_name.__module__
-    'nose.util'
-
-    Calling the transplanted function calls the original.
-
-    >>> rn('nose.tools') #doctest: +ELLIPSIS
-    <module 'nose.tools' ...>
-    >>> resolve_name('nose.tools') #doctest: +ELLIPSIS
-    <module 'nose.tools' ...>
-
-    """
-    def decorate(func):
-        def newfunc(*arg, **kw):
-            return func(*arg, **kw)
-        newfunc = make_decorator(func)(newfunc)
-        newfunc.__module__ = module
-        return newfunc
-    return decorate
-
-
-def transplant_class(cls, module):
-    """
-    Make a class appear to reside in `module`, rather than the module in which
-    it is actually defined.
-
-    >>> from nose.failure import Failure
-    >>> Failure.__module__
-    'nose.failure'
-    >>> Nf = transplant_class(Failure, __name__)
-    >>> Nf.__module__
-    'nose.tools'
-    >>> Nf.__name__
-    'Failure'
-    
-    """
-    class C(cls):
-        pass
-    C.__module__ = module
-    C.__name__ = cls.__name__
-    return C
-
 #
 # Expose assert* from unittest.TestCase
 # - give them pep8 style names

File nose/util.py

         return map(self.get, self._keys)
 
 
+def transplant_func(func, module):
+    """
+    Make a function imported from module A appear as if it is located
+    in module B.
+
+    >>> from pprint import pprint
+    >>> pprint.__module__
+    'pprint'
+    >>> pp = transplant_func(pprint, __name__)
+    >>> pp.__module__
+    'nose.util'
+
+    The original function is not modified
+
+    >>> pprint.__module__
+    'pprint'
+
+    Calling the transplanted function calls the original.
+
+    >>> pp([1, 2])
+    [1, 2]
+    >>> pprint([1,2])
+    [1, 2]
+
+    """
+    from nose.tools import make_decorator
+    def newfunc(*arg, **kw):
+        return func(*arg, **kw)
+    
+    newfunc = make_decorator(func)(newfunc)
+    newfunc.__module__ = module
+    return newfunc
+
+
+def transplant_class(cls, module):
+    """
+    Make a class appear to reside in `module`, rather than the module in which
+    it is actually defined.
+
+    >>> from nose.failure import Failure
+    >>> Failure.__module__
+    'nose.failure'
+    >>> Nf = transplant_class(Failure, __name__)
+    >>> Nf.__module__
+    'nose.util'
+    >>> Nf.__name__
+    'Failure'
+    
+    """
+    class C(cls):
+        pass
+    C.__module__ = module
+    C.__name__ = cls.__name__
+    return C
+
 
 if __name__ == '__main__':
     import doctest