def test_basics_dict(self): d = {'a': 1, 'b': 2} t = track(d) self.assertTrue(istracked(t)) self.assertTrue(t.__subject__ == d) t['b'] = [3] self.assertTrue(istracked(t['b']))
def test_basics_list(self): l = [0, 1] t = track(l) self.assertTrue(istracked(t)) self.assertTrue(t.__subject__ == l) t[1] = ['a'] self.assertTrue(istracked(t[1]))
def test_atomic_ctxtmgr_exception(self): original = {'a': {'b': 1}} call_count = 0 def cb(data): nonlocal call_count call_count += 1 t = track(copy.deepcopy(original), change_callback=cb) with self.assertRaises(RuntimeError): with atomic(t): t['a']['b'] = [2, 3] raise RuntimeError('Something failed') self.assertTrue(t['a']['b'] == 1, t['a']['b']) self.assertTrue(t == original, t) self.assertTrue(istracked(t['a'])) self.assertTrue(call_count == 0, call_count)
def test_atomic_ctxtmgr_baseline(self): t = track({'a': 1}) with atomic(t): t['a'] = { 'b': [2, 3]} self.assertTrue(t['a']['b'][1] == 3) self.assertTrue(istracked(t['a']['b']))
def test_basics_set(self): s = {'a', 'b'} t = track(s) self.assertTrue(istracked(t)) self.assertTrue(t.__subject__ == s)