From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 4 Jan 2018 09:32:53 +0000 (-0800) Subject: bpo-32482: Fix suspicious code in tests for syntax and grammar. (GH-5086) (#5095) X-Git-Tag: v3.6.5rc1~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a70d5ff992e5e123a3fa6f0e7f672026db8ed1f7;p=python bpo-32482: Fix suspicious code in tests for syntax and grammar. (GH-5086) (#5095) (cherry picked from commit 0cc99c8cd70d422e4b345837a907db30e9180ab9) --- diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 62f3251f05..ac8d85a3c4 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -575,6 +575,10 @@ class GrammarTests(unittest.TestCase): self.assertEqual(f(spam='fried', **{'eggs':'scrambled'}), ((), {'eggs':'scrambled', 'spam':'fried'})) + # Check ast errors in *args and *kwargs + check_syntax_error(self, "f(*g(1=2))") + check_syntax_error(self, "f(**g(1=2))") + # argument annotation tests def f(x) -> list: pass self.assertEqual(f.__annotations__, {'return': list}) @@ -616,10 +620,6 @@ class GrammarTests(unittest.TestCase): def f(*, k=1): return closure def f() -> int: return closure - # Check ast errors in *args and *kwargs - check_syntax_error(self, "f(*g(1=2))") - check_syntax_error(self, "f(**g(1=2))") - # Check trailing commas are permitted in funcdef argument list def f(a,): pass def f(*args,): pass @@ -1056,7 +1056,6 @@ class GrammarTests(unittest.TestCase): try: 1/0 except EOFError: pass except TypeError as msg: pass - except RuntimeError as msg: pass except: pass else: pass try: 1/0 @@ -1165,7 +1164,7 @@ class GrammarTests(unittest.TestCase): d[1,2] = 3 d[1,2,3] = 4 L = list(d) - L.sort(key=lambda x: x if isinstance(x, tuple) else ()) + L.sort(key=lambda x: (type(x).__name__, x)) self.assertEqual(str(L), '[1, (1,), (1, 2), (1, 2, 3)]') def test_atoms(self): diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index b7095a2cdb..26f508316b 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -600,12 +600,12 @@ class SyntaxTestCase(unittest.TestCase): "positional argument follows keyword argument") def test_kwargs_last2(self): - self._check_error("int(**{base: 10}, '2')", + self._check_error("int(**{'base': 10}, '2')", "positional argument follows " "keyword argument unpacking") def test_kwargs_last3(self): - self._check_error("int(**{base: 10}, *['2'])", + self._check_error("int(**{'base': 10}, *['2'])", "iterable argument unpacking follows " "keyword argument unpacking")