From 5c578e189980e0f0baf48a06503e5713e1b1a45d Mon Sep 17 00:00:00 2001 From: Peter Law Date: Sun, 30 Jun 2024 19:01:03 +0100 Subject: [PATCH 1/2] Enable linting of our test code, but not our test data files --- .github/workflows/ci.yml | 2 +- setup.cfg | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a565425dc..46355f701 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/setup.cfg b/setup.cfg index f792d5985..a3648aea6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 From 0fcb4468e724929b5914fc4050131a340c42f860 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Sun, 30 Jun 2024 19:03:55 +0100 Subject: [PATCH 2/2] Fix or ignore lints in tests --- test/test_api/test_context.py | 2 +- test/test_api/test_interpreter.py | 29 +++++++++---------- test/test_api/test_project.py | 12 +++++--- test/test_api/test_refactoring.py | 2 +- test/test_api/test_search.py | 2 +- test/test_debug.py | 1 + test/test_inference/test_docstring.py | 7 +++-- test/test_inference/test_extension.py | 4 ++- .../test_gradual/test_typeshed.py | 4 +-- test/test_inference/test_literals.py | 1 - test/test_inference/test_sys_path.py | 4 +-- test/test_parso_integration/test_basic.py | 1 - 12 files changed, 38 insertions(+), 31 deletions(-) diff --git a/test/test_api/test_context.py b/test/test_api/test_context.py index 6fabb2731..8849c6e9e 100644 --- a/test/test_api/test_context.py +++ b/test/test_api/test_context.py @@ -17,7 +17,7 @@ def func1(x, y): def func2(): what ? i = 3 - + def func3(): 1''' cls_code = '''\ diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index 74f066b86..c435db9c4 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -26,7 +26,7 @@ def get_completion(source, namespace): def test_builtin_details(): - import keyword + import keyword # noqa: F401 class EmptyClass: pass @@ -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()') @@ -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']) @@ -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=']) @@ -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() @@ -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 @@ -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'] @@ -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' @@ -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): @@ -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 @@ -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 @@ -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('=')] diff --git a/test/test_api/test_project.py b/test/test_api/test_project.py index 59b7018bb..ddf8d2c68 100644 --- a/test/test_api/test_project.py +++ b/test/test_api/test_project.py @@ -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( @@ -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) ] ) diff --git a/test/test_api/test_refactoring.py b/test/test_api/test_refactoring.py index 6f1b9b8a2..f7bc8c91b 100644 --- a/test/test_api/test_refactoring.py +++ b/test/test_api/test_refactoring.py @@ -113,7 +113,7 @@ def test_diff_without_ending_newline(Script): b -a +c - ''') + ''') # noqa: W291 def test_diff_path_outside_of_project(Script): diff --git a/test/test_api/test_search.py b/test/test_api/test_search.py index 20bb7286a..a91706796 100644 --- a/test/test_api/test_search.py +++ b/test/test_api/test_search.py @@ -1,5 +1,5 @@ import os -import sys +import sys # noqa: F401 import pytest diff --git a/test/test_debug.py b/test/test_debug.py index 00331072c..2a7ee64f7 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -1,6 +1,7 @@ import jedi from jedi import debug + def test_simple(): jedi.set_debug_function() debug.speed('foo') diff --git a/test/test_inference/test_docstring.py b/test/test_inference/test_docstring.py index 85e339337..7c4aad5fd 100644 --- a/test/test_inference/test_docstring.py +++ b/test/test_inference/test_docstring.py @@ -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(): @@ -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''' @@ -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''' diff --git a/test/test_inference/test_extension.py b/test/test_inference/test_extension.py index 85cd7c012..8c9015b54 100644 --- a/test/test_inference/test_extension.py +++ b/test/test_inference/test_extension.py @@ -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 diff --git a/test/test_inference/test_gradual/test_typeshed.py b/test/test_inference/test_gradual/test_typeshed.py index ac3f17274..6d0cdf748 100644 --- a/test/test_inference/test_gradual/test_typeshed.py +++ b/test/test_inference/test_gradual/test_typeshed.py @@ -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: @@ -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: diff --git a/test/test_inference/test_literals.py b/test/test_inference/test_literals.py index c70f7b564..c3b70b8d7 100644 --- a/test/test_inference/test_literals.py +++ b/test/test_inference/test_literals.py @@ -1,4 +1,3 @@ -import pytest from jedi.inference.value import TreeInstance diff --git a/test/test_inference/test_sys_path.py b/test/test_inference/test_sys_path.py index a725cd245..08dd4d095 100644 --- a/test/test_inference/test_sys_path.py +++ b/test/test_inference/test_sys_path.py @@ -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', diff --git a/test/test_parso_integration/test_basic.py b/test/test_parso_integration/test_basic.py index cf1743555..3356150f1 100644 --- a/test/test_parso_integration/test_basic.py +++ b/test/test_parso_integration/test_basic.py @@ -1,6 +1,5 @@ from textwrap import dedent -import pytest from parso import parse