cpython: bcf27fa55632 (original) (raw)
Mercurial > cpython
changeset 100191:bcf27fa55632
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. [#26204]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Mon, 08 Feb 2016 17:57:02 +0100 |
parents | a0d053899ff8 |
children | 4bdb21380743 |
files | Lib/test/test_inspect.py Lib/test/test_peepholer.py Lib/test/test_support.py Lib/test/test_sys_settrace.py Lib/test/test_traceback.py |
diffstat | 5 files changed, 23 insertions(+), 20 deletions(-)[+] [-] Lib/test/test_inspect.py 2 Lib/test/test_peepholer.py 20 Lib/test/test_support.py 3 Lib/test/test_sys_settrace.py 4 Lib/test/test_traceback.py 14 |
line wrap: on
line diff
--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -401,7 +401,7 @@ class TestRetrievingSourceCode(GetSource self.assertEqual(normcase(inspect.getsourcefile(mod.spam)), modfile) self.assertEqual(normcase(inspect.getsourcefile(git.abuse)), modfile) fn = "_non_existing_filename_used_for_sourcefile_test.py"
co = compile("None", fn, "exec")[](#l1.7)
co = compile("x=1", fn, "exec")[](#l1.8) self.assertEqual(inspect.getsourcefile(co), None)[](#l1.9) linecache.cache[co.co_filename] = (1, None, "None", co.co_filename)[](#l1.10) try:[](#l1.11)
--- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -1,9 +1,8 @@ import dis import re import sys -from io import StringIO +import textwrap import unittest -from math import copysign from test.bytecode_helper import BytecodeTestCase @@ -30,22 +29,25 @@ class TestTranforms(BytecodeTestCase): def test_global_as_constant(self): # LOAD_GLOBAL None/True/False --> LOAD_CONST None/True/False
def f(x):[](#l2.18)
None[](#l2.19)
None[](#l2.20)
def f():[](#l2.21)
x = None[](#l2.22)
x = None[](#l2.23) return x[](#l2.24)
def g(x):[](#l2.25)
True[](#l2.26)
def g():[](#l2.27)
x = True[](#l2.28) return x[](#l2.29)
def h(x):[](#l2.30)
False[](#l2.31)
def h():[](#l2.32)
x = False[](#l2.33) return x[](#l2.34)
+ for func, elem in ((f, None), (g, True), (h, False)): self.assertNotInBytecode(func, 'LOAD_GLOBAL') self.assertInBytecode(func, 'LOAD_CONST', elem) + def f(): 'Adding a docstring made this test fail in Py2.5.0' return None + self.assertNotInBytecode(f, 'LOAD_GLOBAL') self.assertInBytecode(f, 'LOAD_CONST', None)
--- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -230,7 +230,8 @@ class TestSupport(unittest.TestCase): def test_check_syntax_error(self): support.check_syntax_error(self, "def class")
self.assertRaises(AssertionError, support.check_syntax_error, self, "1")[](#l3.7)
with self.assertRaises(AssertionError):[](#l3.8)
support.check_syntax_error(self, "x=1")[](#l3.9)
def test_CleanImport(self): import importlib
--- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -338,8 +338,8 @@ class TraceTestCase(unittest.TestCase): def test_14_onliner_if(self): def onliners():
if True: False[](#l4.7)
else: True[](#l4.8)
if True: x=False[](#l4.9)
else: x=True[](#l4.10) return 0[](#l4.11) self.run_and_compare([](#l4.12) onliners,[](#l4.13)
--- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -129,12 +129,12 @@ class SyntaxTracebackCases(unittest.Test def do_test(firstlines, message, charset, lineno): # Raise the message in a subprocess, and catch the output try:
output = open(TESTFN, "w", encoding=charset)[](#l5.7)
output.write("""{0}if 1:[](#l5.8)
import traceback;[](#l5.9)
raise RuntimeError('{1}')[](#l5.10)
""".format(firstlines, message))[](#l5.11)
output.close()[](#l5.12)
with open(TESTFN, "w", encoding=charset) as output:[](#l5.13)
output.write("""{0}if 1:[](#l5.14)
import traceback;[](#l5.15)
raise RuntimeError('{1}')[](#l5.16)
""".format(firstlines, message))[](#l5.17)
+ process = subprocess.Popen([sys.executable, TESTFN], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = process.communicate() @@ -176,7 +176,7 @@ class SyntaxTracebackCases(unittest.Test 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)[](#l5.26)
do_test("x=0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)[](#l5.27)
def test_print_traceback_at_exit(self): # Issue #22599: Ensure that it is possible to use the traceback module