PageRenderTime 247ms CodeModel.GetById 60ms app.highlight 127ms RepoModel.GetById 54ms app.codeStats 0ms

/examples/libtest/ArgsTest.py

http://pyjamas.googlecode.com/
Python | 584 lines | 465 code | 119 blank | 0 comment | 0 complexity | 27c2cd705f338f71b2a3175d7d28ec55 MD5 | raw file
  1from UnitTest import UnitTest
  2
  3class ArgsTest(UnitTest):
  4    def __init__(self):
  5        UnitTest.__init__(self)
  6
  7    def getName(self):
  8        return "Args"
  9 
 10    def testSimpleCall(self):
 11        values = foo(1, 2, 3)
 12        self.assertEquals(values[0], 1)
 13        self.assertEquals(values[1], 2)
 14        self.assertEquals(values[2], 3)
 15        
 16        values = foo2(1, 2, 3)
 17        self.assertEquals(values[0], 1)
 18        self.assertEquals(values[1], 2)
 19        self.assertEquals(values[2], 3)
 20
 21    def testKeywordCall(self):
 22        values = foo2(c=3, b=2, a=1)
 23        self.assertEquals(values[0], 1)
 24        self.assertEquals(values[1], 2)
 25        self.assertEquals(values[2], 3)
 26        
 27        values = foo2(b=2, a=1, c=3)
 28        self.assertEquals(values[0], 1)
 29        self.assertEquals(values[1], 2)
 30        self.assertEquals(values[2], 3)
 31        
 32        values = foo2()
 33        self.assertEquals(values[0], None)
 34        self.assertEquals(values[1], None)
 35        self.assertEquals(values[2], None)
 36
 37        values = foo2(c=True)
 38        self.assertEquals(values[0], None)
 39        self.assertEquals(values[1], None)
 40        self.assertEquals(values[2], True)
 41        
 42        
 43    def testDefaultValuesCall(self):
 44        values = foo3(b=7)
 45        self.assertEquals(values[0], 1)
 46        self.assertEquals(values[1], 7)
 47        self.assertEquals(values[2], 3)
 48        
 49        values = foo3(a=9)
 50        self.assertEquals(values[0], 9)
 51        self.assertEquals(values[1], 2)
 52        self.assertEquals(values[2], 3)
 53        
 54        values = foo3()
 55        self.assertEquals(values[0], 1)
 56        self.assertEquals(values[1], 2)
 57        self.assertEquals(values[2], 3)
 58    
 59    def testVarargsCall(self):
 60        values = foo4(9, 8, 7, 2, 3, 4)
 61        self.assertEquals(values[0], 9)
 62        self.assertEquals(values[1], 8)
 63        self.assertEquals(values[2], 7)
 64        self.assertEquals(values[3][0], 2)
 65        self.assertEquals(values[3][1], 3)
 66        self.assertEquals(values[3][2], 4)
 67        
 68        values = foo4(9, 8, 7, 3, 2, 1)
 69        self.assertEquals(values[0], 9)
 70        self.assertEquals(values[1], 8)
 71        self.assertEquals(values[2], 7)
 72        self.assertEquals(values[3][0], 3)
 73        self.assertEquals(values[3][1], 2)
 74        self.assertEquals(values[3][2], 1)
 75    
 76    def testKwargsCall(self):
 77        values = foo5(9, 8, 7, x=5, y=7)
 78        self.assertEquals(values[0], 9)
 79        self.assertEquals(values[1], 8)
 80        self.assertEquals(values[2], 7)
 81        self.assertEquals(values[3]["x"], 5)
 82        self.assertEquals(values[3]["y"], 7)
 83
 84    def testComboCall(self):
 85        values = foo6(9, 8, 7, 1, 2, 3, x=4, y=5)
 86        self.assertEquals(values[0], 9)
 87        self.assertEquals(values[1], 8)
 88        self.assertEquals(values[2], 7)
 89        self.assertEquals(values[3][0], 1)
 90        self.assertEquals(values[3][1], 2)
 91        self.assertEquals(values[3][2], 3)
 92        self.assertEquals(values[4]["x"], 4)
 93        self.assertEquals(values[4]["y"], 5)
 94        
 95    def testSimpleCtorCall(self):
 96        values = ArgsTestClass_foo(1, 2, 3).x
 97        self.assertEquals(values[0], 1)
 98        self.assertEquals(values[1], 2)
 99        self.assertEquals(values[2], 3)
