Augie Fackler avatar Augie Fackler committed 965a376

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

Comments (0)

Files changed (2)

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))
-
-
+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.
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.