@@ -129,8 +129,14 @@ def setUp(self):
129
129
self .repl .push ("def spam(a, b, c):\n " , False )
130
130
self .repl .push (" pass\n " , False )
131
131
self .repl .push ("\n " , False )
132
+ self .repl .push ("class Spam(object):\n " , False )
133
+ self .repl .push (" def spam(self, a, b, c):\n " , False )
134
+ self .repl .push (" pass\n " , False )
135
+ self .repl .push ("\n " , False )
136
+ self .repl .push ("o = Spam()\n " , False )
137
+ self .repl .push ("\n " , False )
132
138
133
- def setInputLine (self , line ):
139
+ def set_input_line (self , line ):
134
140
"""Set current input line of the test REPL."""
135
141
self .repl .current_line = line
136
142
self .repl .cursor_offset = len (line )
@@ -139,53 +145,62 @@ def test_func_name(self):
139
145
for (line , expected_name ) in [("spam(" , "spam" ),
140
146
("spam(map([]" , "map" ),
141
147
("spam((), " , "spam" )]:
142
- self .setInputLine (line )
148
+ self .set_input_line (line )
149
+ self .assertTrue (self .repl .get_args ())
150
+ self .assertEqual (self .repl .current_func .__name__ , expected_name )
151
+
152
+ def test_func_name_method_issue_479 (self ):
153
+ for (line , expected_name ) in [("o.spam(" , "spam" ),
154
+ ("o.spam(map([]" , "map" ),
155
+ ("o.spam((), " , "spam" )]:
156
+ self .set_input_line (line )
143
157
self .assertTrue (self .repl .get_args ())
144
158
self .assertEqual (self .repl .current_func .__name__ , expected_name )
145
159
160
+
146
161
def test_syntax_error_parens (self ):
147
162
for line in ["spam(]" , "spam([)" , "spam())" ]:
148
- self .setInputLine (line )
163
+ self .set_input_line (line )
149
164
# Should not explode
150
165
self .repl .get_args ()
151
166
152
167
def test_kw_arg_position (self ):
153
- self .setInputLine ("spam(a=0" )
168
+ self .set_input_line ("spam(a=0" )
154
169
self .assertTrue (self .repl .get_args ())
155
170
self .assertEqual (self .repl .argspec [3 ], "a" )
156
171
157
- self .setInputLine ("spam(1, b=1" )
172
+ self .set_input_line ("spam(1, b=1" )
158
173
self .assertTrue (self .repl .get_args ())
159
174
self .assertEqual (self .repl .argspec [3 ], "b" )
160
175
161
- self .setInputLine ("spam(1, c=2" )
176
+ self .set_input_line ("spam(1, c=2" )
162
177
self .assertTrue (self .repl .get_args ())
163
178
self .assertEqual (self .repl .argspec [3 ], "c" )
164
179
165
180
def test_lambda_position (self ):
166
- self .setInputLine ("spam(lambda a, b: 1, " )
181
+ self .set_input_line ("spam(lambda a, b: 1, " )
167
182
self .assertTrue (self .repl .get_args ())
168
183
self .assertTrue (self .repl .argspec )
169
184
# Argument position
170
185
self .assertEqual (self .repl .argspec [3 ], 1 )
171
186
172
187
def test_issue127 (self ):
173
- self .setInputLine ("x=range(" )
188
+ self .set_input_line ("x=range(" )
174
189
self .assertTrue (self .repl .get_args ())
175
190
self .assertEqual (self .repl .current_func .__name__ , "range" )
176
191
177
- self .setInputLine ("{x:range(" )
192
+ self .set_input_line ("{x:range(" )
178
193
self .assertTrue (self .repl .get_args ())
179
194
self .assertEqual (self .repl .current_func .__name__ , "range" )
180
195
181
- self .setInputLine ("foo(1, 2, x,range(" )
196
+ self .set_input_line ("foo(1, 2, x,range(" )
182
197
self .assertEqual (self .repl .current_func .__name__ , "range" )
183
198
184
- self .setInputLine ("(x,range(" )
199
+ self .set_input_line ("(x,range(" )
185
200
self .assertEqual (self .repl .current_func .__name__ , "range" )
186
201
187
202
def test_nonexistent_name (self ):
188
- self .setInputLine ("spamspamspam(" )
203
+ self .set_input_line ("spamspamspam(" )
189
204
self .assertFalse (self .repl .get_args ())
190
205
191
206
@@ -235,7 +250,7 @@ def test_current_line(self):
235
250
236
251
class TestRepl (unittest .TestCase ):
237
252
238
- def setInputLine (self , line ):
253
+ def set_input_line (self , line ):
239
254
"""Set current input line of the test REPL."""
240
255
self .repl .current_line = line
241
256
self .repl .cursor_offset = len (line )
@@ -244,12 +259,12 @@ def setUp(self):
244
259
self .repl = FakeRepl ()
245
260
246
261
def test_current_string (self ):
247
- self .setInputLine ('a = "2"' )
262
+ self .set_input_line ('a = "2"' )
248
263
# TODO factor cpos out of repl.Repl
249
264
self .repl .cpos = 0
250
265
self .assertEqual (self .repl .current_string (), '"2"' )
251
266
252
- self .setInputLine ('a = "2" + 2' )
267
+ self .set_input_line ('a = "2" + 2' )
253
268
self .assertEqual (self .repl .current_string (), '' )
254
269
255
270
def test_push (self ):
@@ -261,7 +276,7 @@ def test_push(self):
261
276
# 1. Global tests
262
277
def test_simple_global_complete (self ):
263
278
self .repl = FakeRepl ({'autocomplete_mode' : autocomplete .SIMPLE })
264
- self .setInputLine ("d" )
279
+ self .set_input_line ("d" )
265
280
266
281
self .assertTrue (self .repl .complete ())
267
282
self .assertTrue (hasattr (self .repl .matches_iter , 'matches' ))
@@ -272,7 +287,7 @@ def test_simple_global_complete(self):
272
287
@unittest .skip ("disabled while non-simple completion is disabled" )
273
288
def test_substring_global_complete (self ):
274
289
self .repl = FakeRepl ({'autocomplete_mode' : autocomplete .SUBSTRING })
275
- self .setInputLine ("time" )
290
+ self .set_input_line ("time" )
276
291
277
292
self .assertTrue (self .repl .complete ())
278
293
self .assertTrue (hasattr (self .repl .completer , 'matches' ))
@@ -282,7 +297,7 @@ def test_substring_global_complete(self):
282
297
@unittest .skip ("disabled while non-simple completion is disabled" )
283
298
def test_fuzzy_global_complete (self ):
284
299
self .repl = FakeRepl ({'autocomplete_mode' : autocomplete .FUZZY })
285
- self .setInputLine ("doc" )
300
+ self .set_input_line ("doc" )
286
301
287
302
self .assertTrue (self .repl .complete ())
288
303
self .assertTrue (hasattr (self .repl .completer , 'matches' ))
@@ -292,7 +307,7 @@ def test_fuzzy_global_complete(self):
292
307
# 2. Attribute tests
293
308
def test_simple_attribute_complete (self ):
294
309
self .repl = FakeRepl ({'autocomplete_mode' : autocomplete .SIMPLE })
295
- self .setInputLine ("Foo.b" )
310
+ self .set_input_line ("Foo.b" )
296
311
297
312
code = "class Foo():\n \t def bar(self):\n \t \t pass\n "
298
313
for line in code .split ("\n " ):
@@ -305,7 +320,7 @@ def test_simple_attribute_complete(self):
305
320
@unittest .skip ("disabled while non-simple completion is disabled" )
306
321
def test_substring_attribute_complete (self ):
307
322
self .repl = FakeRepl ({'autocomplete_mode' : autocomplete .SUBSTRING })
308
- self .setInputLine ("Foo.az" )
323
+ self .set_input_line ("Foo.az" )
309
324
310
325
code = "class Foo():\n \t def baz(self):\n \t \t pass\n "
311
326
for line in code .split ("\n " ):
@@ -318,7 +333,7 @@ def test_substring_attribute_complete(self):
318
333
@unittest .skip ("disabled while non-simple completion is disabled" )
319
334
def test_fuzzy_attribute_complete (self ):
320
335
self .repl = FakeRepl ({'autocomplete_mode' : autocomplete .FUZZY })
321
- self .setInputLine ("Foo.br" )
336
+ self .set_input_line ("Foo.br" )
322
337
323
338
code = "class Foo():\n \t def bar(self):\n \t \t pass\n "
324
339
for line in code .split ("\n " ):
@@ -331,7 +346,7 @@ def test_fuzzy_attribute_complete(self):
331
346
# 3. Edge Cases
332
347
def test_updating_namespace_complete (self ):
333
348
self .repl = FakeRepl ({'autocomplete_mode' : autocomplete .SIMPLE })
334
- self .setInputLine ("foo" )
349
+ self .set_input_line ("foo" )
335
350
self .repl .push ("foobar = 2" )
336
351
337
352
self .assertTrue (self .repl .complete ())
@@ -340,7 +355,7 @@ def test_updating_namespace_complete(self):
340
355
341
356
def test_file_should_not_appear_in_complete (self ):
342
357
self .repl = FakeRepl ({'autocomplete_mode' : autocomplete .SIMPLE })
343
- self .setInputLine ("_" )
358
+ self .set_input_line ("_" )
344
359
self .assertTrue (self .repl .complete ())
345
360
self .assertTrue (hasattr (self .repl .matches_iter , 'matches' ))
346
361
self .assertNotIn ('__file__' , self .repl .matches_iter .matches )
0 commit comments