@@ -63,6 +63,41 @@ def test_sleek_ref():
6363 assert counter () == count + 1
6464 assert sleek_ref () is not None
6565
66+ def test_cute_sleek_value_dictionary_one_by_one ():
67+ volatile_things = [A (), 1 , 4.5 , 'meow' , u'woof' , [1 , 2 ], (1 , 2 ), {1 : 2 },
68+ set ([1 , 2 , 3 ])]
69+ unvolatile_things = [A .s , __builtins__ , list , type , list .append , str .join ,
70+ sum ]
71+
72+ # Using len(csvd) as our key; Just to guarantee we're not running over an
73+ # existing key.
74+
75+ while volatile_things :
76+ volatile_thing = volatile_things .pop ()
77+ csvd = CuteSleekValueDictionary (counter )
78+ if _is_weakreffable (volatile_thing ):
79+ csvd [len (csvd )] = volatile_thing
80+ count = counter ()
81+ del volatile_thing
82+ gc .collect ()
83+ assert counter () == count + 2
84+ else :
85+ csvd [len (csvd )] = volatile_thing
86+ count = counter ()
87+ del volatile_thing
88+ gc .collect ()
89+ assert counter () == count + 1
90+
91+ while unvolatile_things :
92+ unvolatile_thing = unvolatile_things .pop ()
93+ csvd = CuteSleekValueDictionary (counter )
94+
95+ csvd [len (csvd )] = unvolatile_thing
96+ count = counter ()
97+ del unvolatile_thing
98+ gc .collect ()
99+ assert counter () == count + 1
100+
66101def test_cute_sleek_value_dictionary ():
67102 volatile_things = [A (), 1 , 4.5 , 'meow' , u'woof' , [1 , 2 ], (1 , 2 ), {1 : 2 },
68103 set ([1 , 2 , 3 ])]
0 commit comments