diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-06-06 12:40:47 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-06-06 12:42:07 -0400 |
commit | cb09207f6f291696714f5550aacd1e9a3a0e81e1 (patch) | |
tree | 026f8d44180c494e614708a2861326c8ca489407 /tests/test_phystokens.py | |
parent | 95c582fd8038a7158ff96baff4186f5fb601afd4 (diff) | |
download | python-coveragepy-git-cb09207f6f291696714f5550aacd1e9a3a0e81e1.tar.gz |
feat: soft keywords are shown in bold in the HTML report
The match and case soft keywords are shown in bold when they are
keywords, and not when they are not.
The underscore soft keyword is ignored, because it is harder to get
right, and because it doesn't look that much different in bold anyway.
Diffstat (limited to 'tests/test_phystokens.py')
-rw-r--r-- | tests/test_phystokens.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index 82b887e6..3c214c63 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -103,6 +103,42 @@ class PhysTokensTest(CoverageTest): self.check_file_tokenization(stress) +@pytest.mark.skipif(not env.PYBEHAVIOR.soft_keywords, reason="Soft keywords are new in Python 3.10") +class SoftKeywordTest(CoverageTest): + """Tests the tokenizer handling soft keywords.""" + + run_in_temp_dir = False + + def test_soft_keywords(self): + source = textwrap.dedent("""\ + match re.match(something): + case ["what"]: + match = case("hello") + case [_]: + match("hello") + match another.thing: + case 1: + pass + + class case(): pass + def match(): + global case + """) + tokens = list(source_token_lines(source)) + assert tokens[0][0] == ("key", "match") + assert tokens[0][4] == ("nam", "match") + assert tokens[1][1] == ("key", "case") + assert tokens[2][1] == ("nam", "match") + assert tokens[2][5] == ("nam", "case") + assert tokens[3][1] == ("key", "case") + assert tokens[4][1] == ("nam", "match") + assert tokens[5][1] == ("key", "match") + assert tokens[6][1] == ("key", "case") + assert tokens[9][2] == ("nam", "case") + assert tokens[10][2] == ("nam", "match") + assert tokens[11][3] == ("nam", "case") + + # The default encoding is different in Python 2 and Python 3. DEF_ENCODING = "utf-8" |