100        
101        values = ArgsTestClass_foo2(1, 2, 3).x
102        self.assertEquals(values[0], 1)
103        self.assertEquals(values[1], 2)
104        self.assertEquals(values[2], 3)
105
106    def testKeywordCtorCall(self):
107        values = ArgsTestClass_foo2(c=3, b=2, a=1).x
108        self.assertEquals(values[0], 1)
109        self.assertEquals(values[1], 2)
110        self.assertEquals(values[2], 3)
111        
112        values = ArgsTestClass_foo2(b=2, a=1, c=3).x
113        self.assertEquals(values[0], 1)
114        self.assertEquals(values[1], 2)
115        self.assertEquals(values[2], 3)
116        
117        values = ArgsTestClass_foo2().x
118        self.assertEquals(values[0], None)
119        self.assertEquals(values[1], None)
120        self.assertEquals(values[2], None)
121
122        values = ArgsTestClass_foo2(c=True).x
123        self.assertEquals(values[0], None)
124        self.assertEquals(values[1], None)
125        self.assertEquals(values[2], True)
126        
127        
128    def testDefaultValuesCtorCall(self):
129        values = ArgsTestClass_foo3(b=7).x
130        self.assertEquals(values[0], 1)
131        self.assertEquals(values[1], 7)
132        self.assertEquals(values[2], 3)
133        
134        values = ArgsTestClass_foo3(a=9).x
135        self.assertEquals(values[0], 9)
136        self.assertEquals(values[1], 2)
137        self.assertEquals(values[2], 3)
138        
139        values = ArgsTestClass_foo3().x
140        self.assertEquals(values[0], 1)
141        self.assertEquals(values[1], 2)
142        self.assertEquals(values[2], 3)
143    
144    def testVarargsCtorCall(self):
145        values = ArgsTestClass_foo4(9, 8, 7, 2, 3, 4).x
146        self.assertEquals(values[0], 9)
147        self.assertEquals(values[1], 8)
148        self.assertEquals(values[2], 7)
149        self.assertEquals(values[3][0], 2)
150        self.assertEquals(values[3][1], 3)
151        self.assertEquals(values[3][2], 4)
152        
153        values = ArgsTestClass_foo4(9, 8, 7, 3, 2, 1).x
154        self.assertEquals(values[0], 9)
155        self.assertEquals(values[1], 8)
156        self.assertEquals(values[2], 7)
157        self.assertEquals(values[3][0], 3)
158        self.assertEquals(values[3][1], 2)
159        self.assertEquals(values[3][2], 1)
160    
161    def testKwargsCtorCall(self):
162        values = ArgsTestClass_foo5(9, 8, 7, x=5, y=7).x
163        self.assertEquals(values[0], 9)
164        self.assertEquals(values[1], 8)
165        self.assertEquals(values[2], 7)
166        self.assertEquals(values[3]["x"], 5)
167        self.assertEquals(values[3]["y"], 7)
168
169    def testComboCtorCall(self):
170        values = ArgsTestClass_foo6(9, 8, 7, 1, 2, 3, x=4, y=5).x
171        self.assertEquals(values[0], 9)
172        self.assertEquals(values[1], 8)
173        self.assertEquals(values[2], 7)
174        self.assertEquals(values[3][0], 1)
175        self.assertEquals(values[3][1], 2)
176        self.assertEquals(values[3][2], 3)
177        self.assertEquals(values[4]["x"], 4)
178        self.assertEquals(values[4]["y"], 5)
179        
180    def testSimpleMethodCall(self):
181        values = ArgsTestClass().foo(1, 2, 3)
182        self.assertEquals(values[0], 1)
183        self.assertEquals(values[1], 2)
184        self.assertEquals(values[2], 3)
185        
186        values = ArgsTestClass().foo2(1, 2, 3)
187        self.assertEquals(values[0], 1)
188        self.assertEquals(values[1], 2)
189        self.assertEquals(values[2], 3)
190
191    def testKeywordMethodCall(self):
192        values = ArgsTestClass().foo2(c=3, b=2, a=1)
193        self.assertEquals(values[0], 1)
194        self.assertEquals(values[1], 2)
195        self.assertEquals(values[2], 3)
196        
197        values = ArgsTestClass().foo2(b=2, a=1, c=3)
198        self.assertEquals(values[0], 1)
199        self.assertEquals(values[1], 2)
200        self.assertEquals(values[2], 3)
201        
202        values = ArgsTestClass().foo2()
203        self.assertEquals(values[0], None)
204        self.assertEquals(values[1], None)
205        self.assertEquals(values[2], None)
206
207        values = ArgsTestClass().foo2(c=True)
208        self.assertEquals(values[0], None)
209        self.assertEquals(values[1], None)
210        self.assertEquals(values[2], True)
211        
212        
213    def testDefaultValuesMethodCall(self):
214        values = ArgsTestClass().foo3(b=7)
215        self.assertEquals(values[0], 1)
216        self.assertEquals(values[1], 7)
217        self.assertEquals(values[2], 3)
218        
219        values = ArgsTestClass().foo3(a=9)
220        self.assertEquals(values[0], 9)
221        self.assertEquals(values[1], 2)
222        self.assertEquals(values[2], 3)
223        
224        values = ArgsTestClass().foo3()
225        self.assertEquals(values[0], 1)
226        self.assertEquals(values[1], 2)
227        self.assertEquals(values[2], 3)
228    
229    def testVarargsMethodCall(self):
230        values = ArgsTestClass().foo4(1, 2, 3)
231        self.assertEquals(values[0], 1)
232        self.assertEquals(values[1], 2)
233        self.assertEquals(values[2], 3)
234        
235        values = ArgsTestClass().foo4(3, 2, 1)
236        self.assertEquals(values[0], 3)
237        self.assertEquals(values[1], 2)
238        self.assertEquals(values[2], 1)
239    
240    def testKwargsMethodCall(self):
241        values = ArgsTestClass().foo5(x=5, y=7)
242        self.assertEquals(values["x"], 5)
243        self.assertEquals(values["y"], 7)
244
245    def testComboMethodCall(self):
246        values = ArgsTestClass().foo6(1, 2, 3, x=4, y=5)
247        self.assertEquals(values[0][0], 1)
248        self.assertEquals(values[0][1], 2)
249        self.assertEquals(values[0][2], 3)
250        self.assertEquals(values[1]["x"], 4)
251        self.assertEquals(values[1]["y"], 5)
252        
253    def testSimpleStaticMethodCall(self):
254        values = ArgsTestClass2.foo(1, 2, 3)
255        self.assertEquals(values[0], 1)
256        self.assertEquals(values[1], 2)
257        self.assertEquals(values[2], 3)
258        
259        values = ArgsTestClass2.foo2(1, 2, 3)
260        self.assertEquals(values[0], 1)
261        self.assertEquals(values[1], 2)
262        self.assertEquals(values[2], 3)
263
264    def testKeywordStaticMethodCall(self):
265        values = ArgsTestClass2.foo2(c=3, b=2, a=1)
266        self.assertEquals(values[0], 1)
267        self.assertEquals(values[1], 2)
268        self.assertEquals(values[2], 3)
269        
270        values = ArgsTestClass2.foo2(b=2, a=1, c=3)
271        self.assertEquals(values[0], 1)
272        self.assertEquals(values[1], 2)
273        self.assertEquals(values[2], 3)
274        
275        values = ArgsTestClass2.foo2()
276        self.assertEquals(values[0], None)
277        self.assertEquals(values[1], None)
278        self.assertEquals(values[2], None)
279
280        values = ArgsTestClass2.foo2(c=True)
281        self.assertEquals(values[0], None)
282        self.assertEquals(values[1], None)
283        self.assertEquals(values[2], True)
284        
285        
286    def testDefaultValuesStaticMethodCall(self):
287        values = ArgsTestClass2.foo3(b=7)
288        self.assertEquals(values[0], 1)
289        self.assertEquals(values[1], 7)
290        self.assertEquals(values[2], 3)
291        
292        values = ArgsTestClass2.foo3(a=9)
293        self.assertEquals(values[0], 9)
294        self.assertEquals(values[1], 2)
295        self.assertEquals(values[2], 3)
296        
297        values = ArgsTestClass2.foo3()
298        self.assertEquals(values[0], 1)
299        self.assertEquals(values[1], 2)
300        self.assertEquals(values[2], 3)
301    
302    def testVarargsStaticMethodCall(self):
303        values = ArgsTestClass2.foo4(1, 2, 3)
304        self.assertEquals(values[0], 1)
305        self.assertEquals(values[1], 2)
306        self.assertEquals(values[2], 3)
307        
308        values = ArgsTestClass2.foo4(3, 2, 1)
309        self.assertEquals(values[0], 3)
310        self.assertEquals(values[1], 2)
311        self.assertEquals(values[2], 1)
312    
313    def testKwargsStaticMethodCall(self):
314        values = ArgsTestClass2.foo5(x=5, y=7)
315        self.assertEquals(values["x"], 5)
316        self.assertEquals(values["y"], 7)
317
318    def testComboStaticMethodCall(self):
319        values = ArgsTestClass2.foo6(1, 2, 3, x=4, y=5)
320        self.assertEquals(values[0][0], 1)
321        self.assertEquals(values[0][1], 2)
322        self.assertEquals(values[0][2], 3)
323        self.assertEquals(values[1]["x"], 4)
324        self.assertEquals(values[1]["y"], 5)
325 
326    def testSimpleClassMethodCall(self):
327        values = ArgsTestClass3.foo(1, 2, 3)
328        self.assertEquals(values[0], 1)
329        self.assertEquals(values[1], 2)
330        self.assertEquals(values[2], 3)
331        
332        values = ArgsTestClass3.foo2(1, 2, 3)
333        self.assertEquals(values[0], 1)
334        self.assertEquals(values[1], 2)
335        self.assertEquals(values[2], 3)
336
337    def testKeywordClassMethodCall(self):
338        values = ArgsTestClass3.foo2(c=3, b=2, a=1)
339        self.assertEquals(values[0], 1)
340        self.assertEquals(values[1], 2)
341        self.assertEquals(values[2], 3)
342        
343        values = ArgsTestClass3.foo2(b=2, a=1, c=3)
344        self.assertEquals(values[0], 1)
345        self.assertEquals(values[1], 2)
346        self.assertEquals(values[2], 3)
347        
348        values = ArgsTestClass3.foo2()
349        self.assertEquals(values[0], None)
350        self.assertEquals(values[1], None)
351        self.assertEquals(values[2], None)
352
353        values = ArgsTestClass3.foo2(c=True)
354        self.assertEquals(values[0], None)
355        self.assertEquals(values[1], None)
356        self.assertEquals(values[2], True)
357        
358        
359    def testDefaultValuesClassMethodCall(self):
360        values = ArgsTestClass3.foo3(b=7)
361        self.assertEquals(values[0], 1)
362        self.assertEquals(values[1], 7)
363        self.assertEquals(values[2], 3)
364        
365        values = ArgsTestClass3.foo3(a=9)
366        self.assertEquals(values[0], 9)
367        self.assertEquals(values[1], 2)
368        self.assertEquals(values[2], 3)
369        
370        values = ArgsTestClass3.foo3()
371        self.assertEquals(values[0], 1)
372        self.assertEquals(values[1], 2)
373        self.assertEquals(values[2], 3)
374    
375    def testVarargsClassMethodCall(self):
376        values = ArgsTestClass3.foo4(1, 2, 3)
377        self.assertEquals(values[0], 1)
378        self.assertEquals(values[1], 2)
379        self.assertEquals(values[2], 3)
380        
381        values = ArgsTestClass3.foo4(3, 2, 1)
382        self.assertEquals(values[0], 3)
383        self.assertEquals(values[1], 2)
384        self.assertEquals(values[2], 1)
385    
386    def testKwargsClassMethodCall(self):
387        values = ArgsTestClass3.foo5(x=5, y=7)
388        self.assertEquals(values["x"], 5)
389        self.assertEquals(values["y"], 7)
390
391    def testComboClassMethodCall(self):
392        values = ArgsTestClass3.foo6(1, 2, 3, x=4, y=5)
393        self.assertEquals(values[0][0], 1)
394        self.assertEquals(values[0][1], 2)
395        self.assertEquals(values[0][2], 3)
396        self.assertEquals(values[1]["x"], 4)
397        self.assertEquals(values[1]["y"], 5)
398        
399    def testSimpleIndirectClassMethodCall(self):
400        values = ArgsTestClass3().foo(1, 2, 3)
401        self.assertEquals(values[0], 1)
402        self.assertEquals(values[1], 2)
403        self.assertEquals(values[2], 3)
404        
405        values = ArgsTestClass3().foo2(1, 2, 3)
406        self.assertEquals(values[0], 1)
407        self.assertEquals(values[1], 2)
408        self.assertEquals(values[2], 3)
409
410    def testKeywordIndirectClassMethodCall(self):
411        values = ArgsTestClass3().foo2(c=3, b=2, a=1)
412        self.assertEquals(values[0], 1)
413        self.assertEquals(values[1], 2)
414        self.assertEquals(values[2], 3)
415        
416        values = ArgsTestClass3().foo2(b=2, a=1, c=3)
417        self.assertEquals(values[0], 1)
418        self.assertEquals(values[1], 2)
419        self.assertEquals(values[2], 3)
420        
421        values = ArgsTestClass3().foo2()
422        self.assertEquals(values[0], None)
423        self.assertEquals(values[1], None)
424        self.assertEquals(values[2], None)
425
426        values = ArgsTestClass3().foo2(c=True)
427        self.assertEquals(values[0], None)
428        self.assertEquals(values[1], None)
429        self.assertEquals(values[2], True)
430        
431        
432    def testDefaultValuesIndirectClassMethodCall(self):
433        values = ArgsTestClass3().foo3(b=7)
434        self.assertEquals(values[0], 1)
435        self.assertEquals(values[1], 7)
436        self.assertEquals(values[2], 3)
437        
438        values = ArgsTestClass3().foo3(a=9)
439        self.assertEquals(values[0], 9)
440        self.assertEquals(values[1], 2)
441        self.assertEquals(values[2], 3)
442        
443        values = ArgsTestClass3().foo3()
444        self.assertEquals(values[0], 1)
445        self.assertEquals(values[1], 2)
446        self.assertEquals(values[2], 3)
447    
448    def testVarargsIndirectClassMethodCall(self):
449        values = ArgsTestClass3().foo4(1, 2, 3)
450        self.assertEquals(values[0], 1)
451        self.assertEquals(values[1], 2)
452        self.assertEquals(values[2], 3)
453        
454        values = ArgsTestClass3().foo4(3, 2, 1)
455        self.assertEquals(values[0], 3)
456        self.assertEquals(values[1], 2)
457        self.assertEquals(values[2], 1)
458    
459    def testKwargsIndirectClassMethodCall(self):
460        values = ArgsTestClass3().foo5(x=5, y=7)
461        self.assertEquals(values["x"], 5)
462        self.assertEquals(values["y"], 7)
463
464    def testComboIndirectClassMethodCall(self):
465        values = ArgsTestClass3().foo6(1, 2, 3, x=4, y=5)
466        self.assertEquals(values[0][0], 1)
467        self.assertEquals(values[0][1], 2)
468        self.assertEquals(values[0][2], 3)
469        self.assertEquals(values[1]["x"], 4)
470        self.assertEquals(values[1]["y"], 5)
471       
472def foo(a, b, c):
473    return [a, b, c]
474
475def foo2(a=None, b=None, c=None):
476    return [a, b, c]
477
478def foo3(a=1, b=2, c=3):
479    return [a, b, c]
480
481def foo4(a, b, c, *args):
482    return a, b, c, args
483
484def foo5(a, b, c, **kwargs):
485    return a, b, c, kwargs
486
487def foo6(a, b, c, *args, **kwargs):
488    return (a, b, c, args, kwargs)
489
490class ArgsTestClass_foo:
491    def __init__(self, a, b, c):
492        self.x = [a, b, c]
493
494class ArgsTestClass_foo2:
495    def __init__(self, a=None, b=None, c=None):
496        self.x = [a, b, c]
497
498class ArgsTestClass_foo3:
499    def __init__(self, a=1, b=2, c=3):
500        self.x = [a, b, c]
501
502class ArgsTestClass_foo4:
503    def __init__(self, a, b, c, *args):
504        self.x = a, b, c, args
505
506class ArgsTestClass_foo5:
507    def __init__(self, a, b, c, **kwargs):
508        self.x = a, b, c, kwargs
509
510class ArgsTestClass_foo6:
511    def __init__(self, a, b, c, *args, **kwargs):
512        self.x = (a, b, c, args, kwargs)
513
514class ArgsTestClass:
515    def foo(self, a, b, c):
516        return [a, b, c]
517    
518    def foo2(self, a=None, b=None, c=None):
519        return [a, b, c]
520    
521    def foo3(self, a=1, b=2, c=3):
522        return [a, b, c]
523    
524    def foo4(self, *args):
525        return args
526    
527    def foo5(self, **kwargs):
528        return kwargs
529    
530    def foo6(self, *args, **kwargs):
531        return (args, kwargs)
532    
533
534class ArgsTestClass2:
535    @staticmethod
536    def foo(a, b, c):
537        return [a, b, c]
538    
539    @staticmethod
540    def foo2(a=None, b=None, c=None):
541        return [a, b, c]
542    
543    @staticmethod
544    def foo3(a=1, b=2, c=3):
545        return [a, b, c]
546    
547    @staticmethod
548    def foo4(*args):
549        return args
550    
551    @staticmethod
552    def foo5(**kwargs):
553        return kwargs
554    
555    @staticmethod
556    def foo6(*args, **kwargs):
557        return (args, kwargs)
558
559class ArgsTestClass3:
560    @classmethod
561    def foo(self, a, b, c):
562        return [a, b, c]
563    
564    @classmethod
565    def foo2(self, a=None, b=None, c=None):
566        return [a, b, c]
567    
568    @classmethod
569    def foo3(self, a=1, b=2, c=3):
570        return [a, b, c]
571    
572    @classmethod
573    def foo4(self, *args):
574        return args
575    
576    @classmethod
577    def foo5(self, **kwargs):
578        return kwargs
579    
580    @classmethod
581    def foo6(self, *args, **kwargs):
582        return (args, kwargs)
583
584