mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-18 14:29:40 +08:00
Move some more tests.
This commit is contained in:
@@ -6,7 +6,6 @@ import pytest
|
|||||||
|
|
||||||
from jedi.parser.python import parse
|
from jedi.parser.python import parse
|
||||||
from jedi.parser.python import tree
|
from jedi.parser.python import tree
|
||||||
from jedi.parser_utils import get_doc_with_call_signature, get_call_signature
|
|
||||||
|
|
||||||
|
|
||||||
class TestsFunctionAndLambdaParsing(object):
|
class TestsFunctionAndLambdaParsing(object):
|
||||||
@@ -14,13 +13,11 @@ class TestsFunctionAndLambdaParsing(object):
|
|||||||
FIXTURES = [
|
FIXTURES = [
|
||||||
('def my_function(x, y, z) -> str:\n return x + y * z\n', {
|
('def my_function(x, y, z) -> str:\n return x + y * z\n', {
|
||||||
'name': 'my_function',
|
'name': 'my_function',
|
||||||
'call_sig': 'my_function(x, y, z)',
|
|
||||||
'params': ['x', 'y', 'z'],
|
'params': ['x', 'y', 'z'],
|
||||||
'annotation': "str",
|
'annotation': "str",
|
||||||
}),
|
}),
|
||||||
('lambda x, y, z: x + y * z\n', {
|
('lambda x, y, z: x + y * z\n', {
|
||||||
'name': '<lambda>',
|
'name': '<lambda>',
|
||||||
'call_sig': '<lambda>(x, y, z)',
|
|
||||||
'params': ['x', 'y', 'z'],
|
'params': ['x', 'y', 'z'],
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
@@ -62,9 +59,3 @@ class TestsFunctionAndLambdaParsing(object):
|
|||||||
assert node.annotation is None
|
assert node.annotation is None
|
||||||
else:
|
else:
|
||||||
assert node.annotation.value == expected_annotation
|
assert node.annotation.value == expected_annotation
|
||||||
|
|
||||||
def test_get_call_signature(self, node, expected):
|
|
||||||
assert get_call_signature(node) == expected['call_sig']
|
|
||||||
|
|
||||||
def test_doc(self, node, expected):
|
|
||||||
assert get_doc_with_call_signature(node) == (expected['call_sig'] + '\n\n')
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
from jedi._compatibility import u, is_py3
|
from jedi._compatibility import u, is_py3
|
||||||
from jedi.parser_utils import get_statement_of_position, \
|
from jedi import parser_utils
|
||||||
clean_scope_docstring, safe_literal_eval
|
|
||||||
from jedi.parser.python import parse
|
from jedi.parser.python import parse
|
||||||
from jedi.parser.python import tree
|
from jedi.parser.python import tree
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class TestCallAndName():
|
class TestCallAndName():
|
||||||
def get_call(self, source):
|
def get_call(self, source):
|
||||||
@@ -19,7 +20,7 @@ class TestCallAndName():
|
|||||||
|
|
||||||
leaf = self.get_call('1.0\n')
|
leaf = self.get_call('1.0\n')
|
||||||
assert leaf.value == '1.0'
|
assert leaf.value == '1.0'
|
||||||
assert safe_literal_eval(leaf.value) == 1.0
|
assert parser_utils.safe_literal_eval(leaf.value) == 1.0
|
||||||
assert leaf.start_pos == (1, 0)
|
assert leaf.start_pos == (1, 0)
|
||||||
assert leaf.end_pos == (1, 3)
|
assert leaf.end_pos == (1, 3)
|
||||||
|
|
||||||
@@ -30,15 +31,15 @@ class TestCallAndName():
|
|||||||
def test_literal_type(self):
|
def test_literal_type(self):
|
||||||
literal = self.get_call('1.0')
|
literal = self.get_call('1.0')
|
||||||
assert isinstance(literal, tree.Literal)
|
assert isinstance(literal, tree.Literal)
|
||||||
assert type(safe_literal_eval(literal.value)) == float
|
assert type(parser_utils.safe_literal_eval(literal.value)) == float
|
||||||
|
|
||||||
literal = self.get_call('1')
|
literal = self.get_call('1')
|
||||||
assert isinstance(literal, tree.Literal)
|
assert isinstance(literal, tree.Literal)
|
||||||
assert type(safe_literal_eval(literal.value)) == int
|
assert type(parser_utils.safe_literal_eval(literal.value)) == int
|
||||||
|
|
||||||
literal = self.get_call('"hello"')
|
literal = self.get_call('"hello"')
|
||||||
assert isinstance(literal, tree.Literal)
|
assert isinstance(literal, tree.Literal)
|
||||||
assert safe_literal_eval(literal.value) == 'hello'
|
assert parser_utils.safe_literal_eval(literal.value) == 'hello'
|
||||||
|
|
||||||
|
|
||||||
def test_user_statement_on_import():
|
def test_user_statement_on_import():
|
||||||
@@ -48,7 +49,7 @@ def test_user_statement_on_import():
|
|||||||
|
|
||||||
for pos in [(2, 1), (2, 4)]:
|
for pos in [(2, 1), (2, 4)]:
|
||||||
p = parse(s)
|
p = parse(s)
|
||||||
stmt = get_statement_of_position(p, pos)
|
stmt = parser_utils.get_statement_of_position(p, pos)
|
||||||
assert isinstance(stmt, tree.Import)
|
assert isinstance(stmt, tree.Import)
|
||||||
assert [n.value for n in stmt.get_defined_names()] == ['time']
|
assert [n.value for n in stmt.get_defined_names()] == ['time']
|
||||||
|
|
||||||
@@ -62,8 +63,22 @@ def test_hex_values_in_docstring():
|
|||||||
return 1
|
return 1
|
||||||
'''
|
'''
|
||||||
|
|
||||||
doc = clean_scope_docstring(next(parse(source).iter_funcdefs()))
|
doc = parser_utils.clean_scope_docstring(next(parse(source).iter_funcdefs()))
|
||||||
if is_py3:
|
if is_py3:
|
||||||
assert doc == '\xff'
|
assert doc == '\xff'
|
||||||
else:
|
else:
|
||||||
assert doc == u('�')
|
assert doc == u('�')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'code,call_signature', [
|
||||||
|
('def my_function(x, y, z) -> str:\n return', 'my_function(x, y, z)'),
|
||||||
|
('lambda x, y, z: x + y * z\n', '<lambda>(x, y, z)')
|
||||||
|
])
|
||||||
|
def test_get_call_signature(code, call_signature):
|
||||||
|
node = parse(code).children[0]
|
||||||
|
if node.type == 'simple_stmt':
|
||||||
|
node = node.children[0]
|
||||||
|
assert parser_utils.get_call_signature(node) == call_signature
|
||||||
|
|
||||||
|
assert parser_utils.get_doc_with_call_signature(node) == (call_signature + '\n\n')
|
||||||
|
|||||||
Reference in New Issue
Block a user