Skip to content

Commit

Permalink
Merge pull request #2006 from PeterJCLaw/lint-tests
Browse files Browse the repository at this point in the history
Enable linting of our test code, but not our test data files
  • Loading branch information
davidhalter authored Jun 30, 2024
2 parents 9bad42c + 0fcb446 commit b69d4d8
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Run tests
run: |
python -m flake8 jedi setup.py
python -m flake8 jedi test setup.py
python -m mypy jedi sith.py setup.py
coverage:
Expand Down
8 changes: 7 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ per-file-ignores =
jedi/__init__.py:F401
jedi/inference/compiled/__init__.py:F401
jedi/inference/value/__init__.py:F401
exclude = jedi/third_party/* .tox/*
exclude =
.tox/*
jedi/third_party/*
test/completion/*
test/examples/*
test/refactor/*
test/static_analysis/*

[pycodestyle]
max-line-length = 100
Expand Down
2 changes: 1 addition & 1 deletion test/test_api/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def func1(x, y):
def func2():
what ?
i = 3
def func3():
1'''
cls_code = '''\
Expand Down
29 changes: 14 additions & 15 deletions test/test_api/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_completion(source, namespace):


def test_builtin_details():
import keyword
import keyword # noqa: F401

class EmptyClass:
pass
Expand All @@ -53,9 +53,9 @@ def test_numpy_like_non_zero():
"""

class NumpyNonZero:

def __zero__(self):
raise ValueError('Numpy arrays would raise and tell you to use .any() or all()')

def __bool__(self):
raise ValueError('Numpy arrays would raise and tell you to use .any() or all()')

Expand Down Expand Up @@ -113,17 +113,17 @@ def _assert_interpreter_complete(source, namespace, completions, *, check_type=F


def test_complete_raw_function():
from os.path import join
from os.path import join # noqa: F401
_assert_interpreter_complete('join("").up', locals(), ['upper'])


def test_complete_raw_function_different_name():
from os.path import join as pjoin
from os.path import join as pjoin # noqa: F401
_assert_interpreter_complete('pjoin("").up', locals(), ['upper'])


def test_complete_raw_module():
import os
import os # noqa: F401
_assert_interpreter_complete('os.path.join("a").up', locals(), ['upper'])


Expand Down Expand Up @@ -281,7 +281,7 @@ def test_param_completion():
def foo(bar):
pass

lambd = lambda xyz: 3
lambd = lambda xyz: 3 # noqa: E731

_assert_interpreter_complete('foo(bar', locals(), ['bar='])
_assert_interpreter_complete('lambd(xyz', locals(), ['xyz='])
Expand All @@ -295,7 +295,7 @@ def test_endless_yield():


def test_completion_params():
foo = lambda a, b=3: None
foo = lambda a, b=3: None # noqa: E731

script = jedi.Interpreter('foo', [locals()])
c, = script.complete()
Expand Down Expand Up @@ -409,7 +409,7 @@ def __dir__(self):
def test_name_not_findable():
class X():
if 0:
NOT_FINDABLE
NOT_FINDABLE # noqa: F821

def hidden(self):
return
Expand All @@ -422,7 +422,7 @@ def hidden(self):


def test_stubs_working():
from multiprocessing import cpu_count
from multiprocessing import cpu_count # noqa: F401
defs = jedi.Interpreter("cpu_count()", [locals()]).infer()
assert [d.name for d in defs] == ['int']

Expand Down Expand Up @@ -532,7 +532,6 @@ def func(a, b, c):

def test_type_var():
"""This was an issue before, see Github #1369"""
import typing
x = typing.TypeVar('myvar')
def_, = jedi.Interpreter('x', [locals()]).infer()
assert def_.name == 'TypeVar'
Expand Down Expand Up @@ -610,7 +609,7 @@ def test_dict_getitem(code, types):
('next(DunderCls())', 'float'),
('next(dunder)', 'float'),
('for x in DunderCls(): x', 'str'),
#('for x in dunder: x', 'str'),
# ('for x in dunder: x', 'str'),
]
)
def test_dunders(class_is_findable, code, expected, allow_unsafe_getattr):
Expand Down Expand Up @@ -687,7 +686,7 @@ def bar():
]
)
def test_string_annotation(annotations, result, code):
x = lambda foo: 1
x = lambda foo: 1 # noqa: E731
x.__annotations__ = annotations
defs = jedi.Interpreter(code or 'x()', [locals()]).infer()
assert [d.name for d in defs] == result
Expand Down Expand Up @@ -720,8 +719,8 @@ def test_negate():

def test_complete_not_findable_class_source():
class TestClass():
ta=1
ta1=2
ta = 1
ta1 = 2

# Simulate the environment where the class is defined in
# an interactive session and therefore inspect module
Expand Down Expand Up @@ -756,7 +755,7 @@ def test_param_infer_default():
],
)
def test_keyword_param_completion(code, expected):
import random
import random # noqa: F401
completions = jedi.Interpreter(code, [locals()]).complete()
assert expected == [c.name for c in completions if c.name.endswith('=')]

Expand Down
12 changes: 8 additions & 4 deletions test/test_api/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,17 @@ def test_load_save_project(tmpdir):
]
)
def test_search(string, full_names, kwargs):
some_search_test_var = 1.0
some_search_test_var = 1.0 # noqa: F841
project = Project(test_dir)
if kwargs.pop('complete', False) is True:
defs = project.complete_search(string, **kwargs)
else:
defs = project.search(string, **kwargs)
assert sorted([('stub:' if d.is_stub() else '') + (d.full_name or d.name) for d in defs]) == full_names
actual = sorted([
('stub:' if d.is_stub() else '') + (d.full_name or d.name)
for d in defs
])
assert actual == full_names


@pytest.mark.parametrize(
Expand All @@ -169,8 +173,8 @@ def test_complete_search(Script, string, completions, all_scopes):

@pytest.mark.parametrize(
'path,expected', [
(Path(__file__).parents[2], True), # The path of the project
(Path(__file__).parents[1], False), # The path of the tests, not a project
(Path(__file__).parents[2], True), # The path of the project
(Path(__file__).parents[1], False), # The path of the tests, not a project
(Path.home(), None)
]
)
Expand Down
2 changes: 1 addition & 1 deletion test/test_api/test_refactoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_diff_without_ending_newline(Script):
b
-a
+c
''')
''') # noqa: W291


def test_diff_path_outside_of_project(Script):
Expand Down
2 changes: 1 addition & 1 deletion test/test_api/test_search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import sys
import sys # noqa: F401

import pytest

Expand Down
1 change: 1 addition & 0 deletions test/test_debug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import jedi
from jedi import debug


def test_simple():
jedi.set_debug_function()
debug.speed('foo')
Expand Down
7 changes: 5 additions & 2 deletions test/test_inference/test_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def foobar(x, y):
assert 'capitalize' in names
assert 'numerator' in names


@pytest.mark.skipif(numpydoc_unavailable,
reason='numpydoc module is unavailable')
def test_numpydoc_parameters_set_single_value():
Expand Down Expand Up @@ -390,7 +391,8 @@ def bazbiz():
@pytest.mark.skipif(numpydoc_unavailable or numpy_unavailable,
reason='numpydoc or numpy module is unavailable')
def test_numpy_returns():
s = dedent('''
s = dedent(
'''
import numpy
x = numpy.asarray([])
x.d'''
Expand All @@ -402,7 +404,8 @@ def test_numpy_returns():
@pytest.mark.skipif(numpydoc_unavailable or numpy_unavailable,
reason='numpydoc or numpy module is unavailable')
def test_numpy_comp_returns():
s = dedent('''
s = dedent(
'''
import numpy
x = numpy.array([])
x.d'''
Expand Down
4 changes: 3 additions & 1 deletion test/test_inference/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def test_get_signatures_stdlib(Script):

# Check only on linux 64 bit platform and Python3.8.
@pytest.mark.parametrize('load_unsafe_extensions', [False, True])
@pytest.mark.skipif('sys.platform != "linux" or sys.maxsize <= 2**32 or sys.version_info[:2] != (3, 8)')
@pytest.mark.skipif(
'sys.platform != "linux" or sys.maxsize <= 2**32 or sys.version_info[:2] != (3, 8)',
)
def test_init_extension_module(Script, load_unsafe_extensions):
"""
``__init__`` extension modules are also packages and Jedi should understand
Expand Down
4 changes: 2 additions & 2 deletions test/test_inference/test_gradual/test_typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_goto_stubs_on_itself(Script, code, type_):

def test_module_exists_only_as_stub(Script):
try:
import redis
import redis # noqa: F401
except ImportError:
pass
else:
Expand All @@ -234,7 +234,7 @@ def test_module_exists_only_as_stub(Script):

def test_django_exists_only_as_stub(Script):
try:
import django
import django # noqa: F401
except ImportError:
pass
else:
Expand Down
1 change: 0 additions & 1 deletion test/test_inference/test_literals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from jedi.inference.value import TreeInstance


Expand Down
4 changes: 2 additions & 2 deletions test/test_inference/test_sys_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def test_venv_and_pths(venv_path, environment):

ETALON = [
# For now disable egg-links. I have no idea how they work... ~ dave
#pjoin('/path', 'from', 'egg-link'),
#pjoin(site_pkg_path, '.', 'relative', 'egg-link', 'path'),
# pjoin('/path', 'from', 'egg-link'),
# pjoin(site_pkg_path, '.', 'relative', 'egg-link', 'path'),
site_pkg_path,
pjoin(site_pkg_path, 'dir-from-foo-pth'),
'/foo/smth.py:module',
Expand Down
1 change: 0 additions & 1 deletion test/test_parso_integration/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from textwrap import dedent

import pytest
from parso import parse


Expand Down

0 comments on commit b69d4d8

Please sign in to comment.