Skip to content

Commit

Permalink
Pypy 2.x tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Aug 13, 2017
1 parent 963f4a0 commit 4fef1b9
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 65 deletions.
14 changes: 14 additions & 0 deletions test/data/highlight-pypy.right
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(gcd.py:2): <module>
-> 2 """Greatest Common Divisor
Set basename (short filenames) in debugger output is on.
Set event tracing is on.
Set stopping before def or class statements is off.
output set to not use terminal escape sequences
output set to not use terminal escape sequences
output set to not use terminal escape sequences
output set to not use terminal escape sequences
output set to not use terminal escape sequences
output set for terminal with escape sequences for a dark background
output set for terminal with escape sequences for a light background
output set for terminal with escape sequences for a light background
trepan2: That's all, folks...
39 changes: 39 additions & 0 deletions test/data/macro-pypy.right
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(gcd.py:2): <module>
-> 2 """Greatest Common Divisor
Set basename (short filenames) in debugger output is on.
Set event tracing is on.
Set stopping before def or class statements is off.
No macros defined.
Macro "foo" defined.
1 #!/usr/bin/python
2 -> """Greatest Common Divisor
3
4 Some characterstics of this program used for testing check_args() does
5 not have a 'return' statement.
6
7 check_args() raises an uncaught exception when given the wrong number
8 of parameters.
9
10 """
foo

Macro "bar" defined.
1 #!/usr/bin/python
2 -> """Greatest Common Divisor
3
4 Some characterstics of this program used for testing check_args() does
5 not have a 'return' statement.
6
7 check_args() raises an uncaught exception when given the wrong number
8 of parameters.
9
10 """
bar foo

bar:
----
lambda count: 'list %s' % count
foo:
----
lambda: 'list'
trepan2: That's all, folks...
24 changes: 24 additions & 0 deletions test/data/step-pypy.right
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(gcd.py:2): <module>
-> 2 """Greatest Common Divisor
Set basename (short filenames) in debugger output is on.
Set event tracing is on.
Set stopping before def or class statements is off.
Set confirmation of potentially dangerous operations is off.
line - gcd.py:2
line - gcd.py:11
(gcd.py:11): <module>
-- 11 import sys
11 -> import sys
Set stopping before def or class statements is on.
line - gcd.py:13
line - gcd.py:26
line - gcd.py:40
(gcd.py:40): <module>
-- 40 if __name__=='__main__':
40 -> if __name__=='__main__':
Set stopping before def or class statements is off.
line - gcd.py:41
(gcd.py:41): <module>
-- 41 check_args()
41 -> check_args()
trepan2: That's all, folks...
6 changes: 5 additions & 1 deletion test/integration/helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import difflib, os, re, sys, time
from xdis import IS_PYPY

srcdir = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -11,7 +12,10 @@ def run_debugger(testname, python_file, dbgr_opts='', args='',
dbgr_short= "cli.py"
dbgr_path = os.path.join(dbgrdir, dbgr_short)

rightfile = os.path.join(datadir, "%s.right" % testname)
if IS_PYPY:
rightfile = os.path.join(datadir, "%s-pypy.right" % testname)
else:
rightfile = os.path.join(datadir, "%s.right" % testname)

sys.path.insert(0, os.path.join(srcdir, '..', '..'))
os.environ['PYTHONPATH'] = os.pathsep.join(sys.path)
Expand Down
6 changes: 5 additions & 1 deletion test/unit/test-bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import inspect, unittest

from trepan.lib import bytecode as Mcode
from xdis import IS_PYPY


class TestByteCode(unittest.TestCase):
Expand All @@ -21,7 +22,10 @@ def sqr(x):

def test_op_at_frame(self):
frame = inspect.currentframe()
self.assertEqual('CALL_FUNCTION', Mcode.op_at_frame(frame))
if IS_PYPY:
self.assertEqual('CALL_METHOD', Mcode.op_at_frame(frame))
else:
self.assertEqual('CALL_FUNCTION', Mcode.op_at_frame(frame))
return

def test_is_def_frame(self):
Expand Down
126 changes: 64 additions & 62 deletions test/unit/test-completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import unittest
import inspect
from xdis import IS_PYPY

from trepan import debugger as Mdebugger

Expand Down Expand Up @@ -44,68 +45,69 @@ def test_complete_identifier(self):
['mBaseCmd', 'mComplete'])
return

def test_completion(self):

self.dbgr = Mdebugger.Debugger()

for line, expect_completion in [
['set basename', ['basename ']],
['set basename ', ['off', 'on']],
['where', ['where ']], # Single alias completion
['sho', ['show']], # Simple single completion
['un', ['unalias', 'undisplay']], # Simple multiple completion
['python ', []], # Don't add anything - no more
['set basename o', ['off', 'on']],
['set basename of', ['off']],

# Multiple completion on two words
['set auto', ['autoeval', 'autolist', 'autopython']],

# Completion when word is complete, without space.
['show', ['show ']],

# Completion when word is complete with space.
['info ',
['args', 'break', 'builtins', 'code', 'display', 'files', 'frame',
'globals', 'line',
'locals', 'macro', 'pc', 'program', 'return', 'signals', 'source',
'threads']],

['help sta', ['stack', 'status']],
[' unalias c', ['c', 'chdir', 'cond']],


# Any set style completion
['set style def', ['default']],

# ['set auto eval ', '', ['off', 'on']],
# Many 3-word completions
# ['set auto ', ['eval', 'irb', 'list']],
# Many two-word completions
# ['set auto e', ['eval']],
# ['disas', ['disassemble']], # Another single completion
# ['help syn', ['syntax']],
# ## FIXME:
# ## ['help syntax co', ['command']],
# ['help br', ['break', 'breakpoints']],
]:
got = self.run_complete(line)
self.assertEqual(expect_completion, got,
"Completion of '%s', expecting %s, got %s" %
(line, expect_completion, got))
pass

got = self.run_complete('')
self.assertTrue(len(got) > 30,
'Initial completion should return more '
'than 30 commands')
got = self.run_complete('info files ')
self.assertTrue(len(got) > 0,
'info files completion should return a file')
got = self.run_complete('unalias ')
self.assertTrue(len(got) > 0,
'unalias should return lots of aliases')
return
if not IS_PYPY:
def test_completion(self):

self.dbgr = Mdebugger.Debugger()

for line, expect_completion in [
['set basename', ['basename ']],
['set basename ', ['off', 'on']],
['where', ['where ']], # Single alias completion
['sho', ['show']], # Simple single completion
['un', ['unalias', 'undisplay']], # Simple multiple completion
['python ', []], # Don't add anything - no more
['set basename o', ['off', 'on']],
['set basename of', ['off']],

# Multiple completion on two words
['set auto', ['autoeval', 'autolist', 'autopython']],

# Completion when word is complete, without space.
['show', ['show ']],

# Completion when word is complete with space.
['info ',
['args', 'break', 'builtins', 'code', 'display', 'files', 'frame',
'globals', 'line',
'locals', 'macro', 'pc', 'program', 'return', 'signals', 'source',
'threads']],

['help sta', ['stack', 'status']],
[' unalias c', ['c', 'chdir', 'cond']],


# Any set style completion
['set style def', ['default']],

# ['set auto eval ', '', ['off', 'on']],
# Many 3-word completions
# ['set auto ', ['eval', 'irb', 'list']],
# Many two-word completions
# ['set auto e', ['eval']],
# ['disas', ['disassemble']], # Another single completion
# ['help syn', ['syntax']],
# ## FIXME:
# ## ['help syntax co', ['command']],
# ['help br', ['break', 'breakpoints']],
]:
got = self.run_complete(line)
self.assertEqual(expect_completion, got,
"Completion of '%s', expecting %s, got %s" %
(line, expect_completion, got))
pass

got = self.run_complete('')
self.assertTrue(len(got) > 30,
'Initial completion should return more '
'than 30 commands')
got = self.run_complete('info files ')
self.assertTrue(len(got) > 0,
'info files completion should return a file')
got = self.run_complete('unalias ')
self.assertTrue(len(got) > 0,
'unalias should return lots of aliases')
return
pass

if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion test/unit/test-stack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
'Unit test for trepan.frame'
import inspect, sys, unittest
from xdis import IS_PYPY

from trepan.lib import stack as Mstack

Expand All @@ -17,8 +18,10 @@ def test_count_frames(self):

def test_stack_misc(self):
f = inspect.currentframe()
if sys.version_info[0] == 2 and sys.version_info[1] <= 4:
if sys.version_info[0:2] <= (2, 4):
expect = 'defaultTestResult'
elif IS_PYPY:
expect = '_testMethodName'
else:
expect = 'startTest'
pass
Expand Down

0 comments on commit 4fef1b9

Please sign in to comment.