<s> import os <EOL> import unittest <EOL> from genshi . core import Stream <EOL> from genshi . input import HTMLParser , XML <EOL> from trac . mimeview . api import Mimeview <EOL> from trac . mimeview . patch import PatchRenderer <EOL> from trac . test import EnvironmentStub , MockRequest <EOL> from trac . web . chrome import Chrome , web_context <EOL> class PatchRendererTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> env = EnvironmentStub ( enable = [ Chrome , PatchRenderer ] ) <EOL> req = MockRequest ( env ) <EOL> self . context = web_context ( req ) <EOL> self . patch = Mimeview ( env ) . renderers [ <NUM_LIT:0> ] <EOL> patch_html = open ( os . path . join ( os . path . split ( __file__ ) [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' ) ) <EOL> self . patch_html = Stream ( list ( HTMLParser ( patch_html , encoding = '<STR_LIT:utf-8>' ) ) ) <EOL> def _expected ( self , expected_id ) : <EOL> return self . patch_html . select ( '<STR_LIT>' % expected_id ) <EOL> def _test ( self , expected_id , result ) : <EOL> expected = self . _expected ( expected_id ) . render ( encoding = '<STR_LIT:utf-8>' ) <EOL> result = XML ( result . render ( encoding = '<STR_LIT:utf-8>' ) ) . render ( encoding = '<STR_LIT:utf-8>' ) <EOL> expected , result = expected . splitlines ( ) , result . splitlines ( ) <EOL> for exp , res in zip ( expected , result ) : <EOL> self . assertEqual ( exp , res ) <EOL> self . assertEqual ( len ( expected ) , len ( result ) ) <EOL> def test_simple ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . patch . render ( self . context , None , """<STR_LIT>""" ) <EOL> self . assertTrue ( result ) <EOL> self . _test ( '<STR_LIT>' , result ) <EOL> def test_no_newline_in_base ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . patch . render ( self . context , None , """<STR_LIT>""" ) <EOL> self . assertTrue ( result ) <EOL> self . _test ( '<STR_LIT>' , result ) <EOL> def test_no_newline_in_changed ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . patch . render ( self . context , None , """<STR_LIT>""" ) <EOL> self . assertTrue ( result ) <EOL> self . _test ( '<STR_LIT>' , result ) <EOL> def test_diff_to_hdf_expandtabs ( self ) : <EOL> """<STR_LIT>""" <EOL> changes = self . patch . _diff_to_hdf ( <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <NUM_LIT:8> ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> str ( changes [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> str ( changes [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) ) <EOL> def test_diff_to_hdf_leading_ws ( self ) : <EOL> """<STR_LIT>""" <EOL> changes = self . patch . _diff_to_hdf ( <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <NUM_LIT:8> ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> str ( changes [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> str ( changes [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( PatchRendererTestCase ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
