MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_create_on_set_none

Method test_create_on_set_none

test/ext/test_associationproxy.py:1181–1222  ·  view source on GitHub ↗
(
        self, create_on_none, specify_creator, decl_base
    )

Source from the content-addressed store, hash-verified

1179 @testing.variation("create_on_none", [True, False])
1180 @testing.variation("specify_creator", [True, False])
1181 def test_create_on_set_none(
1182 self, create_on_none, specify_creator, decl_base
1183 ):
1184 class A(decl_base):
1185 __tablename__ = "a"
1186 id = mapped_column(Integer, primary_key=True)
1187 b_id = mapped_column(ForeignKey("b.id"))
1188 b = relationship("B")
1189
1190 if specify_creator:
1191 b_data = association_proxy(
1192 "b",
1193 "data",
1194 create_on_none_assignment=bool(create_on_none),
1195 creator=lambda data: B(data=data),
1196 )
1197 else:
1198 b_data = association_proxy(
1199 "b", "data", create_on_none_assignment=bool(create_on_none)
1200 )
1201
1202 class B(decl_base):
1203 __tablename__ = "b"
1204 id = mapped_column(Integer, primary_key=True)
1205 data = mapped_column(String)
1206
1207 def __init__(self, data=None):
1208 self.data = data
1209
1210 a1 = A()
1211 is_none(a1.b)
1212 a1.b_data = None
1213
1214 if create_on_none:
1215 is_not_none(a1.b)
1216 else:
1217 is_none(a1.b)
1218
1219 a1.b_data = "data"
1220
1221 a1.b_data = None
1222 is_not_none(a1.b)
1223
1224 @testing.provide_metadata
1225 def test_empty_scalars(self):

Callers

nothing calls this directly

Calls 3

is_noneFunction · 0.90
is_not_noneFunction · 0.90
AClass · 0.70

Tested by

no test coverage detected