Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
annotate tests/_testhelper.py @ 160:b4028838e0c8
Implement lexer option "prohibit_raiseonerror_filter".
Sphinx raises by default when an Error token is seen (by means of the
"raiseonerror" filter that is applied by default to lexers in Sphinx).
This option skips this and allows error locations to be seen and highlighted
properly.
While there convert most Generic.Error tokens to Error tokens because now
they can be handled by a lexer with "prohibit_raiseonerror_filter=True".
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 08 May 2026 17:46:28 +0200 |
| parents | 859ab8abce0a |
| children |
| rev | line source |
|---|---|
|
18
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
2 # :- |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
3 # SPDX-FileCopyrightText: © 2026 Franz Glasner |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
4 # SPDX-License-Identifier: MIT |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
5 # :- |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
6 """Test helper""" |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
7 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
8 __all__ = ["TokenAssertHelper"] |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
9 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
10 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
11 from pygments.token import Token, is_token_subtype, string_to_tokentype |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
12 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
13 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
14 class TokenAssertHelper(object): |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
15 """Mixin to test for token stream equality""" |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
16 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
17 def assertTokenEqual(self, tok_or_str, txt, token): |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
18 if is_token_subtype(tok_or_str, Token): |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
19 t = tok_or_str |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
20 else: |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
21 t = string_to_tokentype(tok_or_str) |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
22 self.assertEqual((t, txt), token) |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
23 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
24 def assertNextTokenEqual(self, tok_or_str, txt, tokens): |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
25 self.assertTokenEqual(tok_or_str, txt, next(tokens)) |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
26 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
27 def assertTokenStreamEqual(self, expected_tokens, given_tokens): |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
28 for tok, txt in expected_tokens: |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
29 self.assertNextTokenEqual(tok, txt, given_tokens) |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
30 |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
31 def assertTokenStreamEqualComplete(self, expected_tokens, given_tokens): |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
32 self.assertTokenStreamEqual(expected_tokens, given_tokens) |
|
859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
33 self.assertRaises(StopIteration, next, given_tokens) |
