Commits

Augie Fackler  committed 965a376

loader: use a compat function for detecting generators on python < 2.6

  • Participants
  • Parent commits fddde28

Comments (0)

Files changed (2)

File nose2/plugins/loader.py

 import inspect
 from unittest2.plugins import moduleloading as ml
-
+from nose2 import util
 
 def unpack(_self, generator):
     for index, func_args in enumerate(generator):
         return super(Functions, self).createTests(obj, testIndex)
 
     def isGenerator(self, obj):
-        return (inspect.isgeneratorfunction(obj) or
+        return (util.isgeneratorfunction(obj) or
                 super(Functions, self).isGenerator(obj))
 
 
     unpack = unpack
 
     def isGenerator(self, obj):
-        return (inspect.isgeneratorfunction(obj) or
+        return (util.isgeneratorfunction(obj) or
                 super(Generators, self).isGenerator(obj))
-
-

File nose2/util.py

+try:
+    from compiler.consts import CO_GENERATOR
+except ImportError:
+    # IronPython doesn't have a complier module
+    CO_GENERATOR=0x20
+
+try:
+    from inspect import isgeneratorfunction # new in 2.6
+except ImportError:
+    import inspect
+    # backported from Python 2.6
+    def isgeneratorfunction(func):
+        return bool((inspect.isfunction(func) or inspect.ismethod(func)) and
+                    func.func_code.co_flags & CO_GENERATOR)
+
 def ln(label, char='-', width=70):
     """Draw a divider, with label in the middle.