<s> from django . dispatch . saferef import * <EOL> import unittest <EOL> class Test1 ( object ) : <EOL> def x ( self ) : <EOL> pass <EOL> def test2 ( obj ) : <EOL> pass <EOL> class Test2 ( object ) : <EOL> def __call__ ( self , obj ) : <EOL> pass <EOL> class Tester ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> ts = [ ] <EOL> ss = [ ] <EOL> for x in xrange ( <NUM_LIT> ) : <EOL> t = Test1 ( ) <EOL> ts . append ( t ) <EOL> s = safeRef ( t . x , self . _closure ) <EOL> ss . append ( s ) <EOL> ts . append ( test2 ) <EOL> ss . append ( safeRef ( test2 , self . _closure ) ) <EOL> for x in xrange ( <NUM_LIT:30> ) : <EOL> t = Test2 ( ) <EOL> ts . append ( t ) <EOL> s = safeRef ( t , self . _closure ) <EOL> ss . append ( s ) <EOL> self . ts = ts <EOL> self . ss = ss <EOL> self . closureCount = <NUM_LIT:0> <EOL> def tearDown ( self ) : <EOL> del self . ts <EOL> del self . ss <EOL> def testIn ( self ) : <EOL> """<STR_LIT>""" <EOL> for t in self . ts [ : <NUM_LIT:50> ] : <EOL> self . assert_ ( safeRef ( t . x ) in self . ss ) <EOL> def testValid ( self ) : <EOL> """<STR_LIT>""" <EOL> for s in self . ss : <EOL> self . assert_ ( s ( ) ) <EOL> def testShortCircuit ( self ) : <EOL> """<STR_LIT>""" <EOL> sd = { } <EOL> for s in self . ss : <EOL> sd [ s ] = <NUM_LIT:1> <EOL> for t in self . ts : <EOL> if hasattr ( t , '<STR_LIT:x>' ) : <EOL> self . assert_ ( sd . has_key ( safeRef ( t . x ) ) ) <EOL> else : <EOL> self . assert_ ( sd . has_key ( safeRef ( t ) ) ) <EOL> def testRepresentation ( self ) : <EOL> """<STR_LIT>""" <EOL> repr ( self . ss [ - <NUM_LIT:1> ] ) <EOL> def _closure ( self , ref ) : <EOL> """<STR_LIT>""" <EOL> self . closureCount += <NUM_LIT:1> <EOL> def getSuite ( ) : <EOL> return unittest . makeSuite ( Tester , '<STR_LIT:test>' ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
