summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_traceback.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-02-08 16:57:02 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-02-08 16:57:02 (GMT)
commit51d8c526d5634fa1f0e4976fd357c5423a792082 (patch)
tree5aaa710f4f336f949691c88f70a221169ccc42f8 /Lib/test/test_traceback.py
parentf089196beb0ad8fb262be42eddd92af3f0fe81c1 (diff)
downloadcpython-51d8c526d5634fa1f0e4976fd357c5423a792082.zip
cpython-51d8c526d5634fa1f0e4976fd357c5423a792082.tar.gz
cpython-51d8c526d5634fa1f0e4976fd357c5423a792082.tar.bz2
Replace noop constant statement with expression
* Constant statements will be ignored and the compiler will emit a SyntaxWarning. * Replace constant statement (ex: "1") with an expression statement (ex: "x=1"). * test_traceback: use context manager on the file. Issue #26204.
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r--Lib/test/test_traceback.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index b7695d6..2f739ba 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -129,12 +129,12 @@ class SyntaxTracebackCases(unittest.TestCase):
def do_test(firstlines, message, charset, lineno):
# Raise the message in a subprocess, and catch the output
try:
- output = open(TESTFN, "w", encoding=charset)
- output.write("""{0}if 1:
- import traceback;
- raise RuntimeError('{1}')
- """.format(firstlines, message))
- output.close()
+ with open(TESTFN, "w", encoding=charset) as output:
+ output.write("""{0}if 1:
+ import traceback;
+ raise RuntimeError('{1}')
+ """.format(firstlines, message))
+
process = subprocess.Popen([sys.executable, TESTFN],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = process.communicate()
@@ -176,7 +176,7 @@ class SyntaxTracebackCases(unittest.TestCase):
do_test(" \t\f\n# coding: {0}\n".format(charset),
text, charset, 5)
# Issue #18960: coding spec should has no effect
- do_test("0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
+ do_test("x=0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
def test_print_traceback_at_exit(self):
# Issue #22599: Ensure that it is possible to use the traceback module