mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-09 05:22:19 +08:00
Merge with master
The deprecation of Python2.6 and the insertion of environments made it quite difficult to merge.
This commit is contained in:
@@ -403,8 +403,6 @@ def test_func():
|
||||
x
|
||||
|
||||
|
||||
# python >= 2.7
|
||||
# Set literals are not valid in 2.6.
|
||||
#? int()
|
||||
tuple({1})[0]
|
||||
|
||||
|
||||
@@ -286,8 +286,6 @@ with open('') as f:
|
||||
#? str()
|
||||
line
|
||||
|
||||
# Nested with statements don't exist in Python 2.6.
|
||||
# python >= 2.7
|
||||
with open('') as f1, open('') as f2:
|
||||
#? ['closed']
|
||||
f1.closed
|
||||
|
||||
@@ -210,6 +210,5 @@ d[2]
|
||||
next(iter({a for a in range(10)}))
|
||||
|
||||
|
||||
# with a set literal (also doesn't work in 2.6).
|
||||
#? int()
|
||||
[a for a in {1, 2, 3}][0]
|
||||
|
||||
@@ -211,6 +211,17 @@ class X():
|
||||
#?
|
||||
self.x()
|
||||
|
||||
|
||||
def decorator_var_args(function, *args):
|
||||
return function(*args)
|
||||
|
||||
@decorator_var_args
|
||||
def function_var_args(param):
|
||||
return param
|
||||
|
||||
#? int()
|
||||
function_var_args(1)
|
||||
|
||||
# -----------------
|
||||
# method decorators
|
||||
# -----------------
|
||||
|
||||
@@ -288,8 +288,6 @@ third()[0]
|
||||
# -----------------
|
||||
# set.add
|
||||
# -----------------
|
||||
# Set literals are not valid in 2.6.
|
||||
# python >= 2.7
|
||||
st = {1.0}
|
||||
for a in [1,2]:
|
||||
st.add(a)
|
||||
|
||||
@@ -47,10 +47,6 @@ b
|
||||
class Employee:
|
||||
pass
|
||||
|
||||
# The typing library is not installable for Python 2.6, therefore ignore the
|
||||
# following tests.
|
||||
# python >= 2.7
|
||||
|
||||
from typing import List
|
||||
x = [] # type: List[Employee]
|
||||
#? Employee()
|
||||
|
||||
@@ -3,8 +3,6 @@ Test the typing library, with docstrings. This is needed since annotations
|
||||
are not supported in python 2.7 else then annotating by comment (and this is
|
||||
still TODO at 2016-01-23)
|
||||
"""
|
||||
# There's no Python 2.6 typing module.
|
||||
# python >= 2.7
|
||||
import typing
|
||||
class B:
|
||||
pass
|
||||
|
||||
@@ -116,8 +116,6 @@ tup4.index
|
||||
# -----------------
|
||||
# set
|
||||
# -----------------
|
||||
# Set literals are not valid in 2.6.
|
||||
# python >= 2.7
|
||||
set_t = {1,2}
|
||||
|
||||
#? ['clear', 'copy']
|
||||
|
||||
@@ -296,8 +296,6 @@ x = 32
|
||||
[x for x in something]
|
||||
|
||||
x = 3
|
||||
# Not supported syntax in Python 2.6.
|
||||
# python >= 2.7
|
||||
#< 1 (0,1), (0,10)
|
||||
{x:1 for x in something}
|
||||
#< 10 (0,1), (0,10)
|
||||
|
||||
@@ -41,9 +41,9 @@ def parse_test_files_option(opt):
|
||||
opt = str(opt)
|
||||
if ':' in opt:
|
||||
(f_name, rest) = opt.split(':', 1)
|
||||
return (f_name, list(map(int, rest.split(','))))
|
||||
return f_name, list(map(int, rest.split(',')))
|
||||
else:
|
||||
return (opt, [])
|
||||
return opt, []
|
||||
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
@@ -127,7 +127,7 @@ class StaticAnalysisCase(object):
|
||||
|
||||
@pytest.fixture()
|
||||
def cwd_tmpdir(monkeypatch, tmpdir):
|
||||
with helpers.set_cwd(tmpdir.dirpath):
|
||||
with helpers.set_cwd(tmpdir.strpath):
|
||||
yield tmpdir
|
||||
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ class IntegrationTestCase(object):
|
||||
completions = self.script(environment).completions()
|
||||
#import cProfile; cProfile.run('script.completions()')
|
||||
|
||||
comp_str = set([c.name for c in completions])
|
||||
comp_str = {c.name for c in completions}
|
||||
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
|
||||
|
||||
def run_goto_definitions(self, compare_cb, environment):
|
||||
|
||||
@@ -103,8 +103,8 @@ def test_completion_on_complex_literals(Script):
|
||||
_check_number(Script, '4.0j.', 'complex')
|
||||
# No dot no completion - I thought, but 4j is actually a literall after
|
||||
# which a keyword like or is allowed. Good times, haha!
|
||||
assert (set([c.name for c in Script('4j').completions()]) ==
|
||||
set(['if', 'and', 'in', 'is', 'not', 'or']))
|
||||
assert ({c.name for c in Script('4j').completions()} ==
|
||||
{'if', 'and', 'in', 'is', 'not', 'or'})
|
||||
|
||||
|
||||
def test_goto_assignments_on_non_name(Script, environment):
|
||||
@@ -152,7 +152,7 @@ def test_goto_definition_not_multiple(Script):
|
||||
|
||||
def test_usage_description(Script):
|
||||
descs = [u.description for u in Script("foo = ''; foo").usages()]
|
||||
assert set(descs) == set(["foo = ''", 'foo'])
|
||||
assert set(descs) == {"foo = ''", 'foo'}
|
||||
|
||||
|
||||
def test_get_line_code(Script):
|
||||
|
||||
@@ -34,7 +34,7 @@ def test_follow_import_incomplete(Script):
|
||||
|
||||
# incomplete `from * import` part
|
||||
datetime = check_follow_definition_types(Script, "from datetime import datetim")
|
||||
assert set(datetime) == set(['class', 'instance']) # py33: builtin and pure py version
|
||||
assert set(datetime) == {'class', 'instance'} # py33: builtin and pure py version
|
||||
|
||||
# os.path check
|
||||
ospath = check_follow_definition_types(Script, "from os.path import abspat")
|
||||
|
||||
@@ -68,25 +68,25 @@ def test_basedefinition_type(Script, environment):
|
||||
|
||||
def test_basedefinition_type_import(Script):
|
||||
def get_types(source, **kwargs):
|
||||
return set([t.type for t in Script(source, **kwargs).completions()])
|
||||
return {t.type for t in Script(source, **kwargs).completions()}
|
||||
|
||||
# import one level
|
||||
assert get_types('import t') == set(['module'])
|
||||
assert get_types('import ') == set(['module'])
|
||||
assert get_types('import datetime; datetime') == set(['module'])
|
||||
assert get_types('import t') == {'module'}
|
||||
assert get_types('import ') == {'module'}
|
||||
assert get_types('import datetime; datetime') == {'module'}
|
||||
|
||||
# from
|
||||
assert get_types('from datetime import timedelta') == set(['class'])
|
||||
assert get_types('from datetime import timedelta; timedelta') == set(['class'])
|
||||
assert get_types('from json import tool') == set(['module'])
|
||||
assert get_types('from json import tool; tool') == set(['module'])
|
||||
assert get_types('from datetime import timedelta') == {'class'}
|
||||
assert get_types('from datetime import timedelta; timedelta') == {'class'}
|
||||
assert get_types('from json import tool') == {'module'}
|
||||
assert get_types('from json import tool; tool') == {'module'}
|
||||
|
||||
# import two levels
|
||||
assert get_types('import json.tool; json') == set(['module'])
|
||||
assert get_types('import json.tool; json.tool') == set(['module'])
|
||||
assert get_types('import json.tool; json.tool.main') == set(['function'])
|
||||
assert get_types('import json.tool') == set(['module'])
|
||||
assert get_types('import json.tool', column=9) == set(['module'])
|
||||
assert get_types('import json.tool; json') == {'module'}
|
||||
assert get_types('import json.tool; json.tool') == {'module'}
|
||||
assert get_types('import json.tool; json.tool.main') == {'function'}
|
||||
assert get_types('import json.tool') == {'module'}
|
||||
assert get_types('import json.tool', column=9) == {'module'}
|
||||
|
||||
|
||||
def test_function_call_signature_in_doc(Script):
|
||||
|
||||
@@ -16,8 +16,8 @@ else:
|
||||
exec source in global_map """, 'blub', 'exec'))
|
||||
|
||||
|
||||
class _GlobalNameSpace():
|
||||
class SideEffectContainer():
|
||||
class _GlobalNameSpace:
|
||||
class SideEffectContainer:
|
||||
pass
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ def test_numpy_like_non_zero():
|
||||
|
||||
|
||||
def test_nested_resolve():
|
||||
class XX():
|
||||
class XX:
|
||||
def x():
|
||||
pass
|
||||
|
||||
@@ -168,7 +168,7 @@ def test_list():
|
||||
|
||||
|
||||
def test_slice():
|
||||
class Foo1():
|
||||
class Foo1:
|
||||
bar = []
|
||||
baz = 'xbarx'
|
||||
_assert_interpreter_complete('getattr(Foo1, baz[1:-1]).append',
|
||||
@@ -177,7 +177,7 @@ def test_slice():
|
||||
|
||||
|
||||
def test_getitem_side_effects():
|
||||
class Foo2():
|
||||
class Foo2:
|
||||
def __getitem__(self, index):
|
||||
# Possible side effects here, should therefore not call this.
|
||||
if True:
|
||||
@@ -190,7 +190,7 @@ def test_getitem_side_effects():
|
||||
|
||||
def test_property_error_oldstyle():
|
||||
lst = []
|
||||
class Foo3():
|
||||
class Foo3:
|
||||
@property
|
||||
def bar(self):
|
||||
lst.append(1)
|
||||
@@ -261,7 +261,7 @@ def test_completion_param_annotations():
|
||||
a, b, c = c.params
|
||||
assert a._goto_definitions() == []
|
||||
assert [d.name for d in b._goto_definitions()] == ['str']
|
||||
assert set([d.name for d in c._goto_definitions()]) == set(['int', 'float'])
|
||||
assert {d.name for d in c._goto_definitions()} == {'int', 'float'}
|
||||
|
||||
|
||||
def test_more_complex_instances():
|
||||
@@ -269,7 +269,7 @@ def test_more_complex_instances():
|
||||
def foo(self, other):
|
||||
return self
|
||||
|
||||
class Base():
|
||||
class Base:
|
||||
def wow(self):
|
||||
return Something()
|
||||
|
||||
|
||||
@@ -63,3 +63,12 @@ def test_complete_at_zero(Script):
|
||||
|
||||
s = Script("", 1, 0).completions()
|
||||
assert len(s) > 0
|
||||
|
||||
|
||||
def test_wrong_encoding(Script, cwd_tmpdir):
|
||||
x = cwd_tmpdir.join('x.py')
|
||||
# Use both latin-1 and utf-8 (a really broken file).
|
||||
x.write_binary(u'foobar = 1\nä'.encode('latin-1') + 'ä'.encode())
|
||||
|
||||
c, = Script('import x; x.foo', sys_path=['.']).completions()
|
||||
assert c.name == 'foobar'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
def test_module_attributes(Script):
|
||||
def_, = Script('__name__').completions()
|
||||
assert def_.name == '__name__'
|
||||
assert def_.line == None
|
||||
assert def_.column == None
|
||||
assert def_.line is None
|
||||
assert def_.column is None
|
||||
str_, = def_._goto_definitions()
|
||||
assert str_.name == 'str'
|
||||
|
||||
@@ -10,8 +10,6 @@ import pytest
|
||||
from jedi._compatibility import find_module_py33, find_module
|
||||
from ..helpers import cwd_at
|
||||
|
||||
from jedi._compatibility import is_py26
|
||||
|
||||
|
||||
@pytest.mark.skipif('sys.version_info < (3,3)')
|
||||
def test_find_module_py33():
|
||||
@@ -163,10 +161,9 @@ def test_complete_on_empty_import(Script):
|
||||
# relative import
|
||||
assert 10 < len(Script("from . import classes", 1, 6, 'whatever.py').completions()) < 30
|
||||
|
||||
wanted = set(['ImportError', 'import', 'ImportWarning'])
|
||||
assert set([c.name for c in Script("import").completions()]) == wanted
|
||||
if not is_py26: # python 2.6 doesn't always come with a library `import*`.
|
||||
assert len(Script("import import", path='').completions()) > 0
|
||||
wanted = {'ImportError', 'import', 'ImportWarning'}
|
||||
assert {c.name for c in Script("import").completions()} == wanted
|
||||
assert len(Script("import import", path='').completions()) > 0
|
||||
|
||||
# 111
|
||||
assert Script("from datetime import").completions()[0].name == 'import'
|
||||
|
||||
@@ -5,7 +5,6 @@ with "Black Box Tests".
|
||||
from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
from jedi._compatibility import is_py26
|
||||
|
||||
|
||||
# The namedtuple is different for different Python2.7 versions. Some versions
|
||||
@@ -28,10 +27,7 @@ def test_namedtuple_str(letter, expected, Script):
|
||||
dave.%s""") % letter
|
||||
result = Script(source).completions()
|
||||
completions = set(r.name for r in result)
|
||||
if is_py26:
|
||||
assert completions == set()
|
||||
else:
|
||||
assert completions == set(expected)
|
||||
assert completions == set(expected)
|
||||
|
||||
|
||||
def test_namedtuple_list(Script):
|
||||
@@ -42,10 +38,7 @@ def test_namedtuple_list(Script):
|
||||
garfield.l""")
|
||||
result = Script(source).completions()
|
||||
completions = set(r.name for r in result)
|
||||
if is_py26:
|
||||
assert completions == set()
|
||||
else:
|
||||
assert completions == set(['legs', 'length', 'large'])
|
||||
assert completions == {'legs', 'length', 'large'}
|
||||
|
||||
|
||||
def test_namedtuple_content(Script):
|
||||
|
||||
@@ -15,9 +15,9 @@ def test_paths_from_assignment(Script):
|
||||
expr_stmt = script._get_module_node().children[0]
|
||||
return set(sys_path._paths_from_assignment(script._get_module(), expr_stmt))
|
||||
|
||||
assert paths('sys.path[0:0] = ["a"]') == set(['/foo/a'])
|
||||
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == set(['/foo/b', '/foo/c'])
|
||||
assert paths('sys.path = a = ["a"]') == set(['/foo/a'])
|
||||
assert paths('sys.path[0:0] = ["a"]') == {'/foo/a'}
|
||||
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == {'/foo/b', '/foo/c'}
|
||||
assert paths('sys.path = a = ["a"]') == {'/foo/a'}
|
||||
|
||||
# Fail for complicated examples.
|
||||
assert paths('sys.path, other = ["a"], 2') == set()
|
||||
|
||||
@@ -7,7 +7,7 @@ from parso.python import tree
|
||||
import pytest
|
||||
|
||||
|
||||
class TestCallAndName():
|
||||
class TestCallAndName:
|
||||
def get_call(self, source):
|
||||
# Get the simple_stmt and then the first one.
|
||||
node = parse(source).children[0]
|
||||
|
||||
@@ -41,7 +41,6 @@ def test_scipy_speed(Script):
|
||||
s = 'import scipy.weave; scipy.weave.inline('
|
||||
script = Script(s, 1, len(s), '')
|
||||
script.call_signatures()
|
||||
#print(jedi.imports.imports_processed)
|
||||
|
||||
|
||||
@_check_speed(0.8)
|
||||
@@ -63,10 +62,11 @@ def test_no_repr_computation(Script):
|
||||
unwanted computation of repr(). Exemple : big pandas data.
|
||||
See issue #919.
|
||||
"""
|
||||
class SlowRepr():
|
||||
class SlowRepr:
|
||||
"class to test what happens if __repr__ is very slow."
|
||||
def some_method(self):
|
||||
pass
|
||||
|
||||
def __repr__(self):
|
||||
time.sleep(0.2)
|
||||
test = SlowRepr()
|
||||
|
||||
@@ -56,7 +56,7 @@ class TestSetupReadline(unittest.TestCase):
|
||||
string = 'os.path.join("a").upper'
|
||||
assert self.completions(string) == [string]
|
||||
|
||||
c = set(['os.' + d for d in dir(os) if d.startswith('ch')])
|
||||
c = {'os.' + d for d in dir(os) if d.startswith('ch')}
|
||||
assert set(self.completions('os.ch')) == set(c)
|
||||
finally:
|
||||
del self.namespace.sys
|
||||
@@ -68,12 +68,12 @@ class TestSetupReadline(unittest.TestCase):
|
||||
|
||||
def test_import(self):
|
||||
s = 'from os.path import a'
|
||||
assert set(self.completions(s)) == set([s + 'ltsep', s + 'bspath'])
|
||||
assert set(self.completions(s)) == {s + 'ltsep', s + 'bspath'}
|
||||
assert self.completions('import keyword') == ['import keyword']
|
||||
|
||||
import os
|
||||
s = 'from os import '
|
||||
goal = set([s + el for el in dir(os)])
|
||||
goal = {s + el for el in dir(os)}
|
||||
# There are minor differences, e.g. the dir doesn't include deleted
|
||||
# items as well as items that are not only available on linux.
|
||||
assert len(set(self.completions(s)).symmetric_difference(goal)) < 20
|
||||
@@ -85,7 +85,7 @@ class TestSetupReadline(unittest.TestCase):
|
||||
|
||||
def test_preexisting_values(self):
|
||||
self.namespace.a = range(10)
|
||||
assert set(self.completions('a.')) == set(['a.' + n for n in dir(range(1))])
|
||||
assert set(self.completions('a.')) == {'a.' + n for n in dir(range(1))}
|
||||
del self.namespace.a
|
||||
|
||||
def test_colorama(self):
|
||||
|
||||
Reference in New Issue
Block a user