diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-03-02 13:59:06 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-03-02 13:59:06 -0500 |
commit | bf89ca2e10ff1c38e76f78e2d11d7858a50df547 (patch) | |
tree | 2ba46827eb96416e0b8db822b6495d4bc1e6f673 /test/base/test_utils.py | |
parent | 6750c39a4fc6be01502f3c9b1c6ba2d3f67a030e (diff) | |
download | sqlalchemy-bf89ca2e10ff1c38e76f78e2d11d7858a50df547.tar.gz |
- get util.get_callable_argspec() to be completely bulletproof for 2.6-3.4,
methods, classes, builtins, functools.partial(), everything known so far
- use get_callable_argspec() within ColumnDefault._maybe_wrap_callable, re: #2979
Diffstat (limited to 'test/base/test_utils.py')
-rw-r--r-- | test/base/test_utils.py | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/test/base/test_utils.py b/test/base/test_utils.py index 4ff17e8cc..34b707e6c 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -1377,6 +1377,35 @@ class ArgInspectionTest(fixtures.TestBase): (['x', 'y'], None, 'kw', None) ) + def test_callable_argspec_fn_no_self(self): + def foo(x, y, **kw): + pass + eq_( + get_callable_argspec(foo, no_self=True), + (['x', 'y'], None, 'kw', None) + ) + + def test_callable_argspec_fn_no_self_but_self(self): + def foo(self, x, y, **kw): + pass + eq_( + get_callable_argspec(foo, no_self=True), + (['self', 'x', 'y'], None, 'kw', None) + ) + + def test_callable_argspec_py_builtin(self): + import datetime + assert_raises( + TypeError, + get_callable_argspec, datetime.datetime.now + ) + + def test_callable_argspec_obj_init(self): + assert_raises( + TypeError, + get_callable_argspec, object + ) + def test_callable_argspec_method(self): class Foo(object): def foo(self, x, y, **kw): @@ -1386,6 +1415,62 @@ class ArgInspectionTest(fixtures.TestBase): (['self', 'x', 'y'], None, 'kw', None) ) + def test_callable_argspec_instance_method_no_self(self): + class Foo(object): + def foo(self, x, y, **kw): + pass + eq_( + get_callable_argspec(Foo().foo, no_self=True), + (['x', 'y'], None, 'kw', None) + ) + + def test_callable_argspec_unbound_method_no_self(self): + class Foo(object): + def foo(self, x, y, **kw): + pass + eq_( + get_callable_argspec(Foo.foo, no_self=True), + (['self', 'x', 'y'], None, 'kw', None) + ) + + def test_callable_argspec_init(self): + class Foo(object): + def __init__(self, x, y): + pass + + eq_( + get_callable_argspec(Foo), + (['self', 'x', 'y'], None, None, None) + ) + + def test_callable_argspec_init_no_self(self): + class Foo(object): + def __init__(self, x, y): + pass + + eq_( + get_callable_argspec(Foo, no_self=True), + (['x', 'y'], None, None, None) + ) + + def test_callable_argspec_call(self): + class Foo(object): + def __call__(self, x, y): + pass + eq_( + get_callable_argspec(Foo()), + (['self', 'x', 'y'], None, None, None) + ) + + def test_callable_argspec_call_no_self(self): + class Foo(object): + def __call__(self, x, y): + pass + eq_( + get_callable_argspec(Foo(), no_self=True), + (['x', 'y'], None, None, None) + ) + def test_callable_argspec_partial(self): from functools import partial def foo(x, y, z, **kw): @@ -1393,7 +1478,7 @@ class ArgInspectionTest(fixtures.TestBase): bar = partial(foo, 5) assert_raises( - ValueError, + TypeError, get_callable_argspec, bar ) |