diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/orm/test_options.py | 65 | ||||
| -rw-r--r-- | test/orm/test_pickled.py | 1 |
2 files changed, 49 insertions, 17 deletions
diff --git a/test/orm/test_options.py b/test/orm/test_options.py index 709822080..e74ffeced 100644 --- a/test/orm/test_options.py +++ b/test/orm/test_options.py @@ -1,3 +1,5 @@ +import pickle + import sqlalchemy as sa from sqlalchemy import Column from sqlalchemy import ForeignKey @@ -5,6 +7,7 @@ from sqlalchemy import inspect from sqlalchemy import Integer from sqlalchemy import select from sqlalchemy import String +from sqlalchemy import Table from sqlalchemy import testing from sqlalchemy.orm import aliased from sqlalchemy.orm import attributes @@ -1241,31 +1244,61 @@ class OptionsNoPropTestInh(_Polymorphic): eq_(loader.path, orig_path) -class PickleTest(PathTest, QueryTest): - def _option_fixture(self, *arg): - return strategy_options._generate_from_keys( - strategy_options.Load.joinedload, arg, True, {} +class PickleTest(fixtures.MappedTest): + @classmethod + def define_tables(cls, metadata): + Table( + "users", + metadata, + Column("id", Integer, primary_key=True), + Column("name", String(30), nullable=False), + ) + Table( + "addresses", + metadata, + Column("id", Integer, primary_key=True), + Column("user_id", None, ForeignKey("users.id")), + Column("email_address", String(50), nullable=False), + ) + + @testing.fixture + def user_address_fixture(self, registry): + from sqlalchemy.testing.pickleable import User, Address + + registry.map_imperatively( + User, + self.tables.users, + properties={"addresses": relationship(Address)}, ) + registry.map_imperatively(Address, self.tables.addresses) - def test_modern_opt_getstate(self): - User = self.classes.User + return User, Address - opt = self._option_fixture(User.addresses) + def test_slots(self, user_address_fixture): + User, Address = user_address_fixture + + opt = joinedload(User.addresses) + + assert not hasattr(opt, "__dict__") + assert not hasattr(opt.context[0], "__dict__") + + def test_pickle_relationship_loader(self, user_address_fixture): + User, Address = user_address_fixture - q1 = fixture_session().query(User).options(opt) - c1 = q1._compile_context() + for i in range(3): + opt = joinedload(User.addresses) - state = opt.__getstate__() + q1 = fixture_session().query(User).options(opt) + c1 = q1._compile_context() - opt2 = Load.__new__(Load) - opt2.__setstate__(state) + pickled = pickle.dumps(opt) - eq_(opt.__dict__, opt2.__dict__) + opt2 = pickle.loads(pickled) - q2 = fixture_session().query(User).options(opt2) - c2 = q2._compile_context() + q2 = fixture_session().query(User).options(opt2) + c2 = q2._compile_context() - eq_(c1.attributes, c2.attributes) + eq_(c1.attributes, c2.attributes) class LocalOptsTest(PathTest, QueryTest): diff --git a/test/orm/test_pickled.py b/test/orm/test_pickled.py index 8e4c6ab17..a4250e375 100644 --- a/test/orm/test_pickled.py +++ b/test/orm/test_pickled.py @@ -271,7 +271,6 @@ class PickleTest(fixtures.MappedTest): sess.add(u1) sess.commit() sess.close() - u1 = ( sess.query(User) .options( |
