Skip to content

Commit fd2d917

Browse files
Run test files from stubs directory (#92)
1 parent e6ae4cc commit fd2d917

File tree

6 files changed

+169
-1
lines changed

6 files changed

+169
-1
lines changed

test/files/.keep

Whitespace-only changes.

test/files/column_arguments.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from sqlalchemy import Column
2+
from sqlalchemy import ForeignKey
3+
from sqlalchemy import Integer
4+
from sqlalchemy import Sequence
5+
from sqlalchemy import String
6+
from sqlalchemy.orm import Mapped
7+
from sqlalchemy.orm import registry
8+
9+
reg: registry = registry()
10+
11+
12+
@reg.mapped
13+
class InferredNames:
14+
__tablename__ = "infered"
15+
16+
# Instantiated type
17+
id = Column(Integer(), primary_key=True)
18+
19+
# Non-instantiated type
20+
name = Column(String, nullable=False)
21+
22+
# SchemaItem
23+
foreign: Mapped[int] = Column(ForeignKey("infered.id"))
24+
25+
# SchemaItem without type
26+
foreign1: Mapped[int] = Column(ForeignKey("infered.id"))
27+
28+
# SchemaItem without type
29+
foreign2: Mapped[int] = Column(Integer, ForeignKey("infered.id"))
30+
31+
# sequence
32+
seq = Column(Integer, Sequence("my_sequence"), primary_key=True)
33+
34+
35+
@reg.mapped
36+
class ExplicitNames:
37+
__tablename__ = "explicit"
38+
39+
# Instantiated type
40+
id = Column("id", Integer(), primary_key=True)
41+
42+
# Non-instantiated type
43+
name = Column("name", String, nullable=False)
44+
45+
# SchemaItem without type
46+
foreign1: int = Column("foreign", ForeignKey("infered.id"))
47+
48+
# SchemaItem without type
49+
foreign2: int = Column("foreign", Integer, ForeignKey("infered.id"))
50+
51+
# sequence
52+
seq = Column(Integer, Sequence("my_sequence"), primary_key=True)

test/files/column_arguments2.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from sqlalchemy import Column
2+
from sqlalchemy import ForeignKey
3+
from sqlalchemy import Integer
4+
from sqlalchemy import String
5+
6+
Column("name", Integer, index=True)
7+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "None", "str" # noqa E501
8+
Column(None, name="name")
9+
Column(Integer, name="name", index=True)
10+
Column("name", ForeignKey("a.id"))
11+
Column(ForeignKey("a.id"), type_=None, index=True)
12+
Column(ForeignKey("a.id"), name="name", type_=Integer())
13+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "str", "None" # noqa E501
14+
Column("name", None)
15+
Column("name", index=True)
16+
Column(ForeignKey("a.id"), name="name", index=True)
17+
Column(type_=None, index=True)
18+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "None", "ForeignKey" # noqa E501
19+
Column(None, ForeignKey("a.id"))
20+
Column("name")
21+
Column(name="name", type_=None, index=True)
22+
Column(ForeignKey("a.id"), name="name", type_=None)
23+
Column(Integer)
24+
Column(ForeignKey("a.id"), type_=Integer())
25+
Column("name", Integer, ForeignKey("a.id"), index=True)
26+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "str", "None", "ForeignKey", "bool # noqa E501
27+
Column("name", None, ForeignKey("a.id"), index=True)
28+
Column(ForeignKey("a.id"), index=True)
29+
Column("name", Integer)
30+
Column(Integer, name="name")
31+
Column(Integer, ForeignKey("a.id"), name="name", index=True)
32+
Column(ForeignKey("a.id"), type_=None)
33+
Column(ForeignKey("a.id"), name="name")
34+
Column(name="name", index=True)
35+
Column(type_=None)
36+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "None", "bool" # noqa E501
37+
Column(None, index=True)
38+
Column(name="name", type_=None)
39+
Column(type_=Integer(), index=True)
40+
Column("name", Integer, ForeignKey("a.id"))
41+
Column(name="name", type_=Integer(), index=True)
42+
Column(Integer, ForeignKey("a.id"), index=True)
43+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "str", "None", "ForeignKey" # noqa E501
44+
Column("name", None, ForeignKey("a.id"))
45+
Column(index=True)
46+
Column("name", type_=None, index=True)
47+
Column("name", ForeignKey("a.id"), type_=Integer(), index=True)
48+
Column(ForeignKey("a.id"))
49+
Column(Integer, ForeignKey("a.id"))
50+
Column(Integer, ForeignKey("a.id"), name="name")
51+
Column("name", ForeignKey("a.id"), index=True)
52+
Column("name", type_=Integer(), index=True)
53+
Column(ForeignKey("a.id"), name="name", type_=Integer(), index=True)
54+
Column(name="name")
55+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "str", "None", "bool" # noqa E501
56+
Column("name", None, index=True)
57+
Column("name", ForeignKey("a.id"), type_=None, index=True)
58+
Column("name", type_=Integer())
59+
# EXPECTED_MYPY: No overload variant of "Column" matches argument type "None"
60+
Column(None)
61+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "None", "ForeignKey", "bool" # noqa E501
62+
Column(None, ForeignKey("a.id"), index=True)
63+
Column("name", ForeignKey("a.id"), type_=None)
64+
Column(type_=Integer())
65+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "None", "ForeignKey", "str", "bool" # noqa E501
66+
Column(None, ForeignKey("a.id"), name="name", index=True)
67+
Column(Integer, index=True)
68+
Column(ForeignKey("a.id"), name="name", type_=None, index=True)
69+
Column(ForeignKey("a.id"), type_=Integer(), index=True)
70+
Column(name="name", type_=Integer())
71+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "None", "str", "bool" # noqa E501
72+
Column(None, name="name", index=True)
73+
Column()
74+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "None", "ForeignKey", "str" # noqa E501
75+
Column(None, ForeignKey("a.id"), name="name")
76+
Column("name", type_=None)
77+
Column("name", ForeignKey("a.id"), type_=Integer())
78+
79+
80+
# We are no longer able to detect there, as the kwargs must stay in place.
81+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "Type[Integer]", "ForeignKey", "Type[String]" # noqa E501
82+
Column(Integer, ForeignKey("a.id"), type_=String)
83+
84+
# EXPECTED_MYPY: No overload variant of "Column" matches argument types "str", "ForeignKey", "str" # noqa E501
85+
Column("name", ForeignKey("a.id"), name="String")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from datetime import datetime
2+
3+
from sqlalchemy import Column
4+
from sqlalchemy import create_engine
5+
from sqlalchemy import DateTime
6+
from sqlalchemy import Integer
7+
from sqlalchemy.orm import Mapped
8+
from sqlalchemy.orm import registry
9+
from sqlalchemy.orm import Session
10+
from sqlalchemy.sql.functions import now
11+
12+
mapper_registry: registry = registry()
13+
e = create_engine("sqlite:///database.db", echo=True)
14+
15+
16+
@mapper_registry.mapped
17+
class A:
18+
__tablename__ = "a"
19+
id = Column(Integer, primary_key=True)
20+
date_time: Mapped[datetime] = Column(DateTime())
21+
date_time2 = Column(DateTime())
22+
23+
24+
mapper_registry.metadata.create_all(e)
25+
26+
with Session(e) as s:
27+
a = A()
28+
a.date_time = now()
29+
a.date_time2 = now()
30+
s.add(a)
31+
s.commit()

test/incremental/.keep

Whitespace-only changes.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ commands_pre=
2929

3030

3131
commands =
32-
pytest {env:WORKERS} -v test/ext/mypy/test_mypy_plugin_py3k.py {posargs}
32+
pytest {env:WORKERS} --mypy-extra-test-path={toxinidir}/test/ -v test/ext/mypy/test_mypy_plugin_py3k.py {posargs}

0 commit comments

Comments
 (0)