MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / test_pickled_rows

Method test_pickled_rows

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

Source from the content-addressed store, hash-verified

511 @testing.variation("use_pickle", [True, False])
512 @testing.variation("use_labels", [True, False])
513 def test_pickled_rows(self, connection, use_pickle, use_labels):
514 users = self.tables.users
515 addresses = self.tables.addresses
516
517 result = self._pickle_row_data(connection, use_labels)
518
519 if use_pickle:
520 result = pickle.loads(pickle.dumps(result))
521
522 eq_(result, [(7, "jack"), (8, "ed"), (9, "fred")])
523 if use_labels:
524 eq_(result[0]._mapping["users_user_id"], 7)
525 eq_(
526 list(result[0]._fields),
527 ["users_user_id", "users_user_name"],
528 )
529 else:
530 eq_(result[0]._mapping["user_id"], 7)
531 eq_(list(result[0]._fields), ["user_id", "user_name"])
532
533 eq_(result[0][0], 7)
534
535 assert_raises(
536 exc.NoSuchColumnError,
537 lambda: result[0]._mapping["fake key"],
538 )
539
540 # previously would warn
541
542 if use_pickle:
543 with expect_raises_message(
544 exc.NoSuchColumnError,
545 "Row was unpickled; lookup by ColumnElement is unsupported",
546 ):
547 result[0]._mapping[users.c.user_id]
548 else:
549 eq_(result[0]._mapping[users.c.user_id], 7)
550
551 if use_pickle:
552 with expect_raises_message(
553 exc.NoSuchColumnError,
554 "Row was unpickled; lookup by ColumnElement is unsupported",
555 ):
556 result[0]._mapping[users.c.user_name]
557 else:
558 eq_(result[0]._mapping[users.c.user_name], "jack")
559
560 assert_raises(
561 exc.NoSuchColumnError,
562 lambda: result[0]._mapping[addresses.c.user_id],
563 )
564
565 assert_raises(
566 exc.NoSuchColumnError,
567 lambda: result[0]._mapping[addresses.c.address_id],
568 )
569
570 @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