summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/base/test_tutorials.py51
-rw-r--r--test/orm/test_query.py48
-rw-r--r--test/sql/test_compiler.py40
-rw-r--r--test/sql/test_metadata.py6
4 files changed, 120 insertions, 25 deletions
diff --git a/test/base/test_tutorials.py b/test/base/test_tutorials.py
index 4ac3fb981..ea2c1e362 100644
--- a/test/base/test_tutorials.py
+++ b/test/base/test_tutorials.py
@@ -56,7 +56,10 @@ class DocTest(fixtures.TestBase):
self._teardown_create_table_patcher()
self._teardown_logger()
- def _run_doctest_for_content(self, name, content):
+ def _run_doctest(self, *fnames):
+ here = os.path.dirname(__file__)
+ sqla_base = os.path.normpath(os.path.join(here, "..", ".."))
+
optionflags = (
doctest.ELLIPSIS
| doctest.NORMALIZE_WHITESPACE
@@ -68,23 +71,33 @@ class DocTest(fixtures.TestBase):
optionflags=optionflags,
checker=_get_unicode_checker(),
)
- globs = {"print_function": print_function}
parser = doctest.DocTestParser()
- test = parser.get_doctest(content, globs, name, name, 0)
- runner.run(test)
- runner.summarize()
- assert not runner.failures
+ globs = {"print_function": print_function}
- def _run_doctest(self, fname):
- here = os.path.dirname(__file__)
- sqla_base = os.path.normpath(os.path.join(here, "..", ".."))
- path = os.path.join(sqla_base, "doc/build", fname)
- if not os.path.exists(path):
- config.skip_test("Can't find documentation file %r" % path)
- with open(path) as file_:
- content = file_.read()
- content = re.sub(r"{(?:stop|sql|opensql)}", "", content)
- self._run_doctest_for_content(fname, content)
+ for fname in fnames:
+ path = os.path.join(sqla_base, "doc/build", fname)
+ if not os.path.exists(path):
+ config.skip_test("Can't find documentation file %r" % path)
+ with open(path) as file_:
+ content = file_.read()
+ content = re.sub(r"{(?:stop|sql|opensql)}", "", content)
+
+ test = parser.get_doctest(content, globs, fname, fname, 0)
+ runner.run(test, clear_globs=False)
+ runner.summarize()
+ globs.update(test.globs)
+ assert not runner.failures
+
+ def test_20_style(self):
+ self._run_doctest(
+ "tutorial/index.rst",
+ "tutorial/engine.rst",
+ "tutorial/dbapi_transactions.rst",
+ "tutorial/metadata.rst",
+ "tutorial/data.rst",
+ "tutorial/orm_data_manipulation.rst",
+ "tutorial/orm_related_objects.rst",
+ )
def test_orm(self):
self._run_doctest("orm/tutorial.rst")
@@ -93,6 +106,12 @@ class DocTest(fixtures.TestBase):
def test_core(self):
self._run_doctest("core/tutorial.rst")
+ def test_core_operators(self):
+ self._run_doctest("core/operators.rst")
+
+ def test_orm_queryguide(self):
+ self._run_doctest("orm/queryguide.rst")
+
# unicode checker courtesy pytest
diff --git a/test/orm/test_query.py b/test/orm/test_query.py
index 63f50d4f9..8cca45b27 100644
--- a/test/orm/test_query.py
+++ b/test/orm/test_query.py
@@ -4453,19 +4453,55 @@ class YieldTest(_fixtures.FixtureTest):
except StopIteration:
pass
- def test_yield_per_and_execution_options(self):
+ def test_yield_per_and_execution_options_legacy(self):
self._eagerload_mappings()
User = self.classes.User
sess = create_session()
+
+ @event.listens_for(sess, "do_orm_execute")
+ def check(ctx):
+ eq_(ctx.load_options._yield_per, 15)
+ eq_(
+ {
+ k: v
+ for k, v in ctx.execution_options.items()
+ if not k.startswith("_")
+ },
+ {"max_row_buffer": 15, "stream_results": True, "foo": "bar"},
+ )
+
q = sess.query(User).yield_per(15)
q = q.execution_options(foo="bar")
- assert q.load_options._yield_per
- eq_(
- q._execution_options,
- {"stream_results": True, "foo": "bar", "max_row_buffer": 15},
- )
+
+ q.all()
+
+ def test_yield_per_and_execution_options(self):
+ self._eagerload_mappings()
+
+ User = self.classes.User
+
+ sess = create_session()
+
+ @event.listens_for(sess, "do_orm_execute")
+ def check(ctx):
+ eq_(ctx.load_options._yield_per, 15)
+ eq_(
+ {
+ k: v
+ for k, v in ctx.execution_options.items()
+ if not k.startswith("_")
+ },
+ {
+ "max_row_buffer": 15,
+ "stream_results": True,
+ "yield_per": 15,
+ },
+ )
+
+ stmt = select(User).execution_options(yield_per=15)
+ sess.execute(stmt)
def test_no_joinedload_opt(self):
self._eagerload_mappings()
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index d3f8b6a9f..8e5f4a43a 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -1092,6 +1092,25 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
"SELECT NOT (NOT (EXISTS (SELECT 1))) AS anon_1",
)
+ def test_exists_method(self):
+ subq = (
+ select(func.count(table2.c.otherid))
+ .where(table2.c.otherid == table1.c.myid)
+ .correlate(table1)
+ .group_by(table2.c.otherid)
+ .having(func.count(table2.c.otherid) > 1)
+ .exists()
+ )
+
+ self.assert_compile(
+ table1.select().where(subq),
+ "SELECT mytable.myid, mytable.name, mytable.description "
+ "FROM mytable WHERE EXISTS (SELECT count(myothertable.otherid) "
+ "AS count_1 FROM myothertable WHERE myothertable.otherid = "
+ "mytable.myid GROUP BY myothertable.otherid "
+ "HAVING count(myothertable.otherid) > :count_2)",
+ )
+
def test_where_subquery(self):
s = (
select(addresses.c.street)
@@ -1693,6 +1712,15 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
"SELECT mytable.myid FROM mytable",
)
+ def test_where_multiple(self):
+ self.assert_compile(
+ select(table1.c.myid).where(
+ table1.c.myid == 12, table1.c.name == "foobar"
+ ),
+ "SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1 "
+ "AND mytable.name = :name_1",
+ )
+
def test_order_by_nulls(self):
self.assert_compile(
table2.select().order_by(
@@ -5084,6 +5112,12 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL):
select(t2, s1.correlate(t2).scalar_subquery())
)
+ def test_correlate_semiauto_column_correlate_from_subq(self):
+ t1, t2, s1 = self._fixture()
+ self._assert_column_correlated(
+ select(t2, s1.scalar_subquery().correlate(t2))
+ )
+
def test_correlate_semiauto_from(self):
t1, t2, s1 = self._fixture()
self._assert_from_uncorrelated(select(t2, s1.correlate(t2).alias()))
@@ -5094,6 +5128,12 @@ class CorrelateTest(fixtures.TestBase, AssertsCompiledSQL):
select(t2).having(t2.c.a == s1.correlate(t2).scalar_subquery())
)
+ def test_correlate_semiauto_having_from_subq(self):
+ t1, t2, s1 = self._fixture()
+ self._assert_having_correlated(
+ select(t2).having(t2.c.a == s1.scalar_subquery().correlate(t2))
+ )
+
def test_correlate_except_inclusion_where(self):
t1, t2, s1 = self._fixture()
self._assert_where_correlated(
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 980e2886a..b2dae4b22 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -741,7 +741,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
),
(
Table("bar", MetaData(), Column("x", String)),
- "Table('bar', MetaData(bind=None), "
+ "Table('bar', MetaData(), "
"Column('x', String(), table=<bar>), schema=None)",
),
(
@@ -4138,13 +4138,13 @@ class CatchAllEventsTest(fixtures.RemovesEvents, fixtures.TestBase):
"Column->t1",
"ForeignKeyConstraint->Table",
"ForeignKeyConstraint->t1",
- "Table->MetaData(bind=None)",
+ "Table->MetaData()",
"Table->MetaData",
"PrimaryKeyConstraint->Table",
"PrimaryKeyConstraint->t2",
"Column->Table",
"Column->t2",
- "Table->MetaData(bind=None)",
+ "Table->MetaData()",
],
)