Mercurial > hg > pyloader
annotate tests/test_call.txt @ 49:43cb882c3b72
fix test failure
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 08 Jun 2011 21:58:18 -0700 |
parents | d50d5237e82d |
children | 418289c0fe3c |
rev | line source |
---|---|
12 | 1 Test call |
2 ========= | |
5
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 Test the call method:: |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 >>> from pyloader.invoke import call |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 >>> options = {'badarg': 'bar', 'a': 7, 'b': 9, 'c': 10} |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 >>> def foo(a, b=1, c=2): |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 ... return a + 10*b + 100*c |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 >>> foo(7, 9, 10) |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 1097 |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 You can't call methods with bad arguments OOTB in python:: |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 >>> error = None |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 >>> try: |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 ... foo(**options) |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 ... except TypeError, e: |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 ... error = e |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 >>> type(error) |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 <type 'exceptions.TypeError'> |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 But you can with call:: |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 >>> call(foo, **options) |
a825f00fe062
add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 1097 |