Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Jan 15, 2025
1 parent 9060d92 commit 42ce358
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions ipython_pygments_lexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@
r"(?s)(\s*)(%%pypy)([^\n]*\n)(.*)",
bygroups(Text, Operator, Text, using(Python3Lexer)),
),
(
r"(?s)(\s*)(%%python)([^\n]*\n)(.*)",
bygroups(Text, Operator, Text, using(Python3Lexer)),
),
(
r"(?s)(\s*)(%%python2)([^\n]*\n)(.*)",
bygroups(Text, Operator, Text, using(Python2Lexer)),
Expand All @@ -127,16 +123,20 @@
r"(?s)(\s*)(%%python3)([^\n]*\n)(.*)",
bygroups(Text, Operator, Text, using(Python3Lexer)),
),
(
r"(?s)(\s*)(%%python)([^\n]*\n)(.*)",
bygroups(Text, Operator, Text, using(Python3Lexer)),
),
(
r"(?s)(\s*)(%%ruby)([^\n]*\n)(.*)",
bygroups(Text, Operator, Text, using(RubyLexer)),
),
(
r"(?s)(\s*)(%%time)([^\n]*\n)(.*)",
r"(?s)(\s*)(%%timeit)([^\n]*\n)(.*)",
bygroups(Text, Operator, Text, using(Python3Lexer)),
),
(
r"(?s)(\s*)(%%timeit)([^\n]*\n)(.*)",
r"(?s)(\s*)(%%time)([^\n]*\n)(.*)",
bygroups(Text, Operator, Text, using(Python3Lexer)),
),
(
Expand Down
20 changes: 10 additions & 10 deletions test_ipython_pygments_lexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

pyg214 = tuple(int(x) for x in pygments_version.split(".")[:2]) >= (2, 14)

TOKEN_WS = Token.Text.Whitespace if pyg214 else Token.Text


class TestLexers(TestCase):
"""Collection of lexers tests"""
Expand Down Expand Up @@ -71,10 +73,8 @@ def testIPythonLexer(self):
(Token.Text, " "),
(Token.Operator, "%"),
(Token.Keyword, "sx"),
(Token.Text, " "),
(TOKEN_WS, " "),
] + bash_tokens[1:]
if tokens_2[7] == (Token.Text, " ") and pyg214: # pygments 2.14+
tokens_2[7] = (Token.Text.Whitespace, " ")
assert tokens_2[:-1] == list(self.lexer.get_tokens(fragment_2))[:-1]

fragment_2 = "f = %R function () {}\n"
Expand Down Expand Up @@ -147,26 +147,26 @@ def testIPythonLexer(self):
(Token.Text, " "),
(Token.Name, "b"),
(Token.Punctuation, ":"),
(Token.Text, "\n"),
(TOKEN_WS, "\n"),
(Token.Text, " "),
(Token.Keyword, "pass"),
(Token.Text, "\n"),
(TOKEN_WS, "\n"),
]
if tokens[10] == (Token.Text, "\n") and pyg214: # pygments 2.14+
tokens[10] = (Token.Text.Whitespace, "\n")
assert tokens[:-1] == list(self.lexer.get_tokens(fragment))[:-1]
assert tokens == list(self.lexer.get_tokens(fragment))

fragment = "%%timeit\nmath.sin(0)"
tokens = [
(Token.Operator, "%%timeit\n"),
(Token.Operator, "%%timeit"),
(Token.Text, "\n"),
(Token.Name, "math"),
(Token.Operator, "."),
(Token.Name, "sin"),
(Token.Punctuation, "("),
(Token.Literal.Number.Integer, "0"),
(Token.Punctuation, ")"),
(Token.Text, "\n"),
(TOKEN_WS, "\n"),
]
assert tokens == list(self.lexer.get_tokens(fragment))

fragment = "%%HTML\n<div>foo</div>"
tokens = [
Expand Down

0 comments on commit 42ce358

Please sign in to comment.