]> granicus.if.org Git - python/commitdiff
bpo-32482: Fix suspicious code in tests for syntax and grammar. (#5086)
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 4 Jan 2018 08:36:35 +0000 (10:36 +0200)
committerGitHub <noreply@github.com>
Thu, 4 Jan 2018 08:36:35 +0000 (10:36 +0200)
Lib/test/test_grammar.py
Lib/test/test_syntax.py

index 9f26e9c4fb022fdb531d9faad0f9b00b59bfc64e..88c22b89d444a3f93cb398c3fc1731904d806914 100644 (file)
@@ -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
@@ -1091,7 +1091,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
@@ -1200,7 +1199,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):
index e161f56d30f2143d63dc0641cb4a7dd0e1d3598b..2b96a94401a87d7451ebaf128da38bfefb6397a3 100644 (file)
@@ -668,12 +668,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")