MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _load_fixtures

Method _load_fixtures

lib/sqlalchemy/testing/fixtures/sql.py:191–215  ·  view source on GitHub ↗

Insert rows as represented by the fixtures() method.

(cls)

Source from the content-addressed store, hash-verified

189
190 @classmethod
191 def _load_fixtures(cls):
192 """Insert rows as represented by the fixtures() method."""
193 headers, rows = {}, {}
194 for table, data in cls.fixtures().items():
195 if len(data) < 2:
196 continue
197 if isinstance(table, str):
198 table = cls.tables[table]
199 headers[table] = data[0]
200 rows[table] = data[1:]
201 for table, fks in sort_tables_and_constraints(
202 cls._tables_metadata.tables.values()
203 ):
204 if table is None:
205 continue
206 if table not in headers:
207 continue
208 with cls.bind.begin() as conn:
209 conn.execute(
210 table.insert(),
211 [
212 dict(zip(headers[table], column_values))
213 for column_values in rows[table]
214 ],
215 )
216
217
218class NoCache:

Callers 2

_setup_each_insertsMethod · 0.95
_setup_once_insertsMethod · 0.80

Calls 7

itemsMethod · 0.45
fixturesMethod · 0.45
valuesMethod · 0.45
beginMethod · 0.45
executeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected