Skip to content

Commit 6c726f8

Browse files
author
Mehdi
committed
add tests
1 parent fe87ac0 commit 6c726f8

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

test/test-data/sqlalchemy-plugin-features.test

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,93 @@ class M2(M1):
273273
Base = declarative_base(cls=(M1, M2)) # E: Not able to calculate MRO for declarative base
274274
reveal_type(Base) # E: Revealed type is 'Any'
275275
[out]
276+
277+
[case testRelationshipIsGuessed]
278+
from sqlalchemy import Column, Integer, String, ForeignKey
279+
from sqlalchemy.orm import relationship
280+
from sqlalchemy.ext.declarative import declarative_base
281+
282+
Base = declarative_base()
283+
284+
class Parent(Base):
285+
__tablename__ = 'parents'
286+
id = Column(Integer, primary_key=True)
287+
name = Column(String)
288+
289+
children = relationship("Child")
290+
291+
class Child(Base):
292+
__tablename__ = 'children'
293+
id = Column(Integer, primary_key=True)
294+
name = Column(String)
295+
parent_id = Column(Integer, ForeignKey(Parent.id))
296+
297+
parent = relationship(Parent)
298+
299+
child: Child
300+
parent: Parent
301+
302+
reveal_type(child.parent) # E: Revealed type is 'main.Parent*'
303+
reveal_type(parent.children) # E: Revealed type is 'typing.Iterable*[main.Child]'
304+
305+
[out]
306+
307+
[case testRelationshipIsGuessed2]
308+
from sqlalchemy import Column, Integer, String, ForeignKey
309+
from sqlalchemy.orm import relationship
310+
from sqlalchemy.ext.declarative import declarative_base
311+
312+
Base = declarative_base()
313+
314+
class Parent(Base):
315+
__tablename__ = 'parents'
316+
id = Column(Integer, primary_key=True)
317+
name = Column(String)
318+
319+
children = relationship("Child")
320+
321+
class Child(Base):
322+
__tablename__ = 'children'
323+
id = Column(Integer, primary_key=True)
324+
name = Column(String)
325+
parent_id = Column(Integer, ForeignKey("parents.id"))
326+
327+
parent = relationship(Parent)
328+
329+
child: Child
330+
parent: Parent
331+
332+
reveal_type(child.parent) # E: Revealed type is 'main.Parent*'
333+
reveal_type(parent.children) # E: Revealed type is 'typing.Iterable*[main.Child]'
334+
335+
[out]
336+
337+
[case testRelationshipIsGuessed3]
338+
from sqlalchemy import Column, Integer, String, ForeignKey
339+
from sqlalchemy.orm import relationship
340+
from sqlalchemy.ext.declarative import declarative_base
341+
342+
Base = declarative_base()
343+
344+
class Parent(Base):
345+
__tablename__ = 'parents'
346+
id = Column(Integer, primary_key=True)
347+
name = Column(String)
348+
349+
children = relationship("Child")
350+
351+
class Child(Base):
352+
__tablename__ = 'children'
353+
id = Column(Integer, primary_key=True)
354+
name = Column(String)
355+
parent_id = Column(Integer, ForeignKey("other_parents.id"))
356+
357+
parent = relationship(Parent)
358+
359+
child: Child
360+
parent: Parent
361+
362+
reveal_type(child.parent) # E: Revealed type is 'main.Parent*'
363+
reveal_type(parent.children) # E: Revealed type is 'main.Child*'
364+
365+
[out]

0 commit comments

Comments
 (0)