<s> from __future__ import division <EOL> from __future__ import unicode_literals <EOL> import re <EOL> from bs4 import BeautifulSoup <EOL> from django . contrib . auth . models import AnonymousUser <EOL> from django . test import RequestFactory <EOL> from tri . table import render_table <EOL> def reindent ( s , before = "<STR_LIT:U+0020>" , after = "<STR_LIT:U+0020>" ) : <EOL> def reindent_line ( line ) : <EOL> m = re . match ( r'<STR_LIT>' + re . escape ( before ) + r'<STR_LIT>' , line ) <EOL> return after * ( len ( m . group ( <NUM_LIT:1> ) ) // len ( before ) ) + m . group ( <NUM_LIT:3> ) <EOL> return "<STR_LIT:\n>" . join ( reindent_line ( line ) for line in s . splitlines ( ) ) <EOL> def verify_table_html ( expected_html , query = None , find = None , links = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if find is None : <EOL> find = dict ( class_ = '<STR_LIT>' ) <EOL> if not expected_html . strip ( ) : <EOL> expected_html = "<STR_LIT>" <EOL> request = RequestFactory ( ) . get ( "<STR_LIT:/>" , query ) <EOL> request . user = AnonymousUser ( ) <EOL> actual_html = render_table ( request = request , links = links , ** kwargs ) <EOL> prettified_actual = reindent ( BeautifulSoup ( actual_html ) . find ( ** find ) . prettify ( ) ) . strip ( ) <EOL> prettified_expected = reindent ( BeautifulSoup ( expected_html ) . find ( ** find ) . prettify ( ) ) . strip ( ) <EOL> assert prettified_expected == prettified_actual </s>
