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
1d5ccdb2
Commit
1d5ccdb2
authored
May 21, 2012
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
parent
3267a30d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
52 deletions
+20
-52
Lib/test/test_cmd_line_script.py
Lib/test/test_cmd_line_script.py
+19
-0
Lib/test/test_raise.py
Lib/test/test_raise.py
+1
-52
No files found.
Lib/test/test_cmd_line_script.py
View file @
1d5ccdb2
...
@@ -7,6 +7,7 @@ import os
...
@@ -7,6 +7,7 @@ import os
import
os.path
import
os.path
import
py_compile
import
py_compile
import
textwrap
from
test
import
support
from
test
import
support
from
test.script_helper
import
(
from
test.script_helper
import
(
make_pkg
,
make_script
,
make_zip_pkg
,
make_zip_script
,
make_pkg
,
make_script
,
make_zip_pkg
,
make_zip_script
,
...
@@ -286,6 +287,24 @@ class CmdLineTest(unittest.TestCase):
...
@@ -286,6 +287,24 @@ class CmdLineTest(unittest.TestCase):
self
.
_check_output
(
script_name
,
rc
,
out
,
self
.
_check_output
(
script_name
,
rc
,
out
,
script_name
,
script_name
,
''
,
''
)
script_name
,
script_name
,
''
,
''
)
def
test_pep_409_verbiage
(
self
):
# Make sure PEP 409 syntax properly suppresses
# the context of an exception
script
=
textwrap
.
dedent
(
"""
\
try:
raise ValueError
except:
raise NameError from None
"""
)
with
temp_dir
()
as
script_dir
:
script_name
=
_make_test_script
(
script_dir
,
'script'
,
script
)
exitcode
,
stdout
,
stderr
=
assert_python_failure
(
script_name
)
text
=
stderr
.
decode
(
'ascii'
).
split
(
'
\
n
'
)
self
.
assertEqual
(
len
(
text
),
4
)
self
.
assertTrue
(
text
[
0
].
startswith
(
'Traceback'
))
self
.
assertTrue
(
text
[
1
].
startswith
(
' File '
))
self
.
assertTrue
(
text
[
3
].
startswith
(
'NameError'
))
def
test_main
():
def
test_main
():
support
.
run_unittest
(
CmdLineTest
)
support
.
run_unittest
(
CmdLineTest
)
support
.
reap_children
()
support
.
reap_children
()
...
...
Lib/test/test_raise.py
View file @
1d5ccdb2
...
@@ -3,27 +3,13 @@
...
@@ -3,27 +3,13 @@
"""Tests for the raise statement."""
"""Tests for the raise statement."""
from
test
import
support
,
script_helper
from
test
import
support
import
re
import
re
import
sys
import
sys
import
types
import
types
import
unittest
import
unittest
try
:
from
resource
import
setrlimit
,
RLIMIT_CORE
,
error
as
resource_error
except
ImportError
:
prepare_subprocess
=
None
else
:
def
prepare_subprocess
():
# don't create core file
try
:
setrlimit
(
RLIMIT_CORE
,
(
0
,
0
))
except
(
ValueError
,
resource_error
):
pass
def
get_tb
():
def
get_tb
():
try
:
try
:
raise
OSError
()
raise
OSError
()
...
@@ -224,43 +210,6 @@ class TestCause(unittest.TestCase):
...
@@ -224,43 +210,6 @@ class TestCause(unittest.TestCase):
class
TestTraceback
(
unittest
.
TestCase
):
class
TestTraceback
(
unittest
.
TestCase
):
def
get_output
(
self
,
code
,
filename
=
None
):
"""
Run the specified code in Python (in a new child process) and read the
output from the standard error or from a file (if filename is set).
Return the output lines as a list.
"""
options
=
{}
if
prepare_subprocess
:
options
[
'preexec_fn'
]
=
prepare_subprocess
process
=
script_helper
.
spawn_python
(
'-c'
,
code
,
**
options
)
stdout
,
stderr
=
process
.
communicate
()
exitcode
=
process
.
wait
()
output
=
support
.
strip_python_stderr
(
stdout
)
output
=
output
.
decode
(
'ascii'
,
'backslashreplace'
)
if
filename
:
self
.
assertEqual
(
output
,
''
)
with
open
(
filename
,
"rb"
)
as
fp
:
output
=
fp
.
read
()
output
=
output
.
decode
(
'ascii'
,
'backslashreplace'
)
output
=
re
.
sub
(
'Current thread 0x[0-9a-f]+'
,
'Current thread XXX'
,
output
)
return
output
.
splitlines
(),
exitcode
def
test_traceback_verbiage
(
self
):
code
=
"""
try:
raise ValueError
except:
raise NameError from None
"""
text
,
exitcode
=
self
.
get_output
(
code
)
self
.
assertEqual
(
len
(
text
),
3
)
self
.
assertTrue
(
text
[
0
].
startswith
(
'Traceback'
))
self
.
assertTrue
(
text
[
1
].
startswith
(
' File '
))
self
.
assertTrue
(
text
[
2
].
startswith
(
'NameError'
))
def
test_sets_traceback
(
self
):
def
test_sets_traceback
(
self
):
try
:
try
:
raise
IndexError
()
raise
IndexError
()
...
...
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