Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e59eb2c0
Commit
e59eb2c0
authored
Nov 20, 2013
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19183: Fix repr() tests of test_gdb, hash() is now platform dependent
parent
7da027f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
20 deletions
+29
-20
Lib/test/test_gdb.py
Lib/test/test_gdb.py
+29
-20
No files found.
Lib/test/test_gdb.py
View file @
e59eb2c0
...
@@ -42,6 +42,8 @@ if not sysconfig.is_python_build():
...
@@ -42,6 +42,8 @@ if not sysconfig.is_python_build():
checkout_hook_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
sys
.
executable
),
checkout_hook_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
sys
.
executable
),
'python-gdb.py'
)
'python-gdb.py'
)
PYTHONHASHSEED
=
'123'
def
run_gdb
(
*
args
,
**
env_vars
):
def
run_gdb
(
*
args
,
**
env_vars
):
"""Runs gdb in --batch mode with the additional arguments given by *args.
"""Runs gdb in --batch mode with the additional arguments given by *args.
...
@@ -146,7 +148,7 @@ class DebuggerTests(unittest.TestCase):
...
@@ -146,7 +148,7 @@ class DebuggerTests(unittest.TestCase):
# print ' '.join(args)
# print ' '.join(args)
# Use "args" to invoke gdb, capturing stdout, stderr:
# Use "args" to invoke gdb, capturing stdout, stderr:
out
,
err
=
run_gdb
(
*
args
,
PYTHONHASHSEED
=
'0'
)
out
,
err
=
run_gdb
(
*
args
,
PYTHONHASHSEED
=
PYTHONHASHSEED
)
errlines
=
err
.
splitlines
()
errlines
=
err
.
splitlines
()
unexpected_errlines
=
[]
unexpected_errlines
=
[]
...
@@ -219,41 +221,48 @@ class PrettyPrintTests(DebuggerTests):
...
@@ -219,41 +221,48 @@ class PrettyPrintTests(DebuggerTests):
gdb_output
=
self
.
get_stack_trace
(
'id(42)'
)
gdb_output
=
self
.
get_stack_trace
(
'id(42)'
)
self
.
assertTrue
(
BREAKPOINT_FN
in
gdb_output
)
self
.
assertTrue
(
BREAKPOINT_FN
in
gdb_output
)
def
get_python_repr
(
self
,
val
):
args
=
[
sys
.
executable
,
'-c'
,
'print(repr(%a))'
%
(
val
,)]
env
=
os
.
environ
.
copy
()
env
[
'PYTHONHASHSEED'
]
=
PYTHONHASHSEED
output
=
subprocess
.
check_output
(
args
,
env
=
env
,
universal_newlines
=
True
)
return
output
.
rstrip
()
def
assertGdbRepr
(
self
,
val
,
exp_repr
=
None
,
cmds_after_breakpoint
=
None
):
def
assertGdbRepr
(
self
,
val
,
exp_repr
=
None
,
cmds_after_breakpoint
=
None
):
# Ensure that gdb's rendering of the value in a debugged process
# Ensure that gdb's rendering of the value in a debugged process
# matches repr(value) in this process:
# matches repr(value) in this process:
gdb_repr
,
gdb_output
=
self
.
get_gdb_repr
(
'id('
+
ascii
(
val
)
+
')'
,
gdb_repr
,
gdb_output
=
self
.
get_gdb_repr
(
'id('
+
ascii
(
val
)
+
')'
,
cmds_after_breakpoint
)
cmds_after_breakpoint
)
if
not
exp_repr
:
if
not
exp_repr
:
exp_repr
=
repr
(
val
)
exp_repr
=
self
.
get_python_
repr
(
val
)
self
.
assertEqual
(
gdb_repr
,
exp_repr
,
self
.
assertEqual
(
gdb_repr
,
exp_repr
,
(
'%r did not equal expected %r; full output was:
\
n
%s'
(
'%r did not equal expected %r; full output was:
\
n
%s'
%
(
gdb_repr
,
exp_repr
,
gdb_output
)))
%
(
gdb_repr
,
exp_repr
,
gdb_output
)))
def
test_int
(
self
):
def
test_int
(
self
):
'Verify the pretty-printing of various int values'
'Verify the pretty-printing of various int values'
self
.
assertGdbRepr
(
42
)
self
.
assertGdbRepr
(
42
,
'42'
)
self
.
assertGdbRepr
(
0
)
self
.
assertGdbRepr
(
0
,
'0'
)
self
.
assertGdbRepr
(
-
7
)
self
.
assertGdbRepr
(
-
7
,
'-7'
)
self
.
assertGdbRepr
(
1000000000000
)
self
.
assertGdbRepr
(
1000000000000
,
'1000000000000'
)
self
.
assertGdbRepr
(
-
1000000000000000
)
self
.
assertGdbRepr
(
-
1000000000000000
,
'-1000000000000000'
)
def
test_singletons
(
self
):
def
test_singletons
(
self
):
'Verify the pretty-printing of True, False and None'
'Verify the pretty-printing of True, False and None'
self
.
assertGdbRepr
(
True
)
self
.
assertGdbRepr
(
True
,
'True'
)
self
.
assertGdbRepr
(
False
)
self
.
assertGdbRepr
(
False
,
'False'
)
self
.
assertGdbRepr
(
None
)
self
.
assertGdbRepr
(
None
,
'None'
)
def
test_dicts
(
self
):
def
test_dicts
(
self
):
'Verify the pretty-printing of dictionaries'
'Verify the pretty-printing of dictionaries'
self
.
assertGdbRepr
({})
self
.
assertGdbRepr
({}
,
'{}'
)
self
.
assertGdbRepr
({
'foo'
:
'bar'
})
self
.
assertGdbRepr
({
'foo'
:
'bar'
})
self
.
assertGdbRepr
({
'foo'
:
'bar'
,
'douglas'
:
42
})
,
self
.
assertGdbRepr
({
'foo'
:
'bar'
,
'douglas'
:
42
})
def
test_lists
(
self
):
def
test_lists
(
self
):
'Verify the pretty-printing of lists'
'Verify the pretty-printing of lists'
self
.
assertGdbRepr
([])
self
.
assertGdbRepr
([]
,
'[]'
)
self
.
assertGdbRepr
(
list
(
range
(
5
)))
self
.
assertGdbRepr
(
list
(
range
(
5
))
,
'[0, 1, 2, 3, 4]'
)
def
test_bytes
(
self
):
def
test_bytes
(
self
):
'Verify the pretty-printing of bytes'
'Verify the pretty-printing of bytes'
...
@@ -303,7 +312,7 @@ class PrettyPrintTests(DebuggerTests):
...
@@ -303,7 +312,7 @@ class PrettyPrintTests(DebuggerTests):
def
test_tuples
(
self
):
def
test_tuples
(
self
):
'Verify the pretty-printing of tuples'
'Verify the pretty-printing of tuples'
self
.
assertGdbRepr
(
tuple
())
self
.
assertGdbRepr
(
tuple
()
,
'()'
)
self
.
assertGdbRepr
((
1
,),
'(1,)'
)
self
.
assertGdbRepr
((
1
,),
'(1,)'
)
self
.
assertGdbRepr
((
'foo'
,
'bar'
,
'baz'
))
self
.
assertGdbRepr
((
'foo'
,
'bar'
,
'baz'
))
...
@@ -312,13 +321,13 @@ class PrettyPrintTests(DebuggerTests):
...
@@ -312,13 +321,13 @@ class PrettyPrintTests(DebuggerTests):
if
(
gdb_major_version
,
gdb_minor_version
)
<
(
7
,
3
):
if
(
gdb_major_version
,
gdb_minor_version
)
<
(
7
,
3
):
self
.
skipTest
(
"pretty-printing of sets needs gdb 7.3 or later"
)
self
.
skipTest
(
"pretty-printing of sets needs gdb 7.3 or later"
)
self
.
assertGdbRepr
(
set
())
self
.
assertGdbRepr
(
set
())
self
.
assertGdbRepr
(
set
([
'a'
,
'b'
])
,
"{'a', 'b'}"
)
self
.
assertGdbRepr
(
set
([
'a'
,
'b'
]))
self
.
assertGdbRepr
(
set
([
4
,
5
,
6
])
,
"{4, 5, 6}"
)
self
.
assertGdbRepr
(
set
([
4
,
5
,
6
]))
# Ensure that we handle sets containing the "dummy" key value,
# Ensure that we handle sets containing the "dummy" key value,
# which happens on deletion:
# which happens on deletion:
gdb_repr
,
gdb_output
=
self
.
get_gdb_repr
(
'''s = set(['a','b'])
gdb_repr
,
gdb_output
=
self
.
get_gdb_repr
(
'''s = set(['a','b'])
s.
pop(
)
s.
remove('a'
)
id(s)'''
)
id(s)'''
)
self
.
assertEqual
(
gdb_repr
,
"{'b'}"
)
self
.
assertEqual
(
gdb_repr
,
"{'b'}"
)
...
@@ -327,8 +336,8 @@ id(s)''')
...
@@ -327,8 +336,8 @@ id(s)''')
if
(
gdb_major_version
,
gdb_minor_version
)
<
(
7
,
3
):
if
(
gdb_major_version
,
gdb_minor_version
)
<
(
7
,
3
):
self
.
skipTest
(
"pretty-printing of frozensets needs gdb 7.3 or later"
)
self
.
skipTest
(
"pretty-printing of frozensets needs gdb 7.3 or later"
)
self
.
assertGdbRepr
(
frozenset
())
self
.
assertGdbRepr
(
frozenset
())
self
.
assertGdbRepr
(
frozenset
([
'a'
,
'b'
])
,
"frozenset({'a', 'b'})"
)
self
.
assertGdbRepr
(
frozenset
([
'a'
,
'b'
]))
self
.
assertGdbRepr
(
frozenset
([
4
,
5
,
6
])
,
"frozenset({4, 5, 6})"
)
self
.
assertGdbRepr
(
frozenset
([
4
,
5
,
6
]))
def
test_exceptions
(
self
):
def
test_exceptions
(
self
):
# Test a RuntimeError
# Test a RuntimeError
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment