1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
from _pydevd_bundle.pydevd_code_to_source import code_obj_to_source
import pytest
# i.e.: Skip these tests (this is a work in progress / proof of concept / not ready to be used).
pytestmark = pytest.mark.skip
def check(obtained, expected, strip_return_none=True):
keepends = False
obtained_lines = list(obtained.rstrip().splitlines(keepends))
if strip_return_none:
obtained_lines = [x.replace('return None', '') for x in obtained_lines]
expected_lines = list(expected.rstrip().splitlines(keepends))
assert obtained_lines == expected_lines
def test_code_obj_to_source_make_class_and_func():
code = '''
class MyClass(object, other_class):
def my_func(self):
print(self)
'''
expected = '''
__module__=__name____qualname__=MyClassMyClass=(def MyClass():MyClass,object,other_class,)
def MyClass.my_func(self):
print(self)
'''
co = compile(code, '<unused>', 'exec')
contents = code_obj_to_source(co)
check(contents, expected)
def test_code_obj_to_source_lambda():
code = 'my_func = lambda arg: (2,)'
co = compile(code, '<unused>', 'exec')
contents = code_obj_to_source(co)
check(contents, 'my_func=<lambda>(arg):return return (2,)None')
def test_code_obj_to_source_make_func():
code = '''
def my_func(arg1, arg2=2, arg3=3):
some_call(arg1)
'''
co = compile(code, '<unused>', 'exec')
contents = code_obj_to_source(co)
check(contents, code)
def test_code_obj_to_source_call_func():
code = 'a=call1(call2(arg1))'
co = compile(code, '<unused>', 'exec')
contents = code_obj_to_source(co)
check(contents, code)
def test_for_list_comp():
code = '[x for x in range(10)]'
co = compile(code, '<unused>', 'exec')
contents = code_obj_to_source(co)
check(contents, code)
def test_code_obj_to_source_for():
code = 'for i in range(10):\n print(i)'
co = compile(code, '<unused>', 'exec')
contents = code_obj_to_source(co)
check(contents, code)
def test_code_obj_to_source_call_func2():
code = '''a=call1(
call2(
arg1))
'''
co = compile(code, '<unused>', 'exec')
contents = code_obj_to_source(co)
check(contents, code)
|