def test_getitem(self): d = Data() d.a = 1 d.a_a = 2 self.assertEqual(d['a'], d.a) d.select('a') self.assertEqual(d['a'], d.a)
def test_getattr(self): d = Data() d.a = 1 d.a_a = 2 self.assertEqual(d.a, 1) d.select('a') self.assertEqual(d.a, 2)
def test_select(self): d = Data() d.a = 1 d.select('b') d.a = 2 self.assertEqual(d.a, 2) d.select() self.assertEqual(d.a, 1)
def test_setitem(self): d = Data() d['a'] = 1 d.select('a') d['a'] = 2 self.assertEqual(d['a'], 2) d.select('') self.assertEqual(d['a'], 1)
def test_keys(self): d = Data() d.a = 1 d.a_b = 2 self.assertEqual(len(d.keys()), 2) d.select('a') res = d.keys() self.assertEqual(len(res), 1) self.assertEqual(res[0], 'b')
def test_get(self): d = Data() d.a = 1 d.b = 2 d.a_a = 3 self.assertEqual(d.get('a', 0), 1) self.assertEqual(d.get('c', 0), 0) d.select('a') self.assertEqual(d.get('a', 0), 3) self.assertEqual(d.get('b', 0), 0)
def test_history(self): d = Data() d.history['a'] = {} d.a = 1 self.assertEqual(d.history['a'][-1][1], 1) d.select('a') d.a = 0 d.history['a_a'] = {} d.a = 2 self.assertEqual(d.history['a_a'][-1][1], 2)
def test_make_key(self): d = Data() self.assertEqual(d.make_key('a'), 'a') d.select('s') self.assertEqual(d.make_key('a'), 's_a')
def test_get_prefix(self): d = Data() self.assertEqual(d.get_prefix(), '') d.select('a') self.assertEqual(d.get_prefix(), 'a_')