<s> import gc <EOL> import unittest <EOL> from markupsafe import Markup , escape , escape_silent <EOL> class MarkupTestCase ( unittest . TestCase ) : <EOL> def test_markup_operations ( self ) : <EOL> unsafe = '<STR_LIT>' <EOL> safe = Markup ( '<STR_LIT>' ) <EOL> assert unsafe + safe == unicode ( escape ( unsafe ) ) + unicode ( safe ) <EOL> assert Markup ( '<STR_LIT>' ) % '<STR_LIT>' == '<STR_LIT>' <EOL> assert Markup ( '<STR_LIT>' ) % { <EOL> '<STR_LIT:username>' : '<STR_LIT>' <EOL> } == '<STR_LIT>' <EOL> assert type ( Markup ( '<STR_LIT:foo>' ) + '<STR_LIT:bar>' ) is Markup <EOL> x = Markup ( "<STR_LIT:foo>" ) <EOL> assert x . __html__ ( ) is x <EOL> class Foo ( object ) : <EOL> def __html__ ( self ) : <EOL> return '<STR_LIT>' <EOL> def __unicode__ ( self ) : <EOL> return '<STR_LIT>' <EOL> assert Markup ( Foo ( ) ) == '<STR_LIT>' <EOL> assert Markup ( '<STR_LIT>' ) % Foo ( ) == '<STR_LIT>' <EOL> assert escape ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert Markup ( "<STR_LIT>" ) . striptags ( ) == "<STR_LIT>" <EOL> assert Markup ( "<STR_LIT>" ) . unescape ( ) == "<STR_LIT>" <EOL> def test_all_set ( self ) : <EOL> import markupsafe as markup <EOL> for item in markup . __all__ : <EOL> getattr ( markup , item ) <EOL> def test_escape_silent ( self ) : <EOL> assert escape_silent ( None ) == Markup ( ) <EOL> assert escape ( None ) == Markup ( None ) <EOL> assert escape_silent ( '<STR_LIT>' ) == Markup ( u'<STR_LIT>' ) <EOL> class MarkupLeakTestCase ( unittest . TestCase ) : <EOL> def test_markup_leaks ( self ) : <EOL> counts = set ( ) <EOL> for count in xrange ( <NUM_LIT:20> ) : <EOL> for item in xrange ( <NUM_LIT:1000> ) : <EOL> escape ( "<STR_LIT:foo>" ) <EOL> escape ( "<STR_LIT>" ) <EOL> escape ( u"<STR_LIT:foo>" ) <EOL> escape ( u"<STR_LIT>" ) <EOL> counts . add ( len ( gc . get_objects ( ) ) ) <EOL> assert len ( counts ) == <NUM_LIT:1> , '<STR_LIT>' <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( MarkupTestCase ) ) <EOL> if not hasattr ( escape , '<STR_LIT>' ) : <EOL> suite . addTest ( unittest . makeSuite ( MarkupLeakTestCase ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
