Skip to content

Commit 605a997

Browse files
author
Mehdi
committed
add tests
1 parent d5f2ede commit 605a997

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
@@ -280,3 +280,93 @@ class M2(M1):
280280
Base = declarative_base(cls=(M1, M2)) # E: Not able to calculate MRO for declarative base
281281
reveal_type(Base) # E: Revealed type is 'Any'
282282
[out]
283+
284+
[case testRelationshipIsGuessed]
285+
from sqlalchemy import Column, Integer, String, ForeignKey
286+
from sqlalchemy.orm import relationship
287+
from sqlalchemy.ext.declarative import declarative_base
288+
289+
Base = declarative_base()
290+
291+
class Parent(Base):
292+
__tablename__ = 'parents'
293+
id = Column(Integer, primary_key=True)
294+
name = Column(String)
295+
296+
children = relationship("Child")
297+
298+
class Child(Base):
299+
__tablename__ = 'children'
300+
id = Column(Integer, primary_key=True)
301+
name = Column(String)
302+
parent_id = Column(Integer, ForeignKey(Parent.id))
303+
304+
parent = relationship(Parent)
305+
306+
child: Child
307+
parent: Parent
308+
309+
reveal_type(child.parent) # E: Revealed type is 'main.Parent*'
310+
reveal_type(parent.children) # E: Revealed type is 'typing.Iterable*[main.Child]'
311+
312+
[out]
313+
314+
[case testRelationshipIsGuessed2]
315+
from sqlalchemy import Column, Integer, String, ForeignKey
316+
from sqlalchemy.orm import relationship
317+
from sqlalchemy.ext.declarative import declarative_base
318+
319+
Base = declarative_base()
320+
321+
class Parent(Base):
322+
__tablename__ = 'parents'
323+
id = Column(Integer, primary_key=True)
324+
name = Column(String)
325+
326+
children = relationship("Child")
327+
328+
class Child(Base):
329+
__tablename__ = 'children'
330+
id = Column(Integer, primary_key=True)
331+
name = Column(String)
332+
parent_id = Column(Integer, ForeignKey("parents.id"))
333+
334+
parent = relationship(Parent)
335+
336+
child: Child
337+
parent: Parent
338+
339+
reveal_type(child.parent) # E: Revealed type is 'main.Parent*'
340+
reveal_type(parent.children) # E: Revealed type is 'typing.Iterable*[main.Child]'
341+
342+
[out]
343+
344+
[case testRelationshipIsGuessed3]
345+
from sqlalchemy import Column, Integer, String, ForeignKey
346+
from sqlalchemy.orm import relationship
347+
from sqlalchemy.ext.declarative import declarative_base
348+
349+
Base = declarative_base()
350+
351+
class Parent(Base):
352+
__tablename__ = 'parents'
353+
id = Column(Integer, primary_key=True)
354+
name = Column(String)
355+
356+
children = relationship("Child")
357+
358+
class Child(Base):
359+
__tablename__ = 'children'
360+
id = Column(Integer, primary_key=True)
361+
name = Column(String)
362+
parent_id = Column(Integer, ForeignKey("other_parents.id"))
363+
364+
parent = relationship(Parent)
365+
366+
child: Child
367+
parent: Parent
368+
369+
reveal_type(child.parent) # E: Revealed type is 'main.Parent*'
370+
reveal_type(parent.children) # E: Revealed type is 'main.Child*'
371+
372+
[out]

0 commit comments

Comments
 (0)