MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_pickled_rows

Method test_pickled_rows

test/sql/test_resultset.py:459–514  ·  view source on GitHub ↗
(self, connection, use_pickle, use_labels)

Source from the content-addressed store, hash-verified

457 @testing.variation("use_pickle", [True, False])
458 @testing.variation("use_labels", [True, False])
459 def test_pickled_rows(self, connection, use_pickle, use_labels):
460 users = self.tables.users
461 addresses = self.tables.addresses
462
463 result = self._pickle_row_data(connection, use_labels)
464
465 if use_pickle:
466 result = pickle.loads(pickle.dumps(result))
467
468 eq_(result, [(7, "jack"), (8, "ed"), (9, "fred")])
469 if use_labels:
470 eq_(result[0]._mapping["users_user_id"], 7)
471 eq_(
472 list(result[0]._fields),
473 ["users_user_id", "users_user_name"],
474 )
475 else:
476 eq_(result[0]._mapping["user_id"], 7)
477 eq_(list(result[0]._fields), ["user_id", "user_name"])
478
479 eq_(result[0][0], 7)
480
481 assert_raises(
482 exc.NoSuchColumnError,
483 lambda: result[0]._mapping["fake key"],
484 )
485
486 # previously would warn
487
488 if use_pickle:
489 with expect_raises_message(
490 exc.NoSuchColumnError,
491 "Row was unpickled; lookup by ColumnElement is unsupported",
492 ):
493 result[0]._mapping[users.c.user_id]
494 else:
495 eq_(result[0]._mapping[users.c.user_id], 7)
496
497 if use_pickle:
498 with expect_raises_message(
499 exc.NoSuchColumnError,
500 "Row was unpickled; lookup by ColumnElement is unsupported",
501 ):
502 result[0]._mapping[users.c.user_name]
503 else:
504 eq_(result[0]._mapping[users.c.user_name], "jack")
505
506 assert_raises(
507 exc.NoSuchColumnError,
508 lambda: result[0]._mapping[addresses.c.user_id],
509 )
510
511 assert_raises(
512 exc.NoSuchColumnError,
513 lambda: result[0]._mapping[addresses.c.address_id],
514 )
515
516 @testing.variation("use_labels", [True, False])

Callers

nothing calls this directly

Calls 6

_pickle_row_dataMethod · 0.95
eq_Function · 0.90
assert_raisesFunction · 0.90
expect_raises_messageFunction · 0.90
loadsMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected