<s> import unittest <EOL> import whoosh . analysis as analysis <EOL> import whoosh . highlight as highlight <EOL> class TestHighlighting ( unittest . TestCase ) : <EOL> _doc = u"<STR_LIT>" <EOL> def test_null_fragment ( self ) : <EOL> terms = frozenset ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> sa = analysis . StandardAnalyzer ( ) <EOL> nf = highlight . NullFragmenter <EOL> uc = highlight . UppercaseFormatter ( ) <EOL> htext = highlight . highlight ( self . _doc , terms , sa , nf , uc ) <EOL> self . assertEqual ( htext , "<STR_LIT>" ) <EOL> def test_simple_fragment ( self ) : <EOL> terms = frozenset ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> sa = analysis . StandardAnalyzer ( ) <EOL> sf = highlight . SimpleFragmenter ( size = <NUM_LIT:20> ) <EOL> uc = highlight . UppercaseFormatter ( ) <EOL> htext = highlight . highlight ( self . _doc , terms , sa , sf , uc ) <EOL> self . assertEqual ( htext , "<STR_LIT>" ) <EOL> def test_sentence_fragment ( self ) : <EOL> text = u"<STR_LIT>" <EOL> terms = ( "<STR_LIT>" , ) <EOL> sa = analysis . StandardAnalyzer ( stoplist = None ) <EOL> sf = highlight . SentenceFragmenter ( ) <EOL> uc = highlight . UppercaseFormatter ( ) <EOL> htext = highlight . highlight ( text , terms , sa , sf , uc ) <EOL> self . assertEqual ( htext , "<STR_LIT>" ) <EOL> def test_context_fragment ( self ) : <EOL> terms = frozenset ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> sa = analysis . StandardAnalyzer ( ) <EOL> cf = highlight . ContextFragmenter ( terms , surround = <NUM_LIT:6> ) <EOL> uc = highlight . UppercaseFormatter ( ) <EOL> htext = highlight . highlight ( self . _doc , terms , sa , cf , uc ) <EOL> self . assertEqual ( htext , "<STR_LIT>" ) <EOL> def test_html_format ( self ) : <EOL> terms = frozenset ( ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> sa = analysis . StandardAnalyzer ( ) <EOL> cf = highlight . ContextFragmenter ( terms , surround = <NUM_LIT:6> ) <EOL> hf = highlight . HtmlFormatter ( ) <EOL> htext = highlight . highlight ( self . _doc , terms , sa , cf , hf ) <EOL> self . assertEqual ( htext , '<STR_LIT>' ) <EOL> def test_maxclasses ( self ) : <EOL> terms = frozenset ( ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> sa = analysis . StandardAnalyzer ( ) <EOL> cf = highlight . ContextFragmenter ( terms , surround = <NUM_LIT:6> ) <EOL> hf = highlight . HtmlFormatter ( tagname = "<STR_LIT:b>" , termclass = "<STR_LIT:t>" , maxclasses = <NUM_LIT:2> ) <EOL> htext = highlight . highlight ( self . _doc , terms , sa , cf , hf ) <EOL> self . assertEqual ( htext , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
