summaryrefslogtreecommitdiff
path: root/test/base/test_examples.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-02-02 14:38:37 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-02-06 11:08:50 -0500
commit3c6acaba017ef0a0b667864199f103f5eb6f79f9 (patch)
treec8d1ea054d5db18e0d56e2741aa9c75b651af959 /test/base/test_examples.py
parent2459619e751f39a796bb1dd9fe75947dd0961fee (diff)
downloadsqlalchemy-3c6acaba017ef0a0b667864199f103f5eb6f79f9.tar.gz
port history meta to 2.0
first change: Reworked the :ref:`examples_versioned_history` to work with version 2.0, while at the same time improving the overall working of this example to use newer APIs, including a newly added hook :meth:`_orm.MapperEvents.after_mapper_constructed`. second change: Added new event hook :meth:`_orm.MapperEvents.after_mapper_constructed`, which supplies an event hook to take place right as the :class:`_orm.Mapper` object has been fully constructed, but before the :meth:`_orm.registry.configure` call has been called. This allows code that can create additional mappings and table structures based on the initial configuration of a :class:`_orm.Mapper`, which also integrates within Declarative configuration. Previously, when using Declarative, where the :class:`_orm.Mapper` object is created within the class creation process, there was no documented means of running code at this point. The change is to immediately benefit custom mapping schemes such as that of the :ref:`examples_versioned_history` example, which generate additional mappers and tables in response to the creation of mapped classes. third change: The infrequently used :attr:`_orm.Mapper.iterate_properties` attribute and :meth:`_orm.Mapper.get_property` method, which are primarily used internally, no longer implicitly invoke the :meth:`_orm.registry.configure` process. Public access to these methods is extremely rare and the only benefit to having :meth:`_orm.registry.configure` would have been allowing "backref" properties be present in these collections. In order to support the new :meth:`_orm.MapperEvents.after_mapper_constructed` event, iteration and access to the internal :class:`_orm.MapperProperty` objects is now possible without triggering an implicit configure of the mapper itself. The more-public facing route to iteration of all mapper attributes, the :attr:`_orm.Mapper.attrs` collection and similar, will still implicitly invoke the :meth:`_orm.registry.configure` step thus making backref attributes available. In all cases, the :meth:`_orm.registry.configure` is always available to be called directly. fourth change: Fixed obscure ORM inheritance issue caused by :ticket:`8705` where some scenarios of inheriting mappers that indicated groups of columns from the local table and the inheriting table together under a :func:`_orm.column_property` would nonetheless warn that properties of the same name were being combined implicitly. Fixes: #9220 Fixes: #9232 Change-Id: Id335b8e8071c8ea509c057c389df9dcd2059437d
Diffstat (limited to 'test/base/test_examples.py')
-rw-r--r--test/base/test_examples.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/base/test_examples.py b/test/base/test_examples.py
new file mode 100644
index 000000000..50f0c01f2
--- /dev/null
+++ b/test/base/test_examples.py
@@ -0,0 +1,23 @@
+import os
+import sys
+
+from sqlalchemy.testing import fixtures
+
+
+here = os.path.dirname(__file__)
+sqla_base = os.path.normpath(os.path.join(here, "..", ".."))
+
+
+sys.path.insert(0, sqla_base)
+
+test_versioning = __import__(
+ "examples.versioned_history.test_versioning"
+).versioned_history.test_versioning
+
+
+class VersionedRowsTest(
+ test_versioning.TestVersioning,
+ fixtures.RemoveORMEventsGlobally,
+ fixtures.TestBase,
+):
+ pass