Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison tests/_testhelper.py @ 18:859ab8abce0a
The first real tests about lexing with the Pygments API for the tests.
Also implemented a simple helper to compare token streams with shorter code.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 20 Apr 2026 14:12:35 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 17:251898f2f0c7 | 18:859ab8abce0a |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 # :- | |
| 3 # SPDX-FileCopyrightText: © 2026 Franz Glasner | |
| 4 # SPDX-License-Identifier: MIT | |
| 5 # :- | |
| 6 """Test helper""" | |
| 7 | |
| 8 __all__ = ["TokenAssertHelper"] | |
| 9 | |
| 10 | |
| 11 from pygments.token import Token, is_token_subtype, string_to_tokentype | |
| 12 | |
| 13 | |
| 14 class TokenAssertHelper(object): | |
| 15 """Mixin to test for token stream equality""" | |
| 16 | |
| 17 def assertTokenEqual(self, tok_or_str, txt, token): | |
| 18 if is_token_subtype(tok_or_str, Token): | |
| 19 t = tok_or_str | |
| 20 else: | |
| 21 t = string_to_tokentype(tok_or_str) | |
| 22 self.assertEqual((t, txt), token) | |
| 23 | |
| 24 def assertNextTokenEqual(self, tok_or_str, txt, tokens): | |
| 25 self.assertTokenEqual(tok_or_str, txt, next(tokens)) | |
| 26 | |
| 27 def assertTokenStreamEqual(self, expected_tokens, given_tokens): | |
| 28 for tok, txt in expected_tokens: | |
| 29 self.assertNextTokenEqual(tok, txt, given_tokens) | |
| 30 | |
| 31 def assertTokenStreamEqualComplete(self, expected_tokens, given_tokens): | |
| 32 self.assertTokenStreamEqual(expected_tokens, given_tokens) | |
| 33 self.assertRaises(StopIteration, next, given_tokens) |
