MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_changes_reset

Method test_changes_reset

test/orm/test_events.py:2909–2942  ·  view source on GitHub ↗

test the contract of load/refresh such that history is reset. This has never been an official contract but we are testing it here to ensure it is maintained given the loading performance enhancements.

(self)

Source from the content-addressed store, hash-verified

2907 eq_(canary, [])
2908
2909 def test_changes_reset(self):
2910 """test the contract of load/refresh such that history is reset.
2911
2912 This has never been an official contract but we are testing it
2913 here to ensure it is maintained given the loading performance
2914 enhancements.
2915
2916 """
2917 User = self.classes.User
2918
2919 @event.listens_for(User, "load")
2920 def canary1(obj, context):
2921 obj.name = "new name!"
2922
2923 @event.listens_for(User, "refresh")
2924 def canary2(obj, context, props):
2925 obj.name = "refreshed name!"
2926
2927 sess = fixture_session()
2928 u1 = User(name="u1")
2929 sess.add(u1)
2930 sess.commit()
2931 sess.close()
2932
2933 u1 = sess.query(User).first()
2934 eq_(attributes.get_history(u1, "name"), ((), ["new name!"], ()))
2935 assert "name" not in attributes.instance_state(u1).committed_state
2936 assert u1 not in sess.dirty
2937
2938 sess.expire(u1)
2939 u1.id
2940 eq_(attributes.get_history(u1, "name"), ((), ["refreshed name!"], ()))
2941 assert "name" not in attributes.instance_state(u1).committed_state
2942 assert u1 in sess.dirty
2943
2944 def test_repeated_rows(self):
2945 User = self.classes.User

Callers

nothing calls this directly

Calls 10

fixture_sessionFunction · 0.90
eq_Function · 0.90
UserClass · 0.70
addMethod · 0.45
commitMethod · 0.45
closeMethod · 0.45
firstMethod · 0.45
queryMethod · 0.45
get_historyMethod · 0.45
expireMethod · 0.45

Tested by

no test coverage detected