<s> from paste . exceptions import formatter <EOL> from paste . exceptions import collector <EOL> import sys <EOL> import os <EOL> import difflib <EOL> class Mock ( object ) : <EOL> def __init__ ( self , ** kw ) : <EOL> for name , value in kw . items ( ) : <EOL> setattr ( self , name , value ) <EOL> class Supplement ( Mock ) : <EOL> object = '<STR_LIT>' <EOL> source_url = '<STR_LIT>' <EOL> info = '<STR_LIT>' <EOL> args = ( ) <EOL> def getInfo ( self ) : <EOL> return self . info <EOL> def __call__ ( self , * args ) : <EOL> self . args = args <EOL> return self <EOL> class BadSupplement ( Supplement ) : <EOL> def getInfo ( self ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def call_error ( sup ) : <EOL> <NUM_LIT:1> + <NUM_LIT:2> <EOL> __traceback_supplement__ = ( sup , ( ) ) <EOL> assert <NUM_LIT:0> , "<STR_LIT>" <EOL> def raise_error ( sup = '<STR_LIT:default>' ) : <EOL> if sup == '<STR_LIT:default>' : <EOL> sup = Supplement ( ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> __traceback_info__ = i <EOL> if i == <NUM_LIT:5> : <EOL> call_error ( sup = sup ) <EOL> def hide ( t , inner , * args , ** kw ) : <EOL> __traceback_hide__ = t <EOL> return inner ( * args , ** kw ) <EOL> def pass_through ( info , inner , * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> __traceback_info__ = info <EOL> return inner ( * args , ** kw ) <EOL> def format ( type = '<STR_LIT:html>' , ** ops ) : <EOL> data = collector . collect_exception ( * sys . exc_info ( ) ) <EOL> report = getattr ( formatter , '<STR_LIT>' + type ) ( data , ** ops ) <EOL> return report <EOL> formats = ( '<STR_LIT:text>' , '<STR_LIT:html>' ) <EOL> def test_excersize ( ) : <EOL> for f in formats : <EOL> try : <EOL> raise_error ( ) <EOL> except : <EOL> format ( f ) <EOL> def test_content ( ) : <EOL> for f in formats : <EOL> try : <EOL> raise_error ( ) <EOL> except : <EOL> result = format ( f ) <EOL> print ( result ) <EOL> assert '<STR_LIT>' in result <EOL> assert '<STR_LIT>' in result <EOL> assert '<STR_LIT>' in result <EOL> assert '<STR_LIT>' in result <EOL> assert '<STR_LIT>' in result <EOL> assert '<STR_LIT:5>' in result <EOL> assert '<STR_LIT>' in result <EOL> else : <EOL> assert <NUM_LIT:0> <EOL> def test_trim ( ) : <EOL> current = os . path . abspath ( os . getcwd ( ) ) <EOL> for f in formats : <EOL> try : <EOL> raise_error ( ) <EOL> except : <EOL> result = format ( f , trim_source_paths = [ ( current , '<STR_LIT:.>' ) ] ) <EOL> assert current not in result <EOL> assert ( '<STR_LIT>' % os . sep ) in result , ValueError ( repr ( result ) ) <EOL> else : <EOL> assert <NUM_LIT:0> <EOL> def test_hide ( ) : <EOL> for f in formats : <EOL> try : <EOL> hide ( True , raise_error ) <EOL> except : <EOL> result = format ( f ) <EOL> print ( result ) <EOL> assert '<STR_LIT>' not in result <EOL> assert '<STR_LIT>' not in result <EOL> else : <EOL> assert <NUM_LIT:0> <EOL> def print_diff ( s1 , s2 ) : <EOL> differ = difflib . Differ ( ) <EOL> result = list ( differ . compare ( s1 . splitlines ( ) , s2 . splitlines ( ) ) ) <EOL> print ( '<STR_LIT:\n>' . join ( result ) ) <EOL> def test_hide_supppressed ( ) : <EOL> """<STR_LIT>""" <EOL> for f in [ '<STR_LIT:html>' ] : <EOL> results = [ ] <EOL> for hide_value in ( False , '<STR_LIT>' ) : <EOL> try : <EOL> pass_through ( <EOL> '<STR_LIT:a>' , <EOL> hide , <EOL> hide_value , <EOL> pass_through , <EOL> '<STR_LIT:b>' , <EOL> raise_error ) <EOL> except : <EOL> results . append ( format ( f ) ) <EOL> else : <EOL> assert <NUM_LIT:0> <EOL> if results [ <NUM_LIT:0> ] != results [ <NUM_LIT:1> ] : <EOL> print_diff ( results [ <NUM_LIT:0> ] , results [ <NUM_LIT:1> ] ) <EOL> assert <NUM_LIT:0> <EOL> def test_hide_after ( ) : <EOL> for f in formats : <EOL> try : <EOL> pass_through ( <EOL> '<STR_LIT>' , <EOL> hide , '<STR_LIT>' , <EOL> pass_through , '<STR_LIT>' , <EOL> hide , '<STR_LIT>' , <EOL> raise_error ) <EOL> except : <EOL> result = format ( f ) <EOL> assert '<STR_LIT>' in result <EOL> assert '<STR_LIT>' not in result <EOL> assert '<STR_LIT>' in result <EOL> else : <EOL> assert <NUM_LIT:0> <EOL> def test_hide_before ( ) : <EOL> for f in formats : <EOL> try : <EOL> pass_through ( <EOL> '<STR_LIT>' , <EOL> hide , '<STR_LIT>' , <EOL> raise_error ) <EOL> except : <EOL> result = format ( f ) <EOL> print ( result ) <EOL> assert '<STR_LIT>' not in result <EOL> assert '<STR_LIT>' in result <EOL> else : <EOL> assert <NUM_LIT:0> <EOL> def test_make_wrappable ( ) : <EOL> assert '<STR_LIT>' in formatter . make_wrappable ( '<STR_LIT:x>' * <NUM_LIT:1000> ) <EOL> formatter . make_wrappable ( '<STR_LIT:;>' * <NUM_LIT> ) <EOL> assert ( formatter . make_wrappable ( '<STR_LIT>' ) <EOL> == '<STR_LIT>' ) <EOL> assert ( formatter . make_wrappable ( '<STR_LIT>' + ( '<STR_LIT:x>' * <NUM_LIT:50> ) + '<STR_LIT:;>' + ( '<STR_LIT:y>' * <NUM_LIT:50> ) + '<STR_LIT>' ) <EOL> == '<STR_LIT>' + ( '<STR_LIT:x>' * <NUM_LIT:50> ) + '<STR_LIT>' + ( '<STR_LIT:y>' * <NUM_LIT:50> ) + '<STR_LIT>' ) </s>
