summaryrefslogtreecommitdiff
path: root/test/base/test_utils.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-10-08 15:20:48 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-10-10 01:17:25 -0400
commit2665a0c4cb3e94e6545d0b9bbcbcc39ccffebaba (patch)
treeed25383ce7e5899d7d643a11df0f8aee9f2ab959 /test/base/test_utils.py
parentbcc17b1d6e2cac3b0e45c0b17a62cf2d5fc5c5ab (diff)
downloadsqlalchemy-2665a0c4cb3e94e6545d0b9bbcbcc39ccffebaba.tar.gz
generalize scoped_session proxying and apply to asyncio elements
Reworked the proxy creation used by scoped_session() to be based on fully copied code with augmented docstrings and moved it into langhelpers. asyncio session, engine, connection can now take advantage of it so that all non-async methods are availble. Overall implementation of most important accessors / methods on AsyncConnection, etc. , including awaitable versions of invalidate, execution_options, etc. In order to support an event dispatcher on the async classes while still allowing them to hold __slots__, make some adjustments to the event system to allow that to be present, at least rudimentally. Fixes: #5628 Change-Id: I5eb6929fc1e4fdac99e4b767dcfd49672d56e2b2
Diffstat (limited to 'test/base/test_utils.py')
-rw-r--r--test/base/test_utils.py222
1 files changed, 129 insertions, 93 deletions
diff --git a/test/base/test_utils.py b/test/base/test_utils.py
index fa347243e..9220720b6 100644
--- a/test/base/test_utils.py
+++ b/test/base/test_utils.py
@@ -2300,7 +2300,14 @@ class SymbolTest(fixtures.TestBase):
class _Py3KFixtures(object):
- pass
+ def _kw_only_fixture(self):
+ pass
+
+ def _kw_plus_posn_fixture(self):
+ pass
+
+ def _kw_opt_fixture(self):
+ pass
if util.py3k:
@@ -2321,185 +2328,208 @@ def _kw_opt_fixture(self, a, *, b, c="c"):
for k in _locals:
setattr(_Py3KFixtures, k, _locals[k])
+py3k_fixtures = _Py3KFixtures()
-class TestFormatArgspec(_Py3KFixtures, fixtures.TestBase):
- def _test_format_argspec_plus(self, fn, wanted, grouped=None):
-
- # test direct function
- if grouped is None:
- parsed = util.format_argspec_plus(fn)
- else:
- parsed = util.format_argspec_plus(fn, grouped=grouped)
- eq_(parsed, wanted)
-
- # test sending fullargspec
- spec = compat.inspect_getfullargspec(fn)
- if grouped is None:
- parsed = util.format_argspec_plus(spec)
- else:
- parsed = util.format_argspec_plus(spec, grouped=grouped)
- eq_(parsed, wanted)
- def test_specs(self):
- self._test_format_argspec_plus(
+class TestFormatArgspec(_Py3KFixtures, fixtures.TestBase):
+ @testing.combinations(
+ (
lambda: None,
{
"args": "()",
"self_arg": None,
"apply_kw": "()",
"apply_pos": "()",
+ "apply_pos_proxied": "()",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda: None,
- {"args": "", "self_arg": None, "apply_kw": "", "apply_pos": ""},
- grouped=False,
- )
-
- self._test_format_argspec_plus(
+ {
+ "args": "",
+ "self_arg": None,
+ "apply_kw": "",
+ "apply_pos": "",
+ "apply_pos_proxied": "",
+ },
+ False,
+ ),
+ (
lambda self: None,
{
"args": "(self)",
"self_arg": "self",
"apply_kw": "(self)",
"apply_pos": "(self)",
+ "apply_pos_proxied": "()",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda self: None,
{
"args": "self",
"self_arg": "self",
"apply_kw": "self",
"apply_pos": "self",
+ "apply_pos_proxied": "",
},
- grouped=False,
- )
-
- self._test_format_argspec_plus(
+ False,
+ ),
+ (
lambda *a: None,
{
"args": "(*a)",
"self_arg": "a[0]",
"apply_kw": "(*a)",
"apply_pos": "(*a)",
+ "apply_pos_proxied": "(*a)",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda **kw: None,
{
"args": "(**kw)",
"self_arg": None,
"apply_kw": "(**kw)",
"apply_pos": "(**kw)",
+ "apply_pos_proxied": "(**kw)",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda *a, **kw: None,
{
"args": "(*a, **kw)",
"self_arg": "a[0]",
"apply_kw": "(*a, **kw)",
"apply_pos": "(*a, **kw)",
+ "apply_pos_proxied": "(*a, **kw)",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda a, *b: None,
{
"args": "(a, *b)",
"self_arg": "a",
"apply_kw": "(a, *b)",
"apply_pos": "(a, *b)",
+ "apply_pos_proxied": "(*b)",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda a, **b: None,
{
"args": "(a, **b)",
"self_arg": "a",
"apply_kw": "(a, **b)",
"apply_pos": "(a, **b)",
+ "apply_pos_proxied": "(**b)",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda a, *b, **c: None,
{
"args": "(a, *b, **c)",
"self_arg": "a",
"apply_kw": "(a, *b, **c)",
"apply_pos": "(a, *b, **c)",
+ "apply_pos_proxied": "(*b, **c)",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda a, b=1, **c: None,
{
"args": "(a, b=1, **c)",
"self_arg": "a",
"apply_kw": "(a, b=b, **c)",
"apply_pos": "(a, b, **c)",
+ "apply_pos_proxied": "(b, **c)",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda a=1, b=2: None,
{
"args": "(a=1, b=2)",
"self_arg": "a",
"apply_kw": "(a=a, b=b)",
"apply_pos": "(a, b)",
+ "apply_pos_proxied": "(b)",
},
- )
-
- self._test_format_argspec_plus(
+ True,
+ ),
+ (
lambda a=1, b=2: None,
{
"args": "a=1, b=2",
"self_arg": "a",
"apply_kw": "a=a, b=b",
"apply_pos": "a, b",
+ "apply_pos_proxied": "b",
},
- grouped=False,
- )
-
- if util.py3k:
- self._test_format_argspec_plus(
- self._kw_only_fixture,
- {
- "args": "self, a, *, b, c",
- "self_arg": "self",
- "apply_pos": "self, a, *, b, c",
- "apply_kw": "self, a, b=b, c=c",
- },
- grouped=False,
- )
- self._test_format_argspec_plus(
- self._kw_plus_posn_fixture,
- {
- "args": "self, a, *args, b, c",
- "self_arg": "self",
- "apply_pos": "self, a, *args, b, c",
- "apply_kw": "self, a, b=b, c=c, *args",
- },
- grouped=False,
- )
- self._test_format_argspec_plus(
- self._kw_opt_fixture,
- {
- "args": "self, a, *, b, c='c'",
- "self_arg": "self",
- "apply_pos": "self, a, *, b, c",
- "apply_kw": "self, a, b=b, c=c",
- },
- grouped=False,
- )
+ False,
+ ),
+ (
+ py3k_fixtures._kw_only_fixture,
+ {
+ "args": "self, a, *, b, c",
+ "self_arg": "self",
+ "apply_pos": "self, a, *, b, c",
+ "apply_kw": "self, a, b=b, c=c",
+ "apply_pos_proxied": "a, *, b, c",
+ },
+ False,
+ testing.requires.python3,
+ ),
+ (
+ py3k_fixtures._kw_plus_posn_fixture,
+ {
+ "args": "self, a, *args, b, c",
+ "self_arg": "self",
+ "apply_pos": "self, a, *args, b, c",
+ "apply_kw": "self, a, b=b, c=c, *args",
+ "apply_pos_proxied": "a, *args, b, c",
+ },
+ False,
+ testing.requires.python3,
+ ),
+ (
+ py3k_fixtures._kw_opt_fixture,
+ {
+ "args": "self, a, *, b, c='c'",
+ "self_arg": "self",
+ "apply_pos": "self, a, *, b, c",
+ "apply_kw": "self, a, b=b, c=c",
+ "apply_pos_proxied": "a, *, b, c",
+ },
+ False,
+ testing.requires.python3,
+ ),
+ argnames="fn,wanted,grouped",
+ )
+ def test_specs(self, fn, wanted, grouped):
+
+ # test direct function
+ if grouped is None:
+ parsed = util.format_argspec_plus(fn)
+ else:
+ parsed = util.format_argspec_plus(fn, grouped=grouped)
+ eq_(parsed, wanted)
+
+ # test sending fullargspec
+ spec = compat.inspect_getfullargspec(fn)
+ if grouped is None:
+ parsed = util.format_argspec_plus(spec)
+ else:
+ parsed = util.format_argspec_plus(spec, grouped=grouped)
+ eq_(parsed, wanted)
@testing.requires.cpython
def test_init_grouped(self):
@@ -2508,17 +2538,20 @@ class TestFormatArgspec(_Py3KFixtures, fixtures.TestBase):
"self_arg": "self",
"apply_pos": "(self)",
"apply_kw": "(self)",
+ "apply_pos_proxied": "()",
}
wrapper_spec = {
"args": "(self, *args, **kwargs)",
"self_arg": "self",
"apply_pos": "(self, *args, **kwargs)",
"apply_kw": "(self, *args, **kwargs)",
+ "apply_pos_proxied": "(*args, **kwargs)",
}
custom_spec = {
"args": "(slef, a=123)",
"self_arg": "slef", # yes, slef
"apply_pos": "(slef, a)",
+ "apply_pos_proxied": "(a)",
"apply_kw": "(slef, a=a)",
}
@@ -2532,18 +2565,21 @@ class TestFormatArgspec(_Py3KFixtures, fixtures.TestBase):
"self_arg": "self",
"apply_pos": "self",
"apply_kw": "self",
+ "apply_pos_proxied": "",
}
wrapper_spec = {
"args": "self, *args, **kwargs",
"self_arg": "self",
"apply_pos": "self, *args, **kwargs",
"apply_kw": "self, *args, **kwargs",
+ "apply_pos_proxied": "*args, **kwargs",
}
custom_spec = {
"args": "slef, a=123",
"self_arg": "slef", # yes, slef
"apply_pos": "slef, a",
"apply_kw": "slef, a=a",
+ "apply_pos_proxied": "a",
}
self._test_init(False, object_spec, wrapper_spec, custom_spec)