summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2019-11-09 16:21:55 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2019-11-09 16:21:55 +0000
commited2c5f9ad1f92010e447797576ab4eef3beee21f (patch)
tree6e39e7366de4ac2fbb6a98e4e5938e33f34422a4 /lib/sqlalchemy/testing
parent4a2dd4902a1168234f14bdd0634728086d53c406 (diff)
parent3a0e0531c179e598c345e5be24e350c375ce7e22 (diff)
downloadsqlalchemy-ed2c5f9ad1f92010e447797576ab4eef3beee21f.tar.gz
Merge "Support for generated columns"
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/config.py7
-rw-r--r--lib/sqlalchemy/testing/requirements.py4
-rw-r--r--lib/sqlalchemy/testing/suite/test_select.py45
3 files changed, 54 insertions, 2 deletions
diff --git a/lib/sqlalchemy/testing/config.py b/lib/sqlalchemy/testing/config.py
index 87bbc6a0f..8262142ec 100644
--- a/lib/sqlalchemy/testing/config.py
+++ b/lib/sqlalchemy/testing/config.py
@@ -44,7 +44,7 @@ def combinations(*comb, **kw):
well as if it is included in the tokens used to create the id of the
parameter set.
- If omitted, the argment combinations are passed to parametrize as is. If
+ If omitted, the argument combinations are passed to parametrize as is. If
passed, each argument combination is turned into a pytest.param() object,
mapping the elements of the argument tuple to produce an id based on a
character value in the same position within the string template using the
@@ -59,9 +59,12 @@ def combinations(*comb, **kw):
r - the given argument should be passed and it should be added to the
id by calling repr()
- s- the given argument should be passed and it should be added to the
+ s - the given argument should be passed and it should be added to the
id by calling str()
+ a - (argument) the given argument should be passed and it should not
+ be used to generated the id
+
e.g.::
@testing.combinations(
diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py
index c45156d6b..fd8d82690 100644
--- a/lib/sqlalchemy/testing/requirements.py
+++ b/lib/sqlalchemy/testing/requirements.py
@@ -1064,3 +1064,7 @@ class SuiteRequirements(Requirements):
return True
except ImportError:
return False
+
+ @property
+ def computed_columns(self):
+ return exclusions.closed()
diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py
index 02cdcf4f5..9db2daf7a 100644
--- a/lib/sqlalchemy/testing/suite/test_select.py
+++ b/lib/sqlalchemy/testing/suite/test_select.py
@@ -9,6 +9,7 @@ from ..schema import Column
from ..schema import Table
from ... import bindparam
from ... import case
+from ... import Computed
from ... import false
from ... import func
from ... import Integer
@@ -858,3 +859,47 @@ class LikeFunctionsTest(fixtures.TablesTest):
col = self.tables.some_table.c.data
self._test(col.contains("b%cd", autoescape=True, escape="#"), {3})
self._test(col.contains("b#cd", autoescape=True, escape="#"), {7})
+
+
+class ComputedColumnTest(fixtures.TablesTest):
+ __backend__ = True
+ __requires__ = ("computed_columns",)
+
+ @classmethod
+ def define_tables(cls, metadata):
+ Table(
+ "square",
+ metadata,
+ Column("id", Integer, primary_key=True),
+ Column("side", Integer),
+ Column("area", Integer, Computed("side * side")),
+ Column("perimeter", Integer, Computed("4 * side")),
+ )
+
+ @classmethod
+ def insert_data(cls):
+ with config.db.begin() as conn:
+ conn.execute(
+ cls.tables.square.insert(),
+ [{"id": 1, "side": 10}, {"id": 10, "side": 42}],
+ )
+
+ def test_select_all(self):
+ with config.db.connect() as conn:
+ res = conn.execute(
+ select([text("*")])
+ .select_from(self.tables.square)
+ .order_by(self.tables.square.c.id)
+ ).fetchall()
+ eq_(res, [(1, 10, 100, 40), (10, 42, 1764, 168)])
+
+ def test_select_columns(self):
+ with config.db.connect() as conn:
+ res = conn.execute(
+ select(
+ [self.tables.square.c.area, self.tables.square.c.perimeter]
+ )
+ .select_from(self.tables.square)
+ .order_by(self.tables.square.c.id)
+ ).fetchall()
+ eq_(res, [(100, 40), (1764, 168)])