summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-03-16 19:24:23 +0100
committerGeorg Brandl <georg@python.org>2014-03-16 19:24:23 +0100
commit37f118ebedd03947ba5b04dcd9ba21269cfa3a88 (patch)
tree3bb01557dc71cd63c95e639752591234bd09ee33
parent2c2685b93bf0bf61216c36343d081f9f5bee0be2 (diff)
parent5d7d06c133a6eb1a613171d0477931560b0d6d21 (diff)
downloadpygments-37f118ebedd03947ba5b04dcd9ba21269cfa3a88.tar.gz
merge
-rw-r--r--pygments/lexers/__init__.py3
-rw-r--r--tests/test_basic_api.py9
2 files changed, 11 insertions, 1 deletions
diff --git a/pygments/lexers/__init__.py b/pygments/lexers/__init__.py
index 7bcf3bf0..caedd479 100644
--- a/pygments/lexers/__init__.py
+++ b/pygments/lexers/__init__.py
@@ -82,6 +82,9 @@ def get_lexer_by_name(_alias, **options):
"""
Get a lexer by an alias.
"""
+ if not _alias:
+ raise ClassNotFound('no lexer for alias %r found' % _alias)
+
# lookup builtin lexers
for module_name, name, aliases, _, _ in itervalues(LEXERS):
if _alias.lower() in aliases:
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py
index e89b5c31..be7a4747 100644
--- a/tests/test_basic_api.py
+++ b/tests/test_basic_api.py
@@ -16,7 +16,7 @@ from pygments import lexers, formatters, filters, format
from pygments.token import _TokenType, Text
from pygments.lexer import RegexLexer
from pygments.formatters.img import FontNotFound
-from pygments.util import text_type, StringIO, xrange
+from pygments.util import text_type, StringIO, xrange, ClassNotFound
import support
@@ -138,6 +138,13 @@ def test_get_lexers():
for mimetype in mimetypes:
assert cls == lexers.get_lexer_for_mimetype(mimetype).__class__.__name__
+ try:
+ lexers.get_lexer_by_name(None)
+ except ClassNotFound:
+ pass
+ else:
+ raise Exception
+
def test_formatter_public_api():
ts = list(lexers.PythonLexer().get_tokens("def f(): pass"))