forked from VimPlug/jedi
Merge branch 'master' of github.com:davidhalter/jedi
This commit is contained in:
@@ -23,7 +23,7 @@ def inheritance_fixture():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def testdir(testdir):
|
||||
#? ['chdir']
|
||||
testdir.chdir
|
||||
return testdir
|
||||
def capsysbinary(capsysbinary):
|
||||
#? ['close']
|
||||
capsysbinary.clos
|
||||
return capsysbinary
|
||||
|
||||
@@ -5,6 +5,7 @@ import uuid
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models.query_utils import DeferredAttribute
|
||||
from django.db.models.manager import BaseManager
|
||||
|
||||
|
||||
class TagManager(models.Manager):
|
||||
|
||||
@@ -44,7 +44,7 @@ class Foo():
|
||||
baz: typing.ClassVar[str]
|
||||
|
||||
|
||||
#?
|
||||
#? int()
|
||||
Foo.bar
|
||||
#? int()
|
||||
Foo().bar
|
||||
@@ -58,6 +58,7 @@ class VarClass:
|
||||
var_instance2: float
|
||||
var_class1: typing.ClassVar[str] = 1
|
||||
var_class2: typing.ClassVar[bytes]
|
||||
var_class3 = None
|
||||
|
||||
def __init__(self):
|
||||
#? int()
|
||||
@@ -70,15 +71,21 @@ class VarClass:
|
||||
d.var_class2
|
||||
#? []
|
||||
d.int
|
||||
#? ['var_class1', 'var_class2', 'var_instance1', 'var_instance2']
|
||||
#? ['var_class1', 'var_class2', 'var_instance1', 'var_instance2', 'var_class3']
|
||||
self.var_
|
||||
|
||||
class VarClass2(VarClass):
|
||||
var_class3: typing.ClassVar[int]
|
||||
|
||||
#? ['var_class1', 'var_class2', 'var_instance1']
|
||||
def __init__(self):
|
||||
#? int()
|
||||
self.var_class3
|
||||
|
||||
#? ['var_class1', 'var_class2', 'var_instance1', 'var_class3', 'var_instance2']
|
||||
VarClass.var_
|
||||
#? int()
|
||||
VarClass.var_instance1
|
||||
#?
|
||||
#? float()
|
||||
VarClass.var_instance2
|
||||
#? str()
|
||||
VarClass.var_class1
|
||||
@@ -88,7 +95,7 @@ VarClass.var_class2
|
||||
VarClass.int
|
||||
|
||||
d = VarClass()
|
||||
#? ['var_class1', 'var_class2', 'var_instance1', 'var_instance2']
|
||||
#? ['var_class1', 'var_class2', 'var_class3', 'var_instance1', 'var_instance2']
|
||||
d.var_
|
||||
#? int()
|
||||
d.var_instance1
|
||||
|
||||
@@ -139,9 +139,6 @@ def test_p(monkeypatch):
|
||||
#? ['capsysbinary']
|
||||
def test_p(capsysbin
|
||||
|
||||
#? ['tmpdir', 'tmpdir_factory']
|
||||
def test_p(tmpdi
|
||||
|
||||
|
||||
def close_parens():
|
||||
pass
|
||||
@@ -183,3 +180,28 @@ def with_annot() -> Generator[float, None, None]:
|
||||
def test_with_annot(inheritance_fixture, with_annot):
|
||||
#? float()
|
||||
with_annot
|
||||
|
||||
# -----------------
|
||||
# pytest external plugins
|
||||
# -----------------
|
||||
|
||||
#? ['admin_user', 'admin_client']
|
||||
def test_z(admin
|
||||
|
||||
#! 15 ['def admin_client']
|
||||
def test_p(admin_client):
|
||||
#? ['login', 'logout']
|
||||
admin_client.log
|
||||
|
||||
@pytest.fixture
|
||||
@some_decorator
|
||||
#? ['admin_user']
|
||||
def bla(admin_u
|
||||
return
|
||||
|
||||
@pytest.fixture
|
||||
@some_decorator
|
||||
#! 12 ['def admin_user']
|
||||
def bla(admin_user):
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from pytest import fixture
|
||||
|
||||
|
||||
@fixture()
|
||||
def admin_user():
|
||||
pass
|
||||
16
test/examples/pytest_plugin_package/pytest_plugin/plugin.py
Normal file
16
test/examples/pytest_plugin_package/pytest_plugin/plugin.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
|
||||
from .fixtures import admin_user # noqa
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def admin_client():
|
||||
return Client()
|
||||
|
||||
|
||||
class Client:
|
||||
def login(self, **credentials):
|
||||
...
|
||||
|
||||
def logout(self):
|
||||
...
|
||||
@@ -209,7 +209,7 @@ class IntegrationTestCase(BaseTestCase):
|
||||
TEST_REFERENCES: self.run_get_references,
|
||||
}
|
||||
if (self.path.endswith('pytest.py') or self.path.endswith('conftest.py')) \
|
||||
and environment.executable != os.path.realpath(sys.executable):
|
||||
and os.path.realpath(environment.executable) != os.path.realpath(sys.executable):
|
||||
# It's not guarantueed that pytest is installed in test
|
||||
# environments, if we're not running in the same environment that
|
||||
# we're already in, so just skip that case.
|
||||
|
||||
@@ -650,6 +650,7 @@ def test_cursor_after_signature(Script, column):
|
||||
('abs(chr ( \nclass y: pass', 1, 8, 'abs', 0),
|
||||
('abs(chr ( \nclass y: pass', 1, 9, 'abs', 0),
|
||||
('abs(chr ( \nclass y: pass', 1, 10, 'chr', 0),
|
||||
('abs(foo.bar=3)', 1, 13, 'abs', 0),
|
||||
]
|
||||
)
|
||||
def test_base_signatures(Script, code, line, column, name, index):
|
||||
|
||||
@@ -739,3 +739,18 @@ def test_param_infer_default():
|
||||
param, = abs_sig.params
|
||||
assert param.name == 'x'
|
||||
assert param.infer_default() == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'code, expected', [
|
||||
("random.triangular(", ['high=', 'low=', 'mode=']),
|
||||
("random.triangular(low=1, ", ['high=', 'mode=']),
|
||||
("random.triangular(high=1, ", ['low=', 'mode=']),
|
||||
("random.triangular(low=1, high=2, ", ['mode=']),
|
||||
("random.triangular(low=1, mode=2, ", ['high=']),
|
||||
],
|
||||
)
|
||||
def test_keyword_param_completion(code, expected):
|
||||
import random
|
||||
completions = jedi.Interpreter(code, [locals()]).complete()
|
||||
assert expected == [c.name for c in completions if c.name.endswith('=')]
|
||||
|
||||
@@ -178,7 +178,7 @@ def test_is_potential_project(path, expected):
|
||||
|
||||
if expected is None:
|
||||
try:
|
||||
expected = _CONTAINS_POTENTIAL_PROJECT in os.listdir(path)
|
||||
expected = bool(set(_CONTAINS_POTENTIAL_PROJECT) & set(os.listdir(path)))
|
||||
except OSError:
|
||||
expected = False
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
from textwrap import dedent
|
||||
from pathlib import Path
|
||||
import platform
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -70,3 +71,23 @@ def test_diff_without_ending_newline(Script):
|
||||
-a
|
||||
+c
|
||||
''')
|
||||
|
||||
|
||||
def test_diff_path_outside_of_project(Script):
|
||||
if platform.system().lower() == 'windows':
|
||||
abs_path = r'D:\unknown_dir\file.py'
|
||||
else:
|
||||
abs_path = '/unknown_dir/file.py'
|
||||
script = Script(
|
||||
code='foo = 1',
|
||||
path=abs_path,
|
||||
project=jedi.get_default_project()
|
||||
)
|
||||
diff = script.rename(line=1, column=0, new_name='bar').get_diff()
|
||||
assert diff == dedent(f'''\
|
||||
--- {abs_path}
|
||||
+++ {abs_path}
|
||||
@@ -1 +1 @@
|
||||
-foo = 1
|
||||
+bar = 1
|
||||
''')
|
||||
|
||||
@@ -43,6 +43,9 @@ def test_implicit_namespace_package(Script):
|
||||
solution = "foo = '%s'" % solution
|
||||
assert completion.description == solution
|
||||
|
||||
c, = script_with_path('import pkg').complete()
|
||||
assert c.docstring() == ""
|
||||
|
||||
|
||||
def test_implicit_nested_namespace_package(Script):
|
||||
code = 'from implicit_nested_namespaces.namespace.pkg.module import CONST'
|
||||
|
||||
@@ -297,7 +297,6 @@ def test_os_issues(Script):
|
||||
# Github issue #759
|
||||
s = 'import os, s'
|
||||
assert 'sys' in import_names(s)
|
||||
assert 'path' not in import_names(s, column=len(s) - 1)
|
||||
assert 'os' in import_names(s, column=len(s) - 3)
|
||||
|
||||
# Some more checks
|
||||
|
||||
@@ -355,6 +355,48 @@ def test_dataclass_signature(Script, skip_pre_python37, start, start_params):
|
||||
price, = sig.params[-2].infer()
|
||||
assert price.name == 'float'
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'start, start_params', [
|
||||
['@define\nclass X:', []],
|
||||
['@frozen\nclass X:', []],
|
||||
['@define(eq=True)\nclass X:', []],
|
||||
[dedent('''
|
||||
class Y():
|
||||
y: int
|
||||
@define
|
||||
class X(Y):'''), []],
|
||||
[dedent('''
|
||||
@define
|
||||
class Y():
|
||||
y: int
|
||||
z = 5
|
||||
@define
|
||||
class X(Y):'''), ['y']],
|
||||
]
|
||||
)
|
||||
def test_attrs_signature(Script, skip_pre_python37, start, start_params):
|
||||
has_attrs = bool(Script('import attrs').infer())
|
||||
if not has_attrs:
|
||||
raise pytest.skip("attrs needed in target environment to run this test")
|
||||
|
||||
code = dedent('''
|
||||
name: str
|
||||
foo = 3
|
||||
price: float
|
||||
quantity: int = 0.0
|
||||
|
||||
X(''')
|
||||
|
||||
# attrs exposes two namespaces
|
||||
code = 'from attrs import define, frozen\n' + start + code
|
||||
|
||||
sig, = Script(code).get_signatures()
|
||||
assert [p.name for p in sig.params] == start_params + ['name', 'price', 'quantity']
|
||||
quantity, = sig.params[-1].infer()
|
||||
assert quantity.name == 'int'
|
||||
price, = sig.params[-2].infer()
|
||||
assert price.name == 'float'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'stmt, expected', [
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
from collections import namedtuple
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -42,6 +43,22 @@ def test_completion(case, monkeypatch, environment, has_django):
|
||||
|
||||
if (not has_django) and case.path.endswith('django.py'):
|
||||
pytest.skip('Needs django to be installed to run this test.')
|
||||
|
||||
if case.path.endswith("pytest.py"):
|
||||
# to test finding pytest fixtures from external plugins
|
||||
# add a stub pytest plugin to the project sys_path...
|
||||
pytest_plugin_dir = str(helpers.get_example_dir("pytest_plugin_package"))
|
||||
case._project.added_sys_path = [pytest_plugin_dir]
|
||||
|
||||
# ... and mock setuptools entry points to include it
|
||||
# see https://docs.pytest.org/en/stable/how-to/writing_plugins.html#setuptools-entry-points
|
||||
def mock_iter_entry_points(group):
|
||||
assert group == "pytest11"
|
||||
EntryPoint = namedtuple("EntryPoint", ["module_name"])
|
||||
return [EntryPoint("pytest_plugin.plugin")]
|
||||
|
||||
monkeypatch.setattr("pkg_resources.iter_entry_points", mock_iter_entry_points)
|
||||
|
||||
repo_root = helpers.root_dir
|
||||
monkeypatch.chdir(os.path.join(repo_root, 'jedi'))
|
||||
case.run(assert_case_equal, environment)
|
||||
|
||||
Reference in New Issue
Block a user