From aded39f68c29e44a50c85be1ddb370d3d1affe9d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 21 Apr 2020 12:51:13 -0400 Subject: Propose Result as immediate replacement for ResultProxy As progress is made on the _future.Result, including breaking it out such that DBAPI behaviors are local to specific implementations, it becomes apparent that the Result object is a functional superset of ResultProxy and that basic operations like fetchone(), fetchall(), and fetchmany() behave pretty much exactly the same way on the new object. Reorganize things so that ResultProxy is now referred to as LegacyCursorResult, which subclasses CursorResult that represents the DBAPI-cursor version of Result, making use of a multiple inheritance pattern so that the functionality of Result is also available in non-DBAPI contexts, as will be necessary for some ORM patterns. Additionally propose the composition system for Result that will form the basis for ORM-alternative result systems such as horizontal sharding and dogpile cache. As ORM results will soon be coming directly from instances of Result, these extensions will instead build their own ResultFetchStrategies that perform the special steps to create composed or cached result sets. Also considering at the moment not emitting deprecation warnings for fetchXYZ() methods; the immediate issue is Keystone tests are calling upon it, but as the implementations here are proving to be not in any kind of conflict with how Result works, there's not too much issue leaving them around and deprecating at some later point. References: #5087 References: #4395 Fixes: #4959 Change-Id: I8091919d45421e3f53029b8660427f844fee0228 --- test/base/test_utils.py | 139 ------------------------------------------------ 1 file changed, 139 deletions(-) (limited to 'test/base/test_utils.py') diff --git a/test/base/test_utils.py b/test/base/test_utils.py index 246199861..96a9f955a 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -9,7 +9,6 @@ from sqlalchemy import exc from sqlalchemy import sql from sqlalchemy import testing from sqlalchemy import util -from sqlalchemy.engine import result from sqlalchemy.sql import column from sqlalchemy.sql.base import DedupeColumnCollection from sqlalchemy.testing import assert_raises @@ -33,144 +32,6 @@ from sqlalchemy.util import timezone from sqlalchemy.util import WeakSequence -class _KeyedTupleTest(object): - def _fixture(self, values, labels): - raise NotImplementedError() - - def test_empty(self): - keyed_tuple = self._fixture([], []) - eq_(str(keyed_tuple), "()") - eq_(len(keyed_tuple), 0) - - eq_(list(keyed_tuple._mapping.keys()), []) - eq_(keyed_tuple._fields, ()) - eq_(keyed_tuple._asdict(), {}) - - def test_values_none_labels(self): - keyed_tuple = self._fixture([1, 2], [None, None]) - eq_(str(keyed_tuple), "(1, 2)") - eq_(len(keyed_tuple), 2) - - eq_(list(keyed_tuple._mapping.keys()), []) - eq_(keyed_tuple._fields, ()) - eq_(keyed_tuple._asdict(), {}) - - eq_(keyed_tuple[0], 1) - eq_(keyed_tuple[1], 2) - - def test_creation(self): - keyed_tuple = self._fixture([1, 2], ["a", "b"]) - eq_(str(keyed_tuple), "(1, 2)") - eq_(list(keyed_tuple._mapping.keys()), ["a", "b"]) - eq_(keyed_tuple._fields, ("a", "b")) - eq_(keyed_tuple._asdict(), {"a": 1, "b": 2}) - - def test_index_access(self): - keyed_tuple = self._fixture([1, 2], ["a", "b"]) - eq_(keyed_tuple[0], 1) - eq_(keyed_tuple[1], 2) - - def should_raise(): - keyed_tuple[2] - - assert_raises(IndexError, should_raise) - - def test_slice_access(self): - keyed_tuple = self._fixture([1, 2], ["a", "b"]) - eq_(keyed_tuple[0:2], (1, 2)) - - def test_attribute_access(self): - keyed_tuple = self._fixture([1, 2], ["a", "b"]) - eq_(keyed_tuple.a, 1) - eq_(keyed_tuple.b, 2) - - def should_raise(): - keyed_tuple.c - - assert_raises(AttributeError, should_raise) - - def test_contains(self): - keyed_tuple = self._fixture(["x", "y"], ["a", "b"]) - - is_true("x" in keyed_tuple) - is_false("z" in keyed_tuple) - - is_true("z" not in keyed_tuple) - is_false("x" not in keyed_tuple) - - # we don't do keys - is_false("a" in keyed_tuple) - is_false("z" in keyed_tuple) - is_true("a" not in keyed_tuple) - is_true("z" not in keyed_tuple) - - def test_none_label(self): - keyed_tuple = self._fixture([1, 2, 3], ["a", None, "b"]) - eq_(str(keyed_tuple), "(1, 2, 3)") - - eq_(list(keyed_tuple._mapping.keys()), ["a", "b"]) - eq_(keyed_tuple._fields, ("a", "b")) - eq_(keyed_tuple._asdict(), {"a": 1, "b": 3}) - - # attribute access: can't get at value 2 - eq_(keyed_tuple.a, 1) - eq_(keyed_tuple.b, 3) - - # index access: can get at value 2 - eq_(keyed_tuple[0], 1) - eq_(keyed_tuple[1], 2) - eq_(keyed_tuple[2], 3) - - def test_duplicate_labels(self): - keyed_tuple = self._fixture([1, 2, 3], ["a", "b", "b"]) - eq_(str(keyed_tuple), "(1, 2, 3)") - - eq_(list(keyed_tuple._mapping.keys()), ["a", "b", "b"]) - eq_(keyed_tuple._fields, ("a", "b", "b")) - eq_(keyed_tuple._asdict(), {"a": 1, "b": 3}) - - # attribute access: can't get at value 2 - eq_(keyed_tuple.a, 1) - eq_(keyed_tuple.b, 3) - - # index access: can get at value 2 - eq_(keyed_tuple[0], 1) - eq_(keyed_tuple[1], 2) - eq_(keyed_tuple[2], 3) - - def test_immutable(self): - keyed_tuple = self._fixture([1, 2], ["a", "b"]) - eq_(str(keyed_tuple), "(1, 2)") - - eq_(keyed_tuple.a, 1) - - # eh - # assert_raises(AttributeError, setattr, keyed_tuple, "a", 5) - - def should_raise(): - keyed_tuple[0] = 100 - - assert_raises(TypeError, should_raise) - - def test_serialize(self): - - keyed_tuple = self._fixture([1, 2, 3], ["a", None, "b"]) - - for loads, dumps in picklers(): - kt = loads(dumps(keyed_tuple)) - - eq_(str(kt), "(1, 2, 3)") - - eq_(list(kt._mapping.keys()), ["a", "b"]) - eq_(kt._fields, ("a", "b")) - eq_(kt._asdict(), {"a": 1, "b": 3}) - - -class LWKeyedTupleTest(_KeyedTupleTest, fixtures.TestBase): - def _fixture(self, values, labels): - return result.result_tuple(labels)(values) - - class WeakSequenceTest(fixtures.TestBase): @testing.requires.predictable_gc def test_cleanout_elements(self): -- cgit v1.2.1