MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_raw_tuple_params

Method test_raw_tuple_params

test/engine/test_execute.py:572–620  ·  view source on GitHub ↗

test #7820 There was an apparent improvement in the distill params methodology used in exec_driver_sql which allows raw tuples to pass through. In 1.4 there seems to be a _distill_cursor_params() function that says it can handle this kind of parameter, but it isn't

(self, connection)

Source from the content-addressed store, hash-verified

570 ]
571
572 def test_raw_tuple_params(self, connection):
573 """test #7820
574
575 There was an apparent improvement in the distill params
576 methodology used in exec_driver_sql which allows raw tuples to
577 pass through. In 1.4 there seems to be a _distill_cursor_params()
578 function that says it can handle this kind of parameter, but it isn't
579 used and when I tried to substitute it in for exec_driver_sql(),
580 things still fail.
581
582 In any case, add coverage here for the use case of passing
583 direct tuple params to exec_driver_sql including as the first
584 param, to note that it isn't mis-interpreted the way it is
585 in 1.x.
586
587 """
588
589 with patch.object(connection.dialect, "do_execute") as do_exec:
590 connection.exec_driver_sql(
591 "UPDATE users SET user_name = 'query_one' WHERE "
592 "user_id = %s OR user_id IN %s",
593 (3, (1, 2)),
594 )
595
596 connection.exec_driver_sql(
597 "UPDATE users SET user_name = 'query_two' WHERE "
598 "user_id IN %s OR user_id = %s",
599 ((1, 2), 3),
600 )
601
602 eq_(
603 do_exec.mock_calls,
604 [
605 call(
606 mock.ANY,
607 "UPDATE users SET user_name = 'query_one' "
608 "WHERE user_id = %s OR user_id IN %s",
609 connection.dialect.execute_sequence_format((3, (1, 2))),
610 mock.ANY,
611 ),
612 call(
613 mock.ANY,
614 "UPDATE users SET user_name = 'query_two' "
615 "WHERE user_id IN %s OR user_id = %s",
616 connection.dialect.execute_sequence_format(((1, 2), 3)),
617 mock.ANY,
618 ),
619 ],
620 )
621
622 def test_non_dict_mapping(self, connection):
623 """ensure arbitrary Mapping works for execute()"""

Callers

nothing calls this directly

Calls 4

eq_Function · 0.90
callFunction · 0.85
objectMethod · 0.80
exec_driver_sqlMethod · 0.45

Tested by

no test coverage detected