Skip to content

Commit 0748500

Browse files
committed
Failing test for bpython#479
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent aaaf99b commit 0748500

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

bpython/test/test_repl.py

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ def setUp(self):
129129
self.repl.push("def spam(a, b, c):\n", False)
130130
self.repl.push(" pass\n", False)
131131
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)
132138

133-
def setInputLine(self, line):
139+
def set_input_line(self, line):
134140
"""Set current input line of the test REPL."""
135141
self.repl.current_line = line
136142
self.repl.cursor_offset = len(line)
@@ -139,53 +145,62 @@ def test_func_name(self):
139145
for (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)
143157
self.assertTrue(self.repl.get_args())
144158
self.assertEqual(self.repl.current_func.__name__, expected_name)
145159

160+
146161
def test_syntax_error_parens(self):
147162
for line in ["spam(]", "spam([)", "spam())"]:
148-
self.setInputLine(line)
163+
self.set_input_line(line)
149164
# Should not explode
150165
self.repl.get_args()
151166

152167
def test_kw_arg_position(self):
153-
self.setInputLine("spam(a=0")
168+
self.set_input_line("spam(a=0")
154169
self.assertTrue(self.repl.get_args())
155170
self.assertEqual(self.repl.argspec[3], "a")
156171

157-
self.setInputLine("spam(1, b=1")
172+
self.set_input_line("spam(1, b=1")
158173
self.assertTrue(self.repl.get_args())
159174
self.assertEqual(self.repl.argspec[3], "b")
160175

161-
self.setInputLine("spam(1, c=2")
176+
self.set_input_line("spam(1, c=2")
162177
self.assertTrue(self.repl.get_args())
163178
self.assertEqual(self.repl.argspec[3], "c")
164179

165180
def test_lambda_position(self):
166-
self.setInputLine("spam(lambda a, b: 1, ")
181+
self.set_input_line("spam(lambda a, b: 1, ")
167182
self.assertTrue(self.repl.get_args())
168183
self.assertTrue(self.repl.argspec)
169184
# Argument position
170185
self.assertEqual(self.repl.argspec[3], 1)
171186

172187
def test_issue127(self):
173-
self.setInputLine("x=range(")
188+
self.set_input_line("x=range(")
174189
self.assertTrue(self.repl.get_args())
175190
self.assertEqual(self.repl.current_func.__name__, "range")
176191

177-
self.setInputLine("{x:range(")
192+
self.set_input_line("{x:range(")
178193
self.assertTrue(self.repl.get_args())
179194
self.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(")
182197
self.assertEqual(self.repl.current_func.__name__, "range")
183198

184-
self.setInputLine("(x,range(")
199+
self.set_input_line("(x,range(")
185200
self.assertEqual(self.repl.current_func.__name__, "range")
186201

187202
def test_nonexistent_name(self):
188-
self.setInputLine("spamspamspam(")
203+
self.set_input_line("spamspamspam(")
189204
self.assertFalse(self.repl.get_args())
190205

191206

@@ -235,7 +250,7 @@ def test_current_line(self):
235250

236251
class 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."""
240255
self.repl.current_line = line
241256
self.repl.cursor_offset = len(line)
@@ -244,12 +259,12 @@ def setUp(self):
244259
self.repl = FakeRepl()
245260

246261
def test_current_string(self):
247-
self.setInputLine('a = "2"')
262+
self.set_input_line('a = "2"')
248263
# TODO factor cpos out of repl.Repl
249264
self.repl.cpos = 0
250265
self.assertEqual(self.repl.current_string(), '"2"')
251266

252-
self.setInputLine('a = "2" + 2')
267+
self.set_input_line('a = "2" + 2')
253268
self.assertEqual(self.repl.current_string(), '')
254269

255270
def test_push(self):
@@ -261,7 +276,7 @@ def test_push(self):
261276
# 1. Global tests
262277
def test_simple_global_complete(self):
263278
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SIMPLE})
264-
self.setInputLine("d")
279+
self.set_input_line("d")
265280

266281
self.assertTrue(self.repl.complete())
267282
self.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")
273288
def test_substring_global_complete(self):
274289
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SUBSTRING})
275-
self.setInputLine("time")
290+
self.set_input_line("time")
276291

277292
self.assertTrue(self.repl.complete())
278293
self.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")
283298
def test_fuzzy_global_complete(self):
284299
self.repl = FakeRepl({'autocomplete_mode': autocomplete.FUZZY})
285-
self.setInputLine("doc")
300+
self.set_input_line("doc")
286301

287302
self.assertTrue(self.repl.complete())
288303
self.assertTrue(hasattr(self.repl.completer, 'matches'))
@@ -292,7 +307,7 @@ def test_fuzzy_global_complete(self):
292307
# 2. Attribute tests
293308
def test_simple_attribute_complete(self):
294309
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SIMPLE})
295-
self.setInputLine("Foo.b")
310+
self.set_input_line("Foo.b")
296311

297312
code = "class Foo():\n\tdef bar(self):\n\t\tpass\n"
298313
for 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")
306321
def test_substring_attribute_complete(self):
307322
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SUBSTRING})
308-
self.setInputLine("Foo.az")
323+
self.set_input_line("Foo.az")
309324

310325
code = "class Foo():\n\tdef baz(self):\n\t\tpass\n"
311326
for 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")
319334
def test_fuzzy_attribute_complete(self):
320335
self.repl = FakeRepl({'autocomplete_mode': autocomplete.FUZZY})
321-
self.setInputLine("Foo.br")
336+
self.set_input_line("Foo.br")
322337

323338
code = "class Foo():\n\tdef bar(self):\n\t\tpass\n"
324339
for line in code.split("\n"):
@@ -331,7 +346,7 @@ def test_fuzzy_attribute_complete(self):
331346
# 3. Edge Cases
332347
def test_updating_namespace_complete(self):
333348
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SIMPLE})
334-
self.setInputLine("foo")
349+
self.set_input_line("foo")
335350
self.repl.push("foobar = 2")
336351

337352
self.assertTrue(self.repl.complete())
@@ -340,7 +355,7 @@ def test_updating_namespace_complete(self):
340355

341356
def test_file_should_not_appear_in_complete(self):
342357
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SIMPLE})
343-
self.setInputLine("_")
358+
self.set_input_line("_")
344359
self.assertTrue(self.repl.complete())
345360
self.assertTrue(hasattr(self.repl.matches_iter, 'matches'))
346361
self.assertNotIn('__file__', self.repl.matches_iter.matches)

0 commit comments

Comments
 (0)