Fix the use of deprecated inspect.getargspec() on Python 3
from __future__ import unicode_literals
+import functools
import inspect
import pytest
+import six
from pre_commit.languages.all import all_languages
from pre_commit.languages.all import languages
+if six.PY2: # pragma: no cover
+ ArgSpec = functools.partial(
+ inspect.ArgSpec, varargs=None, keywords=None, defaults=None,
+ )
+ getargspec = inspect.getargspec
+else:
+ ArgSpec = functools.partial(
+ inspect.FullArgSpec, varargs=None, varkw=None, defaults=None,
+ kwonlyargs=[], kwonlydefaults=None, annotations={},
+ )
+ getargspec = inspect.getfullargspec
+
+
@pytest.mark.parametrize('language', all_languages)
def test_install_environment_argspec(language):
- expected_argspec = inspect.ArgSpec(
+ expected_argspec = ArgSpec(
args=['prefix', 'version', 'additional_dependencies'],
- varargs=None, keywords=None, defaults=None,
)
- argspec = inspect.getargspec(languages[language].install_environment)
+ argspec = getargspec(languages[language].install_environment)
assert argspec == expected_argspec
@@ -25,28 +39,20 @@ def test_ENVIRONMENT_DIR(language):
@pytest.mark.parametrize('language', all_languages)
def test_run_hook_argpsec(language):
- expected_argspec = inspect.ArgSpec(
- args=['prefix', 'hook', 'file_args'],
- varargs=None, keywords=None, defaults=None,
- )
- argspec = inspect.getargspec(languages[language].run_hook)
+ expected_argspec = ArgSpec(args=['prefix', 'hook', 'file_args'])
+ argspec = getargspec(languages[language].run_hook)
assert argspec == expected_argspec
@pytest.mark.parametrize('language', all_languages)
def test_get_default_version_argspec(language):
- expected_argspec = inspect.ArgSpec(
- args=[], varargs=None, keywords=None, defaults=None,
- )
- argspec = inspect.getargspec(languages[language].get_default_version)
+ expected_argspec = ArgSpec(args=[])
+ argspec = getargspec(languages[language].get_default_version)
assert argspec == expected_argspec
@pytest.mark.parametrize('language', all_languages)
def test_healthy_argspec(language):
- expected_argspec = inspect.ArgSpec(
- args=['prefix', 'language_version'],
- varargs=None, keywords=None, defaults=None,
- )
- argspec = inspect.getargspec(languages[language].healthy)
+ expected_argspec = ArgSpec(args=['prefix', 'language_version'])
+ argspec = getargspec(languages[language].healthy)
assert argspec == expected_argspec
