Use the "if 1:" prefix so that quoted code appears nicely

nested inside the test suite.

def test_me():
    exec("""if 1:
        ...code...
        """)

No other change here.
This commit is contained in:
Amaury Forgeot d'Arc 2010-09-10 19:40:52 +00:00
parent 4f5e298075
commit dfa9b294fa
1 changed files with 153 additions and 153 deletions

View File

@ -192,7 +192,7 @@ class ScopeTests(unittest.TestCase):
def testUnoptimizedNamespaces(self): def testUnoptimizedNamespaces(self):
check_syntax_error(self, """\ check_syntax_error(self, """if 1:
def unoptimized_clash1(strip): def unoptimized_clash1(strip):
def f(s): def f(s):
from sys import * from sys import *
@ -200,7 +200,7 @@ def unoptimized_clash1(strip):
return f return f
""") """)
check_syntax_error(self, """\ check_syntax_error(self, """if 1:
def unoptimized_clash2(): def unoptimized_clash2():
from sys import * from sys import *
def f(s): def f(s):
@ -208,7 +208,7 @@ def unoptimized_clash2():
return f return f
""") """)
check_syntax_error(self, """\ check_syntax_error(self, """if 1:
def unoptimized_clash2(): def unoptimized_clash2():
from sys import * from sys import *
def g(): def g():
@ -217,14 +217,14 @@ def unoptimized_clash2():
return f return f
""") """)
check_syntax_error(self, """\ check_syntax_error(self, """if 1:
def f(x): def f(x):
def g(): def g():
return x return x
del x # can't del name del x # can't del name
""") """)
check_syntax_error(self, """\ check_syntax_error(self, """if 1:
def f(): def f():
def g(): def g():
from sys import * from sys import *
@ -273,7 +273,7 @@ def f():
self.assertRaises(NameError, errorInInner) self.assertRaises(NameError, errorInInner)
# test for bug #1501934: incorrect LOAD/STORE_GLOBAL generation # test for bug #1501934: incorrect LOAD/STORE_GLOBAL generation
exec(""" exec("""if 1:
global_x = 1 global_x = 1
def f(): def f():
global_x += 1 global_x += 1
@ -304,7 +304,7 @@ else:
def testScopeOfGlobalStmt(self): def testScopeOfGlobalStmt(self):
# Examples posted by Samuele Pedroni to python-dev on 3/1/2001 # Examples posted by Samuele Pedroni to python-dev on 3/1/2001
exec("""\ exec("""if 1:
# I # I
x = 7 x = 7
def f(): def f():
@ -409,7 +409,7 @@ self.assertEqual(g.get(), 13)
def testClassAndGlobal(self): def testClassAndGlobal(self):
exec("""\ exec("""if 1:
def test(x): def test(x):
class Foo: class Foo:
global x global x
@ -626,7 +626,10 @@ self.assertTrue(X.passed)
# function to other nested functions in the same block. # function to other nested functions in the same block.
# This test verifies that a global statement in the first # This test verifies that a global statement in the first
# function does not affect the second function. # function does not affect the second function.
CODE = """def f(): local_ns = {}
global_ns = {}
exec("""if 1:
def f():
y = 1 y = 1
def g(): def g():
global y global y
@ -638,10 +641,7 @@ y = 9
g, h = f() g, h = f()
result9 = g() result9 = g()
result2 = h() result2 = h()
""" """, local_ns, global_ns)
local_ns = {}
global_ns = {}
exec(CODE, local_ns, global_ns)
self.assertEqual(2, global_ns["result2"]) self.assertEqual(2, global_ns["result2"])
self.assertEqual(9, global_ns["result9"]) self.assertEqual(9, global_ns["result9"])