77from celery .tests .utils import sleepdeprived , execute_context
88from celery .tests .utils import mask_modules
99
10- class TestChunks (unittest .TestCase ):
10+ class test_chunks (unittest .TestCase ):
1111
1212 def test_chunks (self ):
1313
@@ -27,7 +27,7 @@ def test_chunks(self):
2727 [[0 , 1 ], [2 , 3 ], [4 , 5 ], [6 , 7 ], [8 , 9 ]])
2828
2929
30- class TestGenUniqueId (unittest .TestCase ):
30+ class test_gen_unique_id (unittest .TestCase ):
3131
3232 def test_gen_unique_id_without_ctypes (self ):
3333 old_utils = sys .modules .pop ("celery.utils" )
@@ -47,7 +47,7 @@ def with_ctypes_masked(_val):
4747 sys .modules ["celery.utils" ] = old_utils
4848
4949
50- class TestDivUtils (unittest .TestCase ):
50+ class test_utils (unittest .TestCase ):
5151
5252 def test_repeatlast (self ):
5353 items = range (6 )
@@ -57,8 +57,50 @@ def test_repeatlast(self):
5757 for j in items :
5858 self .assertEqual (it .next (), i )
5959
60+ def test_get_full_cls_name (self ):
61+ Class = type ("Fox" , (object , ), {"__module__" : "quick.brown" })
62+ self .assertEqual (utils .get_full_cls_name (Class ), "quick.brown.Fox" )
63+
64+ def test_is_iterable (self ):
65+ for a in "f" , ["f" ], ("f" , ), {"f" : "f" }:
66+ self .assertTrue (utils .is_iterable (a ))
67+ for b in object (), 1 :
68+ self .assertFalse (utils .is_iterable (b ))
69+
70+ def test_padlist (self ):
71+ self .assertListEqual (utils .padlist (["George" , "Costanza" , "NYC" ], 3 ),
72+ ["George" , "Costanza" , "NYC" ])
73+ self .assertListEqual (utils .padlist (["George" , "Costanza" ], 3 ),
74+ ["George" , "Costanza" , None ])
75+ self .assertListEqual (utils .padlist (["George" , "Costanza" , "NYC" ], 4 ,
76+ default = "Earth" ),
77+ ["George" , "Costanza" , "NYC" , "Earth" ])
78+
79+ def test_firstmethod_AttributeError (self ):
80+ self .assertIsNone (utils .firstmethod ("foo" )([object ()]))
81+
82+ def test_first (self ):
83+ iterations = [0 ]
84+
85+ def predicate (value ):
86+ iterations [0 ] += 1
87+ if value == 5 :
88+ return True
89+ return False
90+
91+ self .assertEqual (5 , utils .first (predicate , xrange (10 )))
92+ self .assertEqual (iterations [0 ], 6 )
93+
94+ iterations [0 ] = 0
95+ self .assertIsNone (utils .first (predicate , xrange (10 , 20 )))
96+ self .assertEqual (iterations [0 ], 10 )
97+
98+ def test_get_cls_by_name__instance_returns_instance (self ):
99+ instance = object ()
100+ self .assertIs (utils .get_cls_by_name (instance ), instance )
101+
60102
61- class TestRetryOverTime (unittest .TestCase ):
103+ class test_retry_over_time (unittest .TestCase ):
62104
63105 def test_returns_retval_on_success (self ):
64106
0 commit comments