Debian Codegraph @

test/test_parso_integration/test_basic.py

raw symbols SCIP
1 from textwrap import dedent
2
3 from parso import parse
4
5
6 def test_form_feed_characters(Script):
7 s = "\f\nclass Test(object):\n pass"
8 Script(s).get_signatures(line=2, column=18)
9
10
11 def check_p(src):
12 module_node = parse(src)
13 assert src == module_node.get_code()
14 return module_node
15
16
17 def test_if(Script):
18 src = dedent('''\
19 def func():
20 x = 3
21 if x:
22 def y():
23 return x
24 return y()
25
26 func()
27 ''')
28
29 # Two parsers needed, one for pass and one for the function.
30 check_p(src)
31 assert [d.name for d in Script(src).infer(8, 6)] == ['int']
32
33
34 def test_class_and_if(Script):
35 src = dedent("""\
36 class V:
37 def __init__(self):
38 pass
39
40 if 1:
41 c = 3
42
43 def a_func():
44 return 1
45
46 # COMMENT
47 a_func()""")
48 check_p(src)
49 assert [d.name for d in Script(src).infer()] == ['int']
50
51
52 def test_add_to_end(Script):
53 """
54 The diff parser doesn't parse everything again. It just updates with the
55 help of caches, this is an example that didn't work.
56 """
57
58 a = dedent("""\
59 class Abc():
60 def abc(self):
61 self.x = 3
62
63 class Two(Abc):
64 def g(self):
65 self
66 """) # ^ here is the first completion
67
68 b = " def h(self):\n" \
69 " self."
70
71 def complete(code, line=None, column=None):
72 script = Script(code, path='example.py')
73 assert script.complete(line, column)
74
75 complete(a, 7, 12)
76 complete(a + b)
77
78 a = a[:-1] + '.\n'
79 complete(a, 7, 13)
80 complete(a + b)
81
82
83 def test_tokenizer_with_string_literal_backslash(Script):
84 c = Script("statement = u'foo\\\n'; statement").infer()
85 assert c[0]._name._value.get_safe_value() == 'foo'
86
87
88 def test_ellipsis_without_getitem(Script, environment):
89 results = Script('x=...;x').infer()
90 assert len(results) >= 1
91 # Sometimes this is inferred as both ellipsis and EllipsisType, which is
92 # probably a small bug, but we don't really need to fix this
93 for result in results:
94 assert result.name in ('ellipsis', 'EllipsisType')