<s> import unittest <EOL> from blinker . _saferef import safe_ref <EOL> class _Sample1 ( object ) : <EOL> def x ( self ) : <EOL> pass <EOL> def _sample2 ( obj ) : <EOL> pass <EOL> class _Sample3 ( object ) : <EOL> def __call__ ( self , obj ) : <EOL> pass <EOL> class TestSaferef ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> ts = [ ] <EOL> ss = [ ] <EOL> for x in range ( <NUM_LIT:100> ) : <EOL> t = _Sample1 ( ) <EOL> ts . append ( t ) <EOL> s = safe_ref ( t . x , self . _closure ) <EOL> ss . append ( s ) <EOL> ts . append ( _sample2 ) <EOL> ss . append ( safe_ref ( _sample2 , self . _closure ) ) <EOL> for x in range ( <NUM_LIT:30> ) : <EOL> t = _Sample3 ( ) <EOL> ts . append ( t ) <EOL> s = safe_ref ( t , self . _closure ) <EOL> ss . append ( s ) <EOL> self . ts = ts <EOL> self . ss = ss <EOL> self . closure_count = <NUM_LIT:0> <EOL> def tearDown ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . ts <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . ss <EOL> def test_In ( self ) : <EOL> """<STR_LIT>""" <EOL> for t in self . ts [ : <NUM_LIT:50> ] : <EOL> assert safe_ref ( t . x ) in self . ss <EOL> def test_Valid ( self ) : <EOL> """<STR_LIT>""" <EOL> for s in self . ss : <EOL> assert s ( ) <EOL> def test_ShortCircuit ( 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> assert safe_ref ( t . x ) in sd <EOL> else : <EOL> assert safe_ref ( t ) in sd <EOL> def test_Representation ( self ) : <EOL> """<STR_LIT>""" <EOL> repr ( self . ss [ - <NUM_LIT:1> ] ) <EOL> def _closure ( self , ref ) : <EOL> """<STR_LIT>""" <EOL> self . closure_count += <NUM_LIT:1> </s>
