]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-102158: Add tests for `softkwlist` (#102159)
authorEclips4 <80244920+Eclips4@users.noreply.github.com>
Fri, 24 Feb 2023 02:28:24 +0000 (05:28 +0300)
committerGitHub <noreply@github.com>
Fri, 24 Feb 2023 02:28:24 +0000 (21:28 -0500)
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Lib/test/test_keyword.py

index 3e2a8b3fb7f4c3bfd1948f5278593545e81226c4..f329f88fa01d51b3e09f2a09c7cb1d81d049aae2 100644 (file)
@@ -20,18 +20,36 @@ class Test_iskeyword(unittest.TestCase):
         keyword.kwlist = ['its', 'all', 'eggs', 'beans', 'and', 'a', 'slice']
         self.assertFalse(keyword.iskeyword('eggs'))
 
+    def test_changing_the_softkwlist_does_not_affect_issoftkeyword(self):
+        oldlist = keyword.softkwlist
+        self.addCleanup(setattr, keyword, "softkwlist", oldlist)
+        keyword.softkwlist = ["foo", "bar", "spam", "egs", "case"]
+        self.assertFalse(keyword.issoftkeyword("spam"))
+
     def test_all_keywords_fail_to_be_used_as_names(self):
         for key in keyword.kwlist:
             with self.assertRaises(SyntaxError):
                 exec(f"{key} = 42")
 
+    def test_all_soft_keywords_can_be_used_as_names(self):
+        for key in keyword.softkwlist:
+            exec(f"{key} = 42")
+
     def test_async_and_await_are_keywords(self):
         self.assertIn("async", keyword.kwlist)
         self.assertIn("await", keyword.kwlist)
 
+    def test_match_and_case_are_soft_keywords(self):
+        self.assertIn("match", keyword.softkwlist)
+        self.assertIn("case", keyword.softkwlist)
+        self.assertIn("_", keyword.softkwlist)
+
     def test_keywords_are_sorted(self):
         self.assertListEqual(sorted(keyword.kwlist), keyword.kwlist)
 
+    def test_softkeywords_are_sorted(self):
+        self.assertListEqual(sorted(keyword.softkwlist), keyword.softkwlist)
+
 
 if __name__ == "__main__":
     unittest.main()