mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 10:37:52 +08:00
Progress in removing the docstring/call signature logic from the parser.
This commit is contained in:
@@ -5,6 +5,7 @@ from jedi.parser.python import load_grammar
|
||||
from jedi.evaluate import compiled, instance
|
||||
from jedi.evaluate.representation import FunctionContext
|
||||
from jedi.evaluate import Evaluator
|
||||
from jedi.parser_utils import clean_scope_docstring
|
||||
from jedi import Script
|
||||
|
||||
|
||||
@@ -33,7 +34,8 @@ def test_fake_loading():
|
||||
|
||||
|
||||
def test_fake_docstr():
|
||||
assert compiled.create(_evaluator(), next).tree_node.raw_doc == next.__doc__
|
||||
node = compiled.create(_evaluator(), next).tree_node
|
||||
assert clean_scope_docstring(node) == next.__doc__
|
||||
|
||||
|
||||
def test_parse_function_doc_illegal_docstr():
|
||||
|
||||
@@ -9,7 +9,8 @@ from jedi._compatibility import u, is_py3
|
||||
from jedi.parser.python import parse, load_grammar
|
||||
from jedi.parser.python import tree
|
||||
from jedi.common import splitlines
|
||||
from jedi.parser_utils import get_statement_of_position
|
||||
from jedi.parser_utils import get_statement_of_position, \
|
||||
clean_scope_docstring, safe_literal_eval
|
||||
|
||||
|
||||
def test_user_statement_on_import():
|
||||
@@ -38,7 +39,7 @@ class TestCallAndName():
|
||||
|
||||
leaf = self.get_call('1.0\n')
|
||||
assert leaf.value == '1.0'
|
||||
assert leaf.eval() == 1.0
|
||||
assert safe_literal_eval(leaf.value) == 1.0
|
||||
assert leaf.start_pos == (1, 0)
|
||||
assert leaf.end_pos == (1, 3)
|
||||
|
||||
@@ -49,15 +50,15 @@ class TestCallAndName():
|
||||
def test_literal_type(self):
|
||||
literal = self.get_call('1.0')
|
||||
assert isinstance(literal, tree.Literal)
|
||||
assert type(literal.eval()) == float
|
||||
assert type(safe_literal_eval(literal.value)) == float
|
||||
|
||||
literal = self.get_call('1')
|
||||
assert isinstance(literal, tree.Literal)
|
||||
assert type(literal.eval()) == int
|
||||
assert type(safe_literal_eval(literal.value)) == int
|
||||
|
||||
literal = self.get_call('"hello"')
|
||||
assert isinstance(literal, tree.Literal)
|
||||
assert literal.eval() == 'hello'
|
||||
assert safe_literal_eval(literal.value) == 'hello'
|
||||
|
||||
|
||||
class TestSubscopes():
|
||||
@@ -131,7 +132,7 @@ def test_hex_values_in_docstring():
|
||||
return 1
|
||||
'''
|
||||
|
||||
doc = parse(source).subscopes[0].raw_doc
|
||||
doc = clean_scope_docstring(parse(source).subscopes[0])
|
||||
if is_py3:
|
||||
assert doc == '\xff'
|
||||
else:
|
||||
|
||||
@@ -6,6 +6,7 @@ import pytest
|
||||
|
||||
from jedi.parser.python import parse
|
||||
from jedi.parser.python import tree
|
||||
from jedi.parser_utils import get_doc_with_call_signature, get_call_signature
|
||||
|
||||
|
||||
class TestsFunctionAndLambdaParsing(object):
|
||||
@@ -63,7 +64,7 @@ class TestsFunctionAndLambdaParsing(object):
|
||||
assert node.annotation.value == expected_annotation
|
||||
|
||||
def test_get_call_signature(self, node, expected):
|
||||
assert node.get_call_signature() == expected['call_sig']
|
||||
assert get_call_signature(node) == expected['call_sig']
|
||||
|
||||
def test_doc(self, node, expected):
|
||||
assert node.doc == expected.get('doc') or (expected['call_sig'] + '\n\n')
|
||||
assert get_doc_with_call_signature(node) == (expected['call_sig'] + '\n\n')
|
||||
|
||||
@@ -8,6 +8,7 @@ from jedi.parser import tokenize
|
||||
from jedi.parser.python import parse
|
||||
from jedi.common import splitlines
|
||||
from jedi.parser.tokenize import TokenInfo
|
||||
from jedi.parser_utils import safe_literal_eval
|
||||
|
||||
|
||||
from ..helpers import unittest
|
||||
@@ -141,7 +142,7 @@ class TokenTest(unittest.TestCase):
|
||||
string_tok = expr_stmt.children[2]
|
||||
assert string_tok.type == 'string'
|
||||
assert string_tok.value == s
|
||||
assert string_tok.eval() == 'test'
|
||||
assert safe_literal_eval(string_tok.value) == 'test'
|
||||
|
||||
|
||||
def test_tokenizer_with_string_literal_backslash():
|
||||
|
||||
Reference in New Issue
Block a user