summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_grammar.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2010-03-17 13:52:48 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2010-03-17 13:52:48 (GMT)
commitd80b4bfd0b291d543c682d7dac0841de0192a238 (patch)
tree3968f81c285078b86b95aedddc6246f4d901a542 /Lib/test/test_grammar.py
parent8b3f1ce5916c3ec5f426d45496b313d7be6ea3a1 (diff)
downloadcpython-d80b4bfd0b291d543c682d7dac0841de0192a238.zip
cpython-d80b4bfd0b291d543c682d7dac0841de0192a238.tar.gz
cpython-d80b4bfd0b291d543c682d7dac0841de0192a238.tar.bz2
#7092: silence some more py3k warnings.
Diffstat (limited to 'Lib/test/test_grammar.py')
-rw-r--r--Lib/test/test_grammar.py45
1 files changed, 29 insertions, 16 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 12039e7..dca5e4a 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -8,7 +8,8 @@
# regression test, the filterwarnings() call has been added to
# regrtest.py.
-from test.test_support import run_unittest, check_syntax_error
+from test.test_support import run_unittest, check_syntax_error, \
+ check_py3k_warnings
import unittest
import sys
# testing import *
@@ -152,8 +153,9 @@ class GrammarTests(unittest.TestCase):
f1(*(), **{})
def f2(one_argument): pass
def f3(two, arguments): pass
- def f4(two, (compound, (argument, list))): pass
- def f5((compound, first), two): pass
+ # Silence Py3k warning
+ exec('def f4(two, (compound, (argument, list))): pass')
+ exec('def f5((compound, first), two): pass')
self.assertEquals(f2.func_code.co_varnames, ('one_argument',))
self.assertEquals(f3.func_code.co_varnames, ('two', 'arguments'))
if sys.platform.startswith('java'):
@@ -172,7 +174,8 @@ class GrammarTests(unittest.TestCase):
def v0(*rest): pass
def v1(a, *rest): pass
def v2(a, b, *rest): pass
- def v3(a, (b, c), *rest): return a, b, c, rest
+ # Silence Py3k warning
+ exec('def v3(a, (b, c), *rest): return a, b, c, rest')
f1()
f2(1)
@@ -277,9 +280,10 @@ class GrammarTests(unittest.TestCase):
d22v(*(1, 2, 3, 4))
d22v(1, 2, *(3, 4, 5))
d22v(1, *(2, 3), **{'d': 4})
- def d31v((x)): pass
+ # Silence Py3k warning
+ exec('def d31v((x)): pass')
+ exec('def d32v((x,)): pass')
d31v(1)
- def d32v((x,)): pass
d32v((1,))
# keyword arguments after *arglist
@@ -474,7 +478,7 @@ hello world
continue
except:
raise
- if count > 2 or big_hippo <> 1:
+ if count > 2 or big_hippo != 1:
self.fail("continue then break in try/except in loop broken!")
test_inner()
@@ -536,7 +540,7 @@ hello world
if z != 2: self.fail('exec u\'z=1+1\'')"""
g = {}
exec 'z = 1' in g
- if g.has_key('__builtins__'): del g['__builtins__']
+ if '__builtins__' in g: del g['__builtins__']
if g != {'z': 1}: self.fail('exec \'z = 1\' in g')
g = {}
l = {}
@@ -544,8 +548,8 @@ hello world
import warnings
warnings.filterwarnings("ignore", "global statement", module="<string>")
exec 'global a; a = 1; b = 2' in g, l
- if g.has_key('__builtins__'): del g['__builtins__']
- if l.has_key('__builtins__'): del l['__builtins__']
+ if '__builtins__' in g: del g['__builtins__']
+ if '__builtins__' in l: del l['__builtins__']
if (g, l) != ({'a':1}, {'b':2}):
self.fail('exec ... in g (%s), l (%s)' %(g,l))
@@ -677,7 +681,6 @@ hello world
x = (1 == 1)
if 1 == 1: pass
if 1 != 1: pass
- if 1 <> 1: pass
if 1 < 1: pass
if 1 > 1: pass
if 1 <= 1: pass
@@ -686,7 +689,10 @@ hello world
if 1 is not 1: pass
if 1 in (): pass
if 1 not in (): pass
- if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1: pass
+ if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 in 1 not in 1 is 1 is not 1: pass
+ # Silence Py3k warning
+ if eval('1 <> 1'): pass
+ if eval('1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1'): pass
def testBinaryMaskOps(self):
x = 1 & 1
@@ -774,9 +780,10 @@ hello world
x = {'one', 'two', 'three'}
x = {2, 3, 4,}
- x = `x`
- x = `1 or 2 or 3`
- self.assertEqual(`1,2`, '(1, 2)')
+ # Silence Py3k warning
+ x = eval('`x`')
+ x = eval('`1 or 2 or 3`')
+ self.assertEqual(eval('`1,2`'), '(1, 2)')
x = x
x = 'x'
@@ -988,7 +995,13 @@ hello world
def test_main():
- run_unittest(TokenTests, GrammarTests)
+ with check_py3k_warnings(
+ ("backquote not supported", SyntaxWarning),
+ ("tuple parameter unpacking has been removed", SyntaxWarning),
+ ("parenthesized argument names are invalid", SyntaxWarning),
+ ("classic int division", DeprecationWarning),
+ (".+ not supported in 3.x", DeprecationWarning)):
+ run_unittest(TokenTests, GrammarTests)
if __name__ == '__main__':
test_main()