Skip to content

Commit 80d86f2

Browse files
Merge branch 'fix-pypy-tests'
2 parents 0f92c18 + 9bc21e5 commit 80d86f2

File tree

3 files changed

+69
-40
lines changed

3 files changed

+69
-40
lines changed

bpython/test/test_curtsies_painting.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ def test_run_line(self):
8989

9090
def test_completion(self):
9191
self.repl.height, self.repl.width = (5, 32)
92-
self.repl.current_line = 'se'
92+
self.repl.current_line = 'an'
9393
self.cursor_offset = 2
9494
if config.supports_box_chars():
95-
screen = ['>>> se',
95+
screen = ['>>> an',
9696
'┌───────────────────────┐',
97-
'│ set( setattr( │',
97+
'│ and any( │',
9898
'└───────────────────────┘',
9999
'Welcome to bpython! Press <F1> f']
100100
else:
101-
screen = ['>>> se',
101+
screen = ['>>> an',
102102
'+-----------------------+',
103-
'| set( setattr( |',
103+
'| and any( |',
104104
'+-----------------------+',
105105
'Welcome to bpython! Press <F1> f']
106106
self.assert_paint_ignoring_formatting(screen, (0, 4))
@@ -284,12 +284,14 @@ def test_rewind_inconsistent_history_more_lines_same_screen(self):
284284
self.repl.width = 60
285285
sys.a = 5
286286
self.enter('import sys')
287-
self.enter('for i in range(sys.a): print(sys.a)')
288-
self.enter()
287+
self.enter('for i in range(sys.a):')
288+
self.enter(' print(sys.a)')
289+
self.enter('')
289290
self.enter('1 + 1')
290291
self.enter('2 + 2')
291292
screen = ['>>> import sys',
292-
'>>> for i in range(sys.a): print(sys.a)',
293+
'>>> for i in range(sys.a):',
294+
'... print(sys.a)',
293295
'... ',
294296
'5',
295297
'5',
@@ -301,9 +303,9 @@ def test_rewind_inconsistent_history_more_lines_same_screen(self):
301303
'>>> 2 + 2',
302304
'4',
303305
'>>> ']
304-
self.assert_paint_ignoring_formatting(screen, (12, 4))
306+
self.assert_paint_ignoring_formatting(screen, (13, 4))
305307
self.repl.scroll_offset += len(screen) - self.repl.height
306-
self.assert_paint_ignoring_formatting(screen[8:], (4, 4))
308+
self.assert_paint_ignoring_formatting(screen[9:], (4, 4))
307309
sys.a = 6
308310
self.undo()
309311
screen = [INCONSISTENT_HISTORY_MSG[:self.repl.width],
@@ -322,12 +324,14 @@ def test_rewind_inconsistent_history_more_lines_lower_screen(self):
322324
self.repl.width = 60
323325
sys.a = 5
324326
self.enter("import sys")
325-
self.enter("for i in range(sys.a): print(sys.a)")
326-
self.enter()
327+
self.enter("for i in range(sys.a):")
328+
self.enter(" print(sys.a)")
329+
self.enter("")
327330
self.enter("1 + 1")
328331
self.enter("2 + 2")
329332
screen = [">>> import sys",
330-
">>> for i in range(sys.a): print(sys.a)",
333+
">>> for i in range(sys.a):",
334+
"... print(sys.a)",
331335
'... ',
332336
'5',
333337
'5',
@@ -339,9 +343,9 @@ def test_rewind_inconsistent_history_more_lines_lower_screen(self):
339343
'>>> 2 + 2',
340344
'4',
341345
'>>> ']
342-
self.assert_paint_ignoring_formatting(screen, (12, 4))
346+
self.assert_paint_ignoring_formatting(screen, (13, 4))
343347
self.repl.scroll_offset += len(screen) - self.repl.height
344-
self.assert_paint_ignoring_formatting(screen[8:], (4, 4))
348+
self.assert_paint_ignoring_formatting(screen[9:], (4, 4))
345349
sys.a = 8
346350
self.undo()
347351
screen = [INCONSISTENT_HISTORY_MSG[:self.repl.width],
@@ -359,12 +363,14 @@ def test_rewind_inconsistent_history_more_lines_raise_screen(self):
359363
self.repl.width = 60
360364
sys.a = 5
361365
self.enter("import sys")
362-
self.enter("for i in range(sys.a): print(sys.a)")
363-
self.enter()
366+
self.enter("for i in range(sys.a):")
367+
self.enter(" print(sys.a)")
368+
self.enter("")
364369
self.enter("1 + 1")
365370
self.enter("2 + 2")
366371
screen = [">>> import sys",
367-
">>> for i in range(sys.a): print(sys.a)",
372+
">>> for i in range(sys.a):",
373+
"... print(sys.a)",
368374
'... ',
369375
'5',
370376
'5',
@@ -376,9 +382,9 @@ def test_rewind_inconsistent_history_more_lines_raise_screen(self):
376382
'>>> 2 + 2',
377383
'4',
378384
'>>> ']
379-
self.assert_paint_ignoring_formatting(screen, (12, 4))
385+
self.assert_paint_ignoring_formatting(screen, (13, 4))
380386
self.repl.scroll_offset += len(screen) - self.repl.height
381-
self.assert_paint_ignoring_formatting(screen[8:], (4, 4))
387+
self.assert_paint_ignoring_formatting(screen[9:], (4, 4))
382388
sys.a = 1
383389
self.undo()
384390
screen = [INCONSISTENT_HISTORY_MSG[:self.repl.width],
@@ -394,12 +400,14 @@ def test_rewind_inconsistent_history_more_lines_raise_screen(self):
394400
def test_rewind_history_not_quite_inconsistent(self):
395401
self.repl.width = 50
396402
sys.a = 5
397-
self.enter("for i in range(__import__('sys').a): print(i)")
398-
self.enter()
403+
self.enter("for i in range(__import__('sys').a):")
404+
self.enter(" print(i)")
405+
self.enter("")
399406
self.enter("1 + 1")
400407
self.enter("2 + 2")
401-
screen = [">>> for i in range(__import__('sys').a): print(i)",
402-
'... ',
408+
screen = [">>> for i in range(__import__('sys').a):",
409+
"... print(i)",
410+
"... ",
403411
'0',
404412
'1',
405413
'2',
@@ -410,9 +418,9 @@ def test_rewind_history_not_quite_inconsistent(self):
410418
'>>> 2 + 2',
411419
'4',
412420
'>>> ']
413-
self.assert_paint_ignoring_formatting(screen, (11, 4))
421+
self.assert_paint_ignoring_formatting(screen, (12, 4))
414422
self.repl.scroll_offset += len(screen) - self.repl.height
415-
self.assert_paint_ignoring_formatting(screen[7:], (4, 4))
423+
self.assert_paint_ignoring_formatting(screen[8:], (4, 4))
416424
sys.a = 6
417425
self.undo()
418426
screen = ['5',

bpython/test/test_interpreter.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import unicode_literals
44

5+
import sys
6+
57
try:
68
import unittest2 as unittest
79
except ImportError:
@@ -13,6 +15,8 @@
1315
from bpython._py3compat import py3
1416
from bpython.test import mock
1517

18+
pypy = 'PyPy' in sys.version
19+
1620

1721
class TestInterpreter(unittest.TestCase):
1822
def test_syntaxerror(self):
@@ -25,11 +29,16 @@ def append_to_a(message):
2529
i.write = append_to_a
2630
i.runsource('1.1.1.1')
2731

28-
expected = ' File ' + green('"<input>"') + ', line ' + \
29-
bold(magenta('1')) + '\n 1.1.1.1\n ^\n' + \
30-
bold(red('SyntaxError')) + ': ' + cyan('invalid syntax') + '\n'
32+
if pypy:
33+
expected = ' File ' + green('"<input>"') + ', line ' + \
34+
bold(magenta('1')) + '\n 1.1.1.1\n ^\n' + \
35+
bold(red('SyntaxError')) + ': ' + cyan('invalid syntax') + '\n'
36+
else:
37+
expected = ' File ' + green('"<input>"') + ', line ' + \
38+
bold(magenta('1')) + '\n 1.1.1.1\n ^\n' + \
39+
bold(red('SyntaxError')) + ': ' + cyan('invalid syntax') + '\n'
3140

32-
self.assertEquals(str(plain('').join(a)), str(expected))
41+
self.assertMultiLineEqual(str(plain('').join(a)), str(expected))
3342
self.assertEquals(plain('').join(a), expected)
3443

3544
def test_traceback(self):
@@ -49,12 +58,17 @@ def g():
4958

5059
i.runsource('g()')
5160

61+
if pypy:
62+
global_not_found = "global name 'g' is not defined"
63+
else:
64+
global_not_found = "name 'g' is not defined"
65+
5266
expected = 'Traceback (most recent call last):\n File ' + \
5367
green('"<input>"') + ', line ' + bold(magenta('1')) + ', in ' + \
5468
cyan('<module>') + '\n' + bold(red('NameError')) + ': ' + \
55-
cyan("name 'g' is not defined") + '\n'
69+
cyan(global_not_found) + '\n'
5670

57-
self.assertEquals(str(plain('').join(a)), str(expected))
71+
self.assertMultiLineEqual(str(plain('').join(a)), str(expected))
5872
self.assertEquals(plain('').join(a), expected)
5973

6074
@unittest.skipIf(py3, "runsource() accepts only unicode in Python 3")

bpython/test/test_repl.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import collections
21
from itertools import islice
2+
import collections
3+
import inspect
34
import os
45
import shutil
56
import socket
67
import tempfile
78
from six.moves import range
9+
import sys
810

911
try:
1012
import unittest2 as unittest
@@ -15,6 +17,7 @@
1517
from bpython import config, repl, cli, autocomplete
1618
from bpython.test import MagicIterMock, mock, FixLanguageTestCase as TestCase
1719

20+
pypy = 'PyPy' in sys.version
1821

1922
def setup_config(conf):
2023
config_struct = config.Struct()
@@ -230,21 +233,25 @@ def assert_get_source_error_for_current_function(self, func, msg):
230233

231234
def test_current_function(self):
232235
self.set_input_line('INPUTLINE')
233-
self.repl.current_func = collections.MutableSet.add
234-
self.assertIn("Add an element.",
236+
self.repl.current_func = inspect.getsource
237+
self.assertIn("text of the source code",
235238
self.repl.get_source_of_current_name())
236239

237240
self.assert_get_source_error_for_current_function(
238-
collections.defaultdict.copy, "No source code found for INPUTLINE")
241+
[], "No source code found for INPUTLINE")
239242

240243
self.assert_get_source_error_for_current_function(
241-
collections.defaultdict, "could not find class definition")
244+
list.pop, "No source code found for INPUTLINE")
242245

246+
@unittest.skipIf(pypy, 'different errors for PyPy')
247+
def test_current_function_cpython(self):
248+
self.set_input_line('INPUTLINE')
243249
self.assert_get_source_error_for_current_function(
244-
[], "No source code found for INPUTLINE")
245-
250+
collections.defaultdict.copy, "No source code found for INPUTLINE")
246251
self.assert_get_source_error_for_current_function(
247-
list.pop, "No source code found for INPUTLINE")
252+
collections.defaultdict, "could not find class definition")
253+
254+
248255

249256
def test_current_line(self):
250257
self.repl.interp.locals['a'] = socket.socket

0 commit comments

Comments
 (0)