MCPcopy Index your code
hub / github.com/zzzeek/sqlalchemy / test_adapt_result_columns

Method test_adapt_result_columns

test/sql/test_resultset.py:2882–2929  ·  view source on GitHub ↗

test adaptation of a CursorResultMetadata to another one. This copies the _keymap from one to the other in terms of the selected columns of a target selectable. This is used by the statement caching process to reuse the CursorResultMetadata from the cached statemen

(self, connection, stmt_fn)

Source from the content-addressed store, hash-verified

2880 argnames="stmt_fn",
2881 )
2882 def test_adapt_result_columns(self, connection, stmt_fn):
2883 """test adaptation of a CursorResultMetadata to another one.
2884
2885
2886 This copies the _keymap from one to the other in terms of the
2887 selected columns of a target selectable.
2888
2889 This is used by the statement caching process to reuse the
2890 CursorResultMetadata from the cached statement against the same
2891 statement sent separately.
2892
2893 """
2894
2895 stmt1 = stmt_fn(self)
2896 stmt2 = stmt_fn(self)
2897
2898 eq_(stmt1._generate_cache_key(), stmt2._generate_cache_key())
2899
2900 column_linkage = dict(
2901 zip(stmt1.selected_columns, stmt2.selected_columns)
2902 )
2903
2904 for i in range(2):
2905 try:
2906 result = connection.execute(stmt1)
2907
2908 mock_context = Mock(
2909 compiled=result.context.compiled, invoked_statement=stmt2
2910 )
2911 existing_metadata = result._metadata
2912 adapted_metadata = existing_metadata._adapt_to_context(
2913 mock_context
2914 )
2915
2916 eq_(existing_metadata.keys, adapted_metadata.keys)
2917
2918 for k in existing_metadata._keymap:
2919 if isinstance(k, ColumnElement) and k in column_linkage:
2920 other_k = column_linkage[k]
2921 else:
2922 other_k = k
2923
2924 is_(
2925 existing_metadata._keymap[k],
2926 adapted_metadata._keymap[other_k],
2927 )
2928 finally:
2929 result.close()
2930
2931 @testing.combinations(
2932 _adapt_result_columns_fixture_one,

Callers

nothing calls this directly

Calls 6

eq_Function · 0.90
is_Function · 0.90
_adapt_to_contextMethod · 0.80
_generate_cache_keyMethod · 0.45
executeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected