<s> import sys <EOL> import py <EOL> from py . __ . magic . exprinfo import getmsg , interpret <EOL> def getexcinfo ( exc , obj , * args , ** kwargs ) : <EOL> try : <EOL> obj ( * args , ** kwargs ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except exc : <EOL> return sys . exc_info ( ) <EOL> else : <EOL> raise AssertionError , "<STR_LIT>" % ( <EOL> obj , args , kwargs ) <EOL> def test_assert_exprinfo ( ) : <EOL> def g ( ) : <EOL> a = <NUM_LIT:1> <EOL> b = <NUM_LIT:2> <EOL> assert a == b <EOL> excinfo = getexcinfo ( AssertionError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg == '<STR_LIT>' <EOL> def test_nested_scopes ( ) : <EOL> def g ( ) : <EOL> a = <NUM_LIT:1> <EOL> def h ( ) : <EOL> return a <EOL> b = <NUM_LIT:2> <EOL> assert h ( ) == b <EOL> excinfo = getexcinfo ( AssertionError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg . startswith ( '<STR_LIT>' ) <EOL> def test_nested_scopes_2 ( ) : <EOL> a = <NUM_LIT:1> <EOL> def g ( ) : <EOL> b = <NUM_LIT:2> <EOL> assert a == b <EOL> excinfo = getexcinfo ( AssertionError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg == '<STR_LIT>' <EOL> def test_assert_func_argument_type_error ( ) : <EOL> def f ( ) : <EOL> pass <EOL> def g ( ) : <EOL> f ( <NUM_LIT:1> ) <EOL> excinfo = getexcinfo ( TypeError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg . find ( "<STR_LIT>" ) != - <NUM_LIT:1> <EOL> class A : <EOL> def f ( ) : <EOL> pass <EOL> def g ( ) : <EOL> A ( ) . f ( ) <EOL> excinfo = getexcinfo ( TypeError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg . find ( "<STR_LIT>" ) != - <NUM_LIT:1> <EOL> def g ( ) : <EOL> A . f ( ) <EOL> excinfo = getexcinfo ( TypeError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg . find ( "<STR_LIT>" ) != - <NUM_LIT:1> <EOL> def global_f ( u = <NUM_LIT:6> , v = <NUM_LIT:7> ) : <EOL> return u * v <EOL> def test_exprinfo_funccall ( ) : <EOL> def g ( ) : <EOL> assert global_f ( ) == <NUM_LIT> <EOL> excinfo = getexcinfo ( AssertionError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg == '<STR_LIT>' <EOL> def test_exprinfo_funccall_keywords ( ) : <EOL> def g ( ) : <EOL> assert global_f ( v = <NUM_LIT:11> ) == <NUM_LIT> <EOL> excinfo = getexcinfo ( AssertionError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg == '<STR_LIT>' <EOL> def test_interpretable_escapes_newlines ( ) : <EOL> class X ( object ) : <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' <EOL> def g ( ) : <EOL> assert X ( ) == '<STR_LIT>' <EOL> excinfo = getexcinfo ( AssertionError , g ) <EOL> msg = getmsg ( excinfo ) <EOL> assert msg == "<STR_LIT>" <EOL> def test_keyboard_interrupt ( ) : <EOL> class DummyCode : <EOL> co_filename = '<STR_LIT>' <EOL> co_firstlineno = <NUM_LIT:0> <EOL> co_name = '<STR_LIT>' <EOL> class DummyFrame : <EOL> f_globals = f_locals = { } <EOL> f_code = DummyCode <EOL> f_lineno = <NUM_LIT:0> <EOL> for exstr in "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" : <EOL> ex = eval ( exstr ) <EOL> try : <EOL> interpret ( "<STR_LIT>" % exstr , py . code . Frame ( DummyFrame ) ) <EOL> except ex : <EOL> pass <EOL> else : <EOL> raise AssertionError , "<STR_LIT>" % ( exstr , ) <EOL> def test_inconsistent_assert_result ( testdir ) : <EOL> p = testdir . makepyfile ( """<STR_LIT>""" ) <EOL> result = testdir . runpytest ( p ) <EOL> s = result . stdout . str ( ) <EOL> assert s . find ( "<STR_LIT>" ) != - <NUM_LIT:1> <EOL> def test_twoarg_comparison_does_not_call_nonzero ( ) : <EOL> class X ( object ) : <EOL> def __eq__ ( self , other ) : <EOL> return self <EOL> def __nonzero__ ( self ) : <EOL> raise ValueError <EOL> def all ( self ) : <EOL> return False <EOL> def f ( ) : <EOL> a = X ( ) <EOL> b = X ( ) <EOL> assert ( a == b ) . all ( ) <EOL> excinfo = getexcinfo ( AssertionError , f ) <EOL> msg = getmsg ( excinfo ) <EOL> print msg <EOL> assert "<STR_LIT>" not in msg <EOL> assert "<STR_LIT>" not in msg </s>
