<s> from pypy . rpython . ootypesystem . ootype import ROOT , Instance , addMethods , meth , Meth , Void <EOL> from pypy . translator . backendopt . checkvirtual import check_virtual_methods <EOL> def test_nonvirtual ( ) : <EOL> A = Instance ( "<STR_LIT:A>" , ROOT ) <EOL> addMethods ( A , { "<STR_LIT:foo>" : meth ( Meth ( [ ] , Void ) ) } ) <EOL> check_virtual_methods ( ) <EOL> assert A . _methods [ "<STR_LIT:foo>" ] . _virtual == False <EOL> def test_checkvirtual_simple ( ) : <EOL> A = Instance ( "<STR_LIT:A>" , ROOT ) <EOL> B = Instance ( "<STR_LIT:B>" , A ) <EOL> addMethods ( A , { "<STR_LIT:foo>" : meth ( Meth ( [ ] , Void ) ) , <EOL> "<STR_LIT:bar>" : meth ( Meth ( [ ] , Void ) ) } ) <EOL> addMethods ( B , { "<STR_LIT:foo>" : meth ( Meth ( [ ] , Void ) ) } ) <EOL> check_virtual_methods ( ) <EOL> assert A . _methods [ "<STR_LIT:foo>" ] . _virtual == True <EOL> assert A . _methods [ "<STR_LIT:bar>" ] . _virtual == False <EOL> assert B . _methods [ "<STR_LIT:foo>" ] . _virtual == False <EOL> def test_checkvirtual_deep ( ) : <EOL> A = Instance ( "<STR_LIT:A>" , ROOT ) <EOL> B = Instance ( "<STR_LIT:B>" , A ) <EOL> C = Instance ( "<STR_LIT:C>" , B ) <EOL> addMethods ( A , { "<STR_LIT:foo>" : meth ( Meth ( [ ] , Void ) ) , <EOL> "<STR_LIT:bar>" : meth ( Meth ( [ ] , Void ) ) } ) <EOL> addMethods ( C , { "<STR_LIT:foo>" : meth ( Meth ( [ ] , Void ) ) } ) <EOL> check_virtual_methods ( ) <EOL> assert A . _methods [ "<STR_LIT:foo>" ] . _virtual == True <EOL> assert A . _methods [ "<STR_LIT:bar>" ] . _virtual == False <EOL> assert "<STR_LIT:foo>" not in B . _methods <EOL> assert C . _methods [ "<STR_LIT:foo>" ] . _virtual == False <EOL> def test_checkvirtual_brother ( ) : <EOL> A = Instance ( "<STR_LIT:A>" , ROOT ) <EOL> B1 = Instance ( "<STR_LIT>" , A ) <EOL> B2 = Instance ( "<STR_LIT>" , A ) <EOL> addMethods ( A , { "<STR_LIT:foo>" : meth ( Meth ( [ ] , Void ) ) , <EOL> "<STR_LIT:bar>" : meth ( Meth ( [ ] , Void ) ) } ) <EOL> addMethods ( B1 , { "<STR_LIT:foo>" : meth ( Meth ( [ ] , Void ) ) } ) <EOL> check_virtual_methods ( ) <EOL> assert A . _methods [ "<STR_LIT:foo>" ] . _virtual == True <EOL> assert A . _methods [ "<STR_LIT:bar>" ] . _virtual == False <EOL> assert B1 . _methods [ "<STR_LIT:foo>" ] . _virtual == False <EOL> assert "<STR_LIT:foo>" not in B2 . _methods </s>
