@@ -129,8 +129,14 @@ def setUp(self):
129129self .repl .push ("def spam(a, b, c):\n " ,False )
130130self .repl .push (" pass\n " ,False )
131131self .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 )
132138
133- def setInputLine (self ,line ):
139+ def set_input_line (self ,line ):
134140"""Set current input line of the test REPL."""
135141self .repl .current_line = line
136142self .repl .cursor_offset = len (line )
@@ -139,53 +145,62 @@ def test_func_name(self):
139145for (line ,expected_name )in [("spam(" ,"spam" ),
140146 ("spam(map([]" ,"map" ),
141147 ("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 )
143157self .assertTrue (self .repl .get_args ())
144158self .assertEqual (self .repl .current_func .__name__ ,expected_name )
145159
160+
146161def test_syntax_error_parens (self ):
147162for line in ["spam(]" ,"spam([)" ,"spam())" ]:
148- self .setInputLine (line )
163+ self .set_input_line (line )
149164# Should not explode
150165self .repl .get_args ()
151166
152167def test_kw_arg_position (self ):
153- self .setInputLine ("spam(a=0" )
168+ self .set_input_line ("spam(a=0" )
154169self .assertTrue (self .repl .get_args ())
155170self .assertEqual (self .repl .argspec [3 ],"a" )
156171
157- self .setInputLine ("spam(1, b=1" )
172+ self .set_input_line ("spam(1, b=1" )
158173self .assertTrue (self .repl .get_args ())
159174self .assertEqual (self .repl .argspec [3 ],"b" )
160175
161- self .setInputLine ("spam(1, c=2" )
176+ self .set_input_line ("spam(1, c=2" )
162177self .assertTrue (self .repl .get_args ())
163178self .assertEqual (self .repl .argspec [3 ],"c" )
164179
165180def test_lambda_position (self ):
166- self .setInputLine ("spam(lambda a, b: 1, " )
181+ self .set_input_line ("spam(lambda a, b: 1, " )
167182self .assertTrue (self .repl .get_args ())
168183self .assertTrue (self .repl .argspec )
169184# Argument position
170185self .assertEqual (self .repl .argspec [3 ],1 )
171186
172187def test_issue127 (self ):
173- self .setInputLine ("x=range(" )
188+ self .set_input_line ("x=range(" )
174189self .assertTrue (self .repl .get_args ())
175190self .assertEqual (self .repl .current_func .__name__ ,"range" )
176191
177- self .setInputLine ("{x:range(" )
192+ self .set_input_line ("{x:range(" )
178193self .assertTrue (self .repl .get_args ())
179194self .assertEqual (self .repl .current_func .__name__ ,"range" )
180195
181- self .setInputLine ("foo(1, 2, x,range(" )
196+ self .set_input_line ("foo(1, 2, x,range(" )
182197self .assertEqual (self .repl .current_func .__name__ ,"range" )
183198
184- self .setInputLine ("(x,range(" )
199+ self .set_input_line ("(x,range(" )
185200self .assertEqual (self .repl .current_func .__name__ ,"range" )
186201
187202def test_nonexistent_name (self ):
188- self .setInputLine ("spamspamspam(" )
203+ self .set_input_line ("spamspamspam(" )
189204self .assertFalse (self .repl .get_args ())
190205
191206
@@ -235,7 +250,7 @@ def test_current_line(self):
235250
236251class TestRepl (unittest .TestCase ):
237252
238- def setInputLine (self ,line ):
253+ def set_input_line (self ,line ):
239254"""Set current input line of the test REPL."""
240255self .repl .current_line = line
241256self .repl .cursor_offset = len (line )
@@ -244,12 +259,12 @@ def setUp(self):
244259self .repl = FakeRepl ()
245260
246261def test_current_string (self ):
247- self .setInputLine ('a = "2"' )
262+ self .set_input_line ('a = "2"' )
248263# TODO factor cpos out of repl.Repl
249264self .repl .cpos = 0
250265self .assertEqual (self .repl .current_string (),'"2"' )
251266
252- self .setInputLine ('a = "2" + 2' )
267+ self .set_input_line ('a = "2" + 2' )
253268self .assertEqual (self .repl .current_string (),'' )
254269
255270def test_push (self ):
@@ -261,7 +276,7 @@ def test_push(self):
261276# 1. Global tests
262277def test_simple_global_complete (self ):
263278self .repl = FakeRepl ({'autocomplete_mode' :autocomplete .SIMPLE })
264- self .setInputLine ("d" )
279+ self .set_input_line ("d" )
265280
266281self .assertTrue (self .repl .complete ())
267282self .assertTrue (hasattr (self .repl .matches_iter ,'matches' ))
@@ -272,7 +287,7 @@ def test_simple_global_complete(self):
272287@unittest .skip ("disabled while non-simple completion is disabled" )
273288def test_substring_global_complete (self ):
274289self .repl = FakeRepl ({'autocomplete_mode' :autocomplete .SUBSTRING })
275- self .setInputLine ("time" )
290+ self .set_input_line ("time" )
276291
277292self .assertTrue (self .repl .complete ())
278293self .assertTrue (hasattr (self .repl .completer ,'matches' ))
@@ -282,7 +297,7 @@ def test_substring_global_complete(self):
282297@unittest .skip ("disabled while non-simple completion is disabled" )
283298def test_fuzzy_global_complete (self ):
284299self .repl = FakeRepl ({'autocomplete_mode' :autocomplete .FUZZY })
285- self .setInputLine ("doc" )
300+ self .set_input_line ("doc" )
286301
287302self .assertTrue (self .repl .complete ())
288303self .assertTrue (hasattr (self .repl .completer ,'matches' ))
@@ -292,7 +307,7 @@ def test_fuzzy_global_complete(self):
292307# 2. Attribute tests
293308def test_simple_attribute_complete (self ):
294309self .repl = FakeRepl ({'autocomplete_mode' :autocomplete .SIMPLE })
295- self .setInputLine ("Foo.b" )
310+ self .set_input_line ("Foo.b" )
296311
297312code = "class Foo():\n \t def bar(self):\n \t \t pass\n "
298313for line in code .split ("\n " ):
@@ -305,7 +320,7 @@ def test_simple_attribute_complete(self):
305320@unittest .skip ("disabled while non-simple completion is disabled" )
306321def test_substring_attribute_complete (self ):
307322self .repl = FakeRepl ({'autocomplete_mode' :autocomplete .SUBSTRING })
308- self .setInputLine ("Foo.az" )
323+ self .set_input_line ("Foo.az" )
309324
310325code = "class Foo():\n \t def baz(self):\n \t \t pass\n "
311326for line in code .split ("\n " ):
@@ -318,7 +333,7 @@ def test_substring_attribute_complete(self):
318333@unittest .skip ("disabled while non-simple completion is disabled" )
319334def test_fuzzy_attribute_complete (self ):
320335self .repl = FakeRepl ({'autocomplete_mode' :autocomplete .FUZZY })
321- self .setInputLine ("Foo.br" )
336+ self .set_input_line ("Foo.br" )
322337
323338code = "class Foo():\n \t def bar(self):\n \t \t pass\n "
324339for line in code .split ("\n " ):
@@ -331,7 +346,7 @@ def test_fuzzy_attribute_complete(self):
331346# 3. Edge Cases
332347def test_updating_namespace_complete (self ):
333348self .repl = FakeRepl ({'autocomplete_mode' :autocomplete .SIMPLE })
334- self .setInputLine ("foo" )
349+ self .set_input_line ("foo" )
335350self .repl .push ("foobar = 2" )
336351
337352self .assertTrue (self .repl .complete ())
@@ -340,7 +355,7 @@ def test_updating_namespace_complete(self):
340355
341356def test_file_should_not_appear_in_complete (self ):
342357self .repl = FakeRepl ({'autocomplete_mode' :autocomplete .SIMPLE })
343- self .setInputLine ("_" )
358+ self .set_input_line ("_" )
344359self .assertTrue (self .repl .complete ())
345360self .assertTrue (hasattr (self .repl .matches_iter ,'matches' ))
346361self .assertNotIn ('__file__' ,self .repl .matches_iter .matches )