summaryrefslogtreecommitdiff
path: root/tests/test_basic_api.py
diff options
context:
space:
mode:
authorJean Abou-Samra <jean@abou-samra.fr>2022-05-12 08:35:59 +0200
committerGitHub <noreply@github.com>2022-05-12 08:35:59 +0200
commit49c757cab5e4ca80af109581b83a3527df02d29c (patch)
treec6153eb458cc0289f5e538881a6fdbbb60cf688e /tests/test_basic_api.py
parent4d2a285bd14f4dc153360e171bebdc52d1921089 (diff)
downloadpygments-git-49c757cab5e4ca80af109581b83a3527df02d29c.tar.gz
Improve heuristic to warn about passing lexer/formatter class (#2123)
Don't rely on the error message since 'missing 1 required positional argument' can give false positives. Instead, use issubclass().
Diffstat (limited to 'tests/test_basic_api.py')
-rw-r--r--tests/test_basic_api.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py
index 1767572f..62ea4895 100644
--- a/tests/test_basic_api.py
+++ b/tests/test_basic_api.py
@@ -15,6 +15,7 @@ import pytest
from pygments import lexers, formatters, lex, format
from pygments.token import _TokenType, Text
from pygments.lexer import RegexLexer
+from pygments.formatter import Formatter
from pygments.formatters.img import FontNotFound
from pygments.util import ClassNotFound
@@ -250,6 +251,27 @@ def test_bare_class_handler():
else:
assert False, 'nothing raised'
+ # These cases should not trigger this heuristic.
+ class BuggyLexer(RegexLexer):
+ def get_tokens(self, text, extra_argument):
+ pass
+ tokens = {'root': []}
+ try:
+ list(lex('dummy', BuggyLexer()))
+ except TypeError as e:
+ assert 'lex() argument must be a lexer instance' not in str(e)
+ else:
+ assert False, 'no error raised by buggy lexer?'
+
+ class BuggyFormatter(Formatter):
+ def format(self, tokensource, outfile, extra_argument):
+ pass
+ try:
+ format([], BuggyFormatter())
+ except TypeError as e:
+ assert 'format() argument must be a formatter instance' not in str(e)
+ else:
+ assert False, 'no error raised by buggy formatter?'
class TestFilters: