def test_attribute_assignment(self): u = Unpacker({'a': 2, 'b': 3}) u.a = 45 u.b = 67 self.assertEqual(u.a, 45) self.assertEqual(u.b, 67) self.assertEqual(u['a'], 45) self.assertEqual(u['b'], 67)
def test_multiple_assignment(self): u = Unpacker(OrderedDict([('a', 12), ('c', 13)])) a, c = u self.assertEqual(a, u.a) self.assertEqual(c, u.c) u.b = 14 self.assertEqual(u['b'], 14) a, c, b = u self.assertEqual(a, u.a) self.assertEqual(c, u.c) self.assertEqual(b, u.b)
def test_multiple_key_return(self): u = Unpacker({'a': 2, 'c': 3}) self.assertEqual(u['a', 'c'], (2, 3)) u.b = 4 self.assertEqual(u['b', 'c'], (4, 3)) u['b', 'a', 'c'] = (5, 6, 7) self.assertEqual(u['a'], 6) self.assertEqual(u['c'], 7) self.assertEqual(u['b'], 5) u['a', 'e'] = 100, 300 u['b', 'c'] = (n**2 for n in [2, 3]) self.assertEqual(u['a'], 100) self.assertEqual(u['e'], 300) self.assertEqual(u['b'], 4) self.assertEqual(u['c'], 9) with self.assertRaises(Exception): # ValueError preferably u['b', 'a', 'c'] = (5, 6) with self.assertRaises(Exception): # ValueError preferably u['b', 'a'] = (5, 6, 7)