Skip to content

Commit

Permalink
Merge pull request #1 from tacaswell/mnt_py36_compat
Browse files Browse the repository at this point in the history
Resolve python deprecation warnings
  • Loading branch information
timgates42 authored Jun 24, 2019
2 parents 7c26ad1 + b28f8ee commit cbbd474
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo: false
language: python
python:
- 2.6
Expand All @@ -7,8 +8,9 @@ python:
- 3.4
- 3.5
- pypy
- nightly
install:
- pip uninstall -y nose
- pip install -r requirements.txt --use-mirrors
- pip install -r requirements.txt
script:
- python setup.py build_tests || python setup.py egg_info; python selftest.py
16 changes: 14 additions & 2 deletions nose/plugins/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,19 @@ def addPlugin(self, plugin, call):
"""
meth = getattr(plugin, call, None)
if meth is not None:
if call == 'loadTestsFromModule' and \
len(inspect.getargspec(meth)[0]) == 2:
try:
sig = inspect.signature(meth)
bl = set([inspect.Parameter.VAR_KEYWORD,
inspect.Parameter.VAR_POSITIONAL,
inspect.Parameter.KEYWORD_ONLY])
args = [k for k, v in sig.parameters.items()
if v.kind not in bl]
arg_len = len(args)
if hasattr(meth, '__self__'):
arg_len += 1
except AttributeError:
arg_len = len(inspect.getargspec(meth)[0])
if call == 'loadTestsFromModule' and arg_len == 2:
orig_meth = meth
meth = lambda module, path, **kwargs: orig_meth(module)
self.plugins.append((plugin, meth))
Expand Down Expand Up @@ -153,6 +164,7 @@ def generate(self, *arg, **kw):
if result is not None:
for r in result:
yield r

except (KeyboardInterrupt, SystemExit):
raise
except:
Expand Down
29 changes: 24 additions & 5 deletions nose/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,35 @@ def try_run(obj, names):
if type(obj) == types.ModuleType:
# py.test compatibility
if isinstance(func, types.FunctionType):
args, varargs, varkw, defaults = \
inspect.getargspec(func)
try:
sig = inspect.signature(func)
bl = set([inspect.Parameter.VAR_KEYWORD,
inspect.Parameter.VAR_POSITIONAL,
inspect.Parameter.KEYWORD_ONLY])
args = [k for k, v in sig.parameters.items()
if v.kind not in bl]
except AttributeError:
args, varargs, varkw, defaults = \
inspect.getargspec(func)

else:
# Not a function. If it's callable, call it anyway
if hasattr(func, '__call__') and not inspect.ismethod(func):
func = func.__call__
try:
args, varargs, varkw, defaults = \
inspect.getargspec(func)
args.pop(0) # pop the self off
try:
sig = inspect.signature(func)
bl = set([inspect.Parameter.VAR_KEYWORD,
inspect.Parameter.VAR_POSITIONAL,
inspect.Parameter.KEYWORD_ONLY])
args = [k for k, v in sig.parameters.items()
if v.kind not in bl]

except AttributeError:
args, varargs, varkw, defaults = \
inspect.getargspec(func)
# signature never returns it
args.pop(0) # pop the self off
except TypeError:
raise TypeError("Attribute %s of %r is not a python "
"function. Only functions or callables"
Expand Down

0 comments on commit cbbd474

Please sign in to comment.