summaryrefslogtreecommitdiff
path: root/test/base/test_utils.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-08-11 15:24:13 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-08-11 22:33:54 -0400
commit2a079cdc76b3a0f5b4f37299d280d328586e2f7e (patch)
treed7769b2c30ec0fdbdced9514bfbd7936fd9e489e /test/base/test_utils.py
parentf5e57f7c311288d892894edcc44d901b5bfbb3d1 (diff)
downloadsqlalchemy-2a079cdc76b3a0f5b4f37299d280d328586e2f7e.tar.gz
Rewrite pool reset_on_return parsing using a util function
Choosing a util.symbol() based on a user parameter is about to have another use case added as part of #4623, so add a generalized solution ahead of it. Change-Id: I420631f81af2ffc655995b9cce9ff2ac618c16d7
Diffstat (limited to 'test/base/test_utils.py')
-rw-r--r--test/base/test_utils.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/base/test_utils.py b/test/base/test_utils.py
index 4f073ebfe..0b431def2 100644
--- a/test/base/test_utils.py
+++ b/test/base/test_utils.py
@@ -2227,6 +2227,69 @@ class SymbolTest(fixtures.TestBase):
assert not (sym1 | sym2) & (sym3 | sym4)
assert (sym1 | sym2) & (sym2 | sym4)
+ def test_parser(self):
+ sym1 = util.symbol("sym1", canonical=1)
+ sym2 = util.symbol("sym2", canonical=2)
+ sym3 = util.symbol("sym3", canonical=4)
+ sym4 = util.symbol("sym4", canonical=8)
+
+ lookup_one = {sym1: [], sym2: [True], sym3: [False], sym4: [None]}
+ lookup_two = {sym1: [], sym2: [True], sym3: [False]}
+ lookup_three = {sym1: [], sym2: ["symbol2"], sym3: []}
+
+ is_(
+ util.symbol.parse_user_argument(
+ "sym2", lookup_one, "some_name", resolve_symbol_names=True
+ ),
+ sym2,
+ )
+
+ assert_raises_message(
+ exc.ArgumentError,
+ "Invalid value for 'some_name': 'sym2'",
+ util.symbol.parse_user_argument,
+ "sym2",
+ lookup_one,
+ "some_name",
+ )
+ is_(
+ util.symbol.parse_user_argument(
+ True, lookup_one, "some_name", resolve_symbol_names=False
+ ),
+ sym2,
+ )
+
+ is_(
+ util.symbol.parse_user_argument(sym2, lookup_one, "some_name"),
+ sym2,
+ )
+
+ is_(
+ util.symbol.parse_user_argument(None, lookup_one, "some_name"),
+ sym4,
+ )
+
+ is_(
+ util.symbol.parse_user_argument(None, lookup_two, "some_name"),
+ None,
+ )
+
+ is_(
+ util.symbol.parse_user_argument(
+ "symbol2", lookup_three, "some_name"
+ ),
+ sym2,
+ )
+
+ assert_raises_message(
+ exc.ArgumentError,
+ "Invalid value for 'some_name': 'foo'",
+ util.symbol.parse_user_argument,
+ "foo",
+ lookup_three,
+ "some_name",
+ )
+
class _Py3KFixtures(object):
pass