<s> """<STR_LIT>""" <EOL> from pygments . lexer import RegexLexer <EOL> from pygments . token import Text , Name <EOL> from pygments . filters import ErrorToken <EOL> from pygments . formatters . html import HtmlFormatter <EOL> from sphinx . highlighting import PygmentsBridge <EOL> from util import with_app <EOL> class MyLexer ( RegexLexer ) : <EOL> name = '<STR_LIT>' <EOL> tokens = { <EOL> '<STR_LIT:root>' : [ <EOL> ( '<STR_LIT:a>' , Name ) , <EOL> ( '<STR_LIT:b>' , Text ) , <EOL> ] , <EOL> } <EOL> class MyFormatter ( HtmlFormatter ) : <EOL> def format ( self , tokensource , outfile ) : <EOL> for tok in tokensource : <EOL> outfile . write ( tok [ <NUM_LIT:1> ] ) <EOL> class ComplainOnUnhighlighted ( PygmentsBridge ) : <EOL> def unhighlighted ( self , source ) : <EOL> raise AssertionError ( "<STR_LIT>" % source ) <EOL> @ with_app ( ) <EOL> def test_add_lexer ( app , status , warning ) : <EOL> app . add_lexer ( '<STR_LIT:test>' , MyLexer ( ) ) <EOL> bridge = PygmentsBridge ( '<STR_LIT:html>' ) <EOL> ret = bridge . highlight_block ( '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> assert '<STR_LIT>' in ret <EOL> def test_detect_interactive ( ) : <EOL> bridge = ComplainOnUnhighlighted ( '<STR_LIT:html>' ) <EOL> blocks = [ <EOL> """<STR_LIT>""" , <EOL> ] <EOL> for block in blocks : <EOL> ret = bridge . highlight_block ( block . lstrip ( ) , '<STR_LIT>' ) <EOL> assert ret . startswith ( "<STR_LIT>" ) <EOL> def test_lexer_options ( ) : <EOL> bridge = PygmentsBridge ( '<STR_LIT:html>' ) <EOL> ret = bridge . highlight_block ( '<STR_LIT>' , '<STR_LIT>' , opts = { '<STR_LIT>' : True } ) <EOL> assert '<STR_LIT>' in ret <EOL> def test_set_formatter ( ) : <EOL> PygmentsBridge . html_formatter = MyFormatter <EOL> try : <EOL> bridge = PygmentsBridge ( '<STR_LIT:html>' ) <EOL> ret = bridge . highlight_block ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert ret == '<STR_LIT>' <EOL> finally : <EOL> PygmentsBridge . html_formatter = HtmlFormatter <EOL> def test_trim_doctest_flags ( ) : <EOL> PygmentsBridge . html_formatter = MyFormatter <EOL> try : <EOL> bridge = PygmentsBridge ( '<STR_LIT:html>' , trim_doctest_flags = True ) <EOL> ret = bridge . highlight_block ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert ret == '<STR_LIT>' <EOL> finally : <EOL> PygmentsBridge . html_formatter = HtmlFormatter <EOL> def test_default_highlight ( ) : <EOL> bridge = PygmentsBridge ( '<STR_LIT:html>' ) <EOL> ret = bridge . highlight_block ( '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> assert ret == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ret = bridge . highlight_block ( '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> assert ret == '<STR_LIT>' <EOL> ret = bridge . highlight_block ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert ret == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> try : <EOL> ret = bridge . highlight_block ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert False , "<STR_LIT>" <EOL> except ErrorToken : <EOL> pass </s>
