File: test_deprecations.py

package info (click to toggle)
sqlalchemy 1.4.46%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,444 kB
  • sloc: python: 341,434; ansic: 1,760; makefile: 226; xml: 17; sh: 7
file content (57 lines) | stat: -rw-r--r-- 1,709 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from sqlalchemy import Integer
from sqlalchemy import testing
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import registry
from sqlalchemy.orm import Session
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
from sqlalchemy.testing.schema import Column


class BoundMetadataDeclarativeTest(fixtures.MappedTest):
    def test_bound_declarative_base(self):
        with testing.expect_deprecated(
            "The ``bind`` argument to declarative_base"
        ):
            Base = declarative_base(testing.db)

        class User(Base):
            __tablename__ = "user"
            id = Column(Integer, primary_key=True)

        s = Session()

        with testing.expect_deprecated_20(
            "This Session located a target engine via bound metadata"
        ):
            is_(s.get_bind(User), testing.db)

    def test_bound_cls_registry_base(self):
        reg = registry(_bind=testing.db)

        Base = reg.generate_base()

        class User(Base):
            __tablename__ = "user"
            id = Column(Integer, primary_key=True)

        s = Session()
        with testing.expect_deprecated_20(
            "This Session located a target engine via bound metadata"
        ):
            is_(s.get_bind(User), testing.db)

    def test_bound_cls_registry_decorated(self):
        reg = registry(_bind=testing.db)

        @reg.mapped
        class User(object):
            __tablename__ = "user"
            id = Column(Integer, primary_key=True)

        s = Session()

        with testing.expect_deprecated_20(
            "This Session located a target engine via bound metadata"
        ):
            is_(s.get_bind(User), testing.db)