Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-102158: Add tests for softkwlist #102159

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,36 @@ def test_changing_the_kwlist_does_not_affect_iskeyword(self):
keyword.kwlist = ['its', 'all', 'eggs', 'beans', 'and', 'a', 'slice']
self.assertFalse(keyword.iskeyword('eggs'))

def test_changing_the_softkwlist_does_not_affect_issoftkeyword(self):
Eclips4 marked this conversation as resolved.
Show resolved Hide resolved
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)
Eclips4 marked this conversation as resolved.
Show resolved Hide resolved

Eclips4 marked this conversation as resolved.
Show resolved Hide resolved
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()