test_highlight.py
65 lines
| 1.9 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
r11481 | """ | ||
Module with tests for Highlight | ||||
""" | ||||
#----------------------------------------------------------------------------- | ||||
# Copyright (c) 2013, the IPython Development Team. | ||||
# | ||||
# Distributed under the terms of the Modified BSD License. | ||||
# | ||||
# The full license is in the file COPYING.txt, distributed with this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
from ...tests.base import TestsBase | ||||
Jonathan Frederic
|
r11928 | from ..highlight import highlight2html, highlight2latex | ||
Jonathan Frederic
|
r11481 | |||
#----------------------------------------------------------------------------- | ||||
# Class | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r11494 | class TestHighlight(TestsBase): | ||
Jonathan Frederic
|
r11481 | """Contains test functions for highlight.py""" | ||
Jonathan Frederic
|
r11906 | #Hello world test, magics test, blank string test | ||
tests = [ | ||||
Jonathan Frederic
|
r11914 | """ | ||
#Hello World Example | ||||
def say(text): | ||||
print(text) | ||||
Jonathan Frederic
|
r11481 | |||
Jonathan Frederic
|
r11914 | say('Hello World!') | ||
""", | ||||
""" | ||||
%%pylab | ||||
plot(x,y, 'r') | ||||
Jonathan Frederic
|
r11918 | """ | ||
Jonathan Frederic
|
r11914 | ] | ||
Jonathan Frederic
|
r11481 | |||
Jonathan Frederic
|
r11914 | tokens = [ | ||
['Hello World Example', 'say', 'text', 'print', 'def'], | ||||
['pylab', 'plot']] | ||||
Jonathan Frederic
|
r11481 | |||
Jonathan Frederic
|
r11906 | |||
def test_highlight2html(self): | ||||
Jonathan Frederic
|
r11934 | """highlight2html test""" | ||
Jonathan Frederic
|
r11906 | for index, test in enumerate(self.tests): | ||
Jonathan Frederic
|
r11936 | yield self._try_highlight(highlight2html, test, self.tokens[index]) | ||
Jonathan Frederic
|
r11906 | |||
def test_highlight2latex(self): | ||||
Jonathan Frederic
|
r11934 | """highlight2latex test""" | ||
Jonathan Frederic
|
r11906 | for index, test in enumerate(self.tests): | ||
Jonathan Frederic
|
r11936 | yield self._try_highlight(highlight2latex, test, self.tokens[index]) | ||
Jonathan Frederic
|
r11906 | |||
Jonathan Frederic
|
r11914 | def _try_highlight(self, method, test, tokens): | ||
Jonathan Frederic
|
r11934 | """Try highlighting source, look for key tokens""" | ||
Jonathan Frederic
|
r11914 | results = method(test) | ||
for token in tokens: | ||||
assert token in results | ||||