mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
fix python 2.7 issues. the parser now only takes unicode inputs
This commit is contained in:
@@ -2,9 +2,10 @@ import difflib
|
||||
|
||||
import pytest
|
||||
|
||||
import jedi.parser as parser
|
||||
from jedi._compatibility import u
|
||||
from jedi.parser import Parser
|
||||
|
||||
code_basic_features = '''
|
||||
code_basic_features = u('''
|
||||
"""A mod docstring"""
|
||||
|
||||
def a_function(a_argument, a_default = "default"):
|
||||
@@ -21,7 +22,7 @@ to""" + "huhu"
|
||||
return str(a_result)
|
||||
else
|
||||
return None
|
||||
'''
|
||||
''')
|
||||
|
||||
|
||||
def diff_code_assert(a, b, n=4):
|
||||
@@ -43,7 +44,7 @@ def diff_code_assert(a, b, n=4):
|
||||
def test_basic_parsing():
|
||||
"""Validate the parsing features"""
|
||||
|
||||
prs = parser.Parser(code_basic_features)
|
||||
prs = Parser(code_basic_features)
|
||||
diff_code_assert(
|
||||
code_basic_features,
|
||||
prs.module.get_code2()
|
||||
@@ -52,6 +53,34 @@ def test_basic_parsing():
|
||||
|
||||
@pytest.mark.skipif('True', reason='Not yet working.')
|
||||
def test_operators():
|
||||
src = '5 * 3'
|
||||
prs = parser.Parser(src)
|
||||
src = u('5 * 3')
|
||||
prs = Parser(src)
|
||||
diff_code_assert(src, prs.module.get_code())
|
||||
|
||||
|
||||
def test_get_code():
|
||||
"""Use the same code that the parser also generates, to compare"""
|
||||
s = u('''"""a docstring"""
|
||||
class SomeClass(object, mixin):
|
||||
def __init__(self):
|
||||
self.xy = 3.0
|
||||
"""statement docstr"""
|
||||
def some_method(self):
|
||||
return 1
|
||||
def yield_method(self):
|
||||
while hasattr(self, 'xy'):
|
||||
yield True
|
||||
for x in [1, 2]:
|
||||
yield x
|
||||
def empty(self):
|
||||
pass
|
||||
class Empty:
|
||||
pass
|
||||
class WithDocstring:
|
||||
"""class docstr"""
|
||||
pass
|
||||
def method_with_docstring():
|
||||
"""class docstr"""
|
||||
pass
|
||||
''')
|
||||
assert Parser(s).module.get_code() == s
|
||||
|
||||
Reference in New Issue
Block a user