diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-02-24 02:52:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-24 02:52:31 (GMT) |
commit | 2e2ab6752b9815490df366f50d022cdda1235511 (patch) | |
tree | 18b00db996c790b52e8149375ac271c49acdf1f7 /Lib | |
parent | 9a0116d35ceb5d4a01546da7fc2ad329282579b3 (diff) | |
download | cpython-2e2ab6752b9815490df366f50d022cdda1235511.zip cpython-2e2ab6752b9815490df366f50d022cdda1235511.tar.gz cpython-2e2ab6752b9815490df366f50d022cdda1235511.tar.bz2 |
gh-102158: Add tests for `softkwlist` (GH-102159)
---------
(cherry picked from commit 9f3ecd1aa3566947648a053bd9716ed67dd9a718)
Co-authored-by: Eclips4 <80244920+Eclips4@users.noreply.github.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_keyword.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_keyword.py b/Lib/test/test_keyword.py index 3e2a8b3..f329f88 100644 --- a/Lib/test/test_keyword.py +++ b/Lib/test/test_keyword.py @@ -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() |