forked from VimPlug/jedi
parsing representation get_code tests
This commit is contained in:
@@ -423,6 +423,8 @@ class Class(Scope):
|
|||||||
string += ':\n'
|
string += ':\n'
|
||||||
string += super(Class, self).get_code(True, indention)
|
string += super(Class, self).get_code(True, indention)
|
||||||
if self.is_empty():
|
if self.is_empty():
|
||||||
|
if self.docstr:
|
||||||
|
string += indention
|
||||||
string += "pass\n"
|
string += "pass\n"
|
||||||
return string
|
return string
|
||||||
|
|
||||||
@@ -472,6 +474,8 @@ class Function(Scope):
|
|||||||
string += "def %s(%s):\n" % (self.name, params)
|
string += "def %s(%s):\n" % (self.name, params)
|
||||||
string += super(Function, self).get_code(True, indention)
|
string += super(Function, self).get_code(True, indention)
|
||||||
if self.is_empty():
|
if self.is_empty():
|
||||||
|
if self.docstr:
|
||||||
|
string += indention
|
||||||
string += 'pass\n'
|
string += 'pass\n'
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
|||||||
29
test/test_parsing_representation.py
Normal file
29
test/test_parsing_representation.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from jedi.parsing import Parser
|
||||||
|
|
||||||
|
def test_get_code():
|
||||||
|
"""Use the same code that the parser also generates, to compare"""
|
||||||
|
s = \
|
||||||
|
'''"""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