Mercurial > hg > pyloader
annotate tests/test_call.txt @ 89:7fdd934855bf
needs a bit more thought
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 21 Mar 2014 23:04:01 -0700 |
parents | 418289c0fe3c |
children |
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} |
85
418289c0fe3c
STUB: tests/test_call.txt tests/test_factory.txt
Jeff Hammel <k0scist@gmail.com>
parents:
12
diff
changeset
|
8 >>> def foo(a, b=1, c=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
|
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 |