Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9bc21e5

Browse files
specialize source finding error messages
1 parent4408f9d commit9bc21e5

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

‎bpython/test/test_interpreter.py‎

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

33
from __future__importunicode_literals
44

5+
importsys
6+
57
try:
68
importunittest2asunittest
79
exceptImportError:
@@ -13,6 +15,8 @@
1315
frombpython._py3compatimportpy3
1416
frombpython.testimportmock
1517

18+
pypy='PyPy'insys.version
19+
1620

1721
classTestInterpreter(unittest.TestCase):
1822
deftest_syntaxerror(self):
@@ -25,9 +29,14 @@ 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+
ifpypy:
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

3241
self.assertMultiLineEqual(str(plain('').join(a)),str(expected))
3342
self.assertEquals(plain('').join(a),expected)
@@ -49,10 +58,15 @@ def g():
4958

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

61+
ifpypy:
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

5771
self.assertMultiLineEqual(str(plain('').join(a)),str(expected))
5872
self.assertEquals(plain('').join(a),expected)

‎bpython/test/test_repl.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
importcollections
21
fromitertoolsimportislice
2+
importcollections
3+
importinspect
34
importos
45
importshutil
56
importsocket
67
importtempfile
78
fromsix.movesimportrange
9+
importsys
810

911
try:
1012
importunittest2asunittest
@@ -15,6 +17,7 @@
1517
frombpythonimportconfig,repl,cli,autocomplete
1618
frombpython.testimportMagicIterMock,mock,FixLanguageTestCaseasTestCase
1719

20+
pypy='PyPy'insys.version
1821

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

231234
deftest_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+
deftest_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
deftest_current_line(self):
250257
self.repl.interp.locals['a']=socket.socket

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp