File: misc.py

package info (click to toggle)
sqlalchemy 2.0.45%2Bds1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 26,868 kB
  • sloc: python: 416,938; makefile: 231; sh: 7
file content (37 lines) | stat: -rw-r--r-- 885 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
from typing import Any

from sqlalchemy import column
from sqlalchemy import ColumnElement
from sqlalchemy import Integer
from sqlalchemy import literal
from sqlalchemy import table


def test_col_accessors() -> None:
    t = table("t", column("a"), column("b"), column("c"))

    t.c.a
    t.c["a"]

    t.c[2]
    t.c[0, 1]
    t.c[0, 1, "b", "c"]
    t.c[(0, 1, "b", "c")]

    t.c[:-1]
    t.c[0:2]


def test_col_get() -> None:
    col_id = column("id", Integer)
    col_alt = column("alt", Integer)
    tbl = table("mytable", col_id)

    # EXPECTED_TYPE: ColumnClause[Any] | None
    reveal_type(tbl.c.get("id"))
    # EXPECTED_TYPE: ColumnClause[Any] | None
    reveal_type(tbl.c.get("id", None))
    # EXPECTED_TYPE: ColumnClause[Any] | ColumnClause[int]
    reveal_type(tbl.c.get("alt", col_alt))
    col: ColumnElement[Any] = tbl.c.get("foo", literal("bar"))
    print(col)