class GroupByResultDictLikeTest(TestCase): '''Test dict like behaviors''' def setUp(self): self.groupby_result = GroupByResult({'total': 100}) def test_in(self): self.assert_('a' not in self.groupby_result) self.assert_('total' in self.groupby_result) def test_key(self): self.assert_(self.groupby_result.keys(), ['total']) def test_setdefault(self): ret_val = self.groupby_result.setdefault('count', {}) self.assertEqual(ret_val, {}) ret_val = self.groupby_result.setdefault('total', 200) self.assertEqual(ret_val, 100) def test_getitem(self): ret_val = self.groupby_result['total'] self.assertEqual(ret_val, 100) try: ret_val = self.groupby_result['xxx'] except KeyError: pass else: self.fail('xxx does not exist. KeyError should be raised.') def test_setitem(self): self.groupby_result['count'] = 200 self.assertEqual(self.groupby_result['count'], 200) self.groupby_result['total'] = 999 self.assertEqual(self.groupby_result['total'], 999) def test_get(self): ret_val = self.groupby_result.get('total') self.assertEqual(ret_val, 100) ret_val = self.groupby_result.get('count', 999) self.assertEqual(ret_val, 999) ret_val = self.groupby_result.get('xxx') self.assertEqual(ret_val, None) def test_len(self): self.assertEqual(len(self.groupby_result), 1) def test_del(self): self.groupby_result['count'] = 200 del self.groupby_result['total'] self.assert_('total' not in self.groupby_result) del self.groupby_result['count'] self.assert_('count' not in self.groupby_result) self.assertEqual(len(self.groupby_result), 0)
class GroupByResultDictLikeTest(unittest.TestCase): """Test dict like behaviors""" def setUp(self): self.groupby_result = GroupByResult({'total': 100}) def test_in(self): self.assert_('a' not in self.groupby_result) self.assert_('total' in self.groupby_result) def test_key(self): self.assert_(self.groupby_result.keys(), ['total']) def test_setdefault(self): ret_val = self.groupby_result.setdefault('count', {}) self.assertEqual(ret_val, {}) ret_val = self.groupby_result.setdefault('total', 200) self.assertEqual(ret_val, 100) def test_getitem(self): ret_val = self.groupby_result['total'] self.assertEqual(ret_val, 100) try: ret_val = self.groupby_result['xxx'] except KeyError: pass else: self.fail('xxx does not exist. KeyError should be raised.') def test_setitem(self): self.groupby_result['count'] = 200 self.assertEqual(self.groupby_result['count'], 200) self.groupby_result['total'] = 999 self.assertEqual(self.groupby_result['total'], 999) def test_get(self): ret_val = self.groupby_result.get('total') self.assertEqual(ret_val, 100) ret_val = self.groupby_result.get('count', 999) self.assertEqual(ret_val, 999) ret_val = self.groupby_result.get('xxx') self.assertEqual(ret_val, None) def test_len(self): self.assertEqual(len(self.groupby_result), 1) def test_del(self): self.groupby_result['count'] = 200 del self.groupby_result['total'] self.assert_('total' not in self.groupby_result) del self.groupby_result['count'] self.assert_('count' not in self.groupby_result) self.assertEqual(len(self.groupby_result), 0)
class GroupByResultDictLikeTest(unittest.TestCase): """Test dict like behaviors""" def setUp(self): self.groupby_result = GroupByResult({'total': 100}) def test_in(self): self.assertNotIn('a', self.groupby_result) self.assertIn('total', self.groupby_result) def test_key(self): self.assertTrue(self.groupby_result.keys(), ['total']) def test_setdefault(self): ret_val = self.groupby_result.setdefault('count', {}) self.assertEqual(ret_val, {}) ret_val = self.groupby_result.setdefault('total', 200) self.assertEqual(ret_val, 100) def test_setitem(self): self.groupby_result['count'] = 200 self.assertEqual(self.groupby_result['count'], 200) self.groupby_result['total'] = 999 self.assertEqual(self.groupby_result['total'], 999) def test_get(self): ret_val = self.groupby_result.get('total') self.assertEqual(ret_val, 100) ret_val = self.groupby_result.get('count', 999) self.assertEqual(ret_val, 999) ret_val = self.groupby_result.get('xxx') self.assertEqual(ret_val, None) def test_len(self): self.assertEqual(len(self.groupby_result), 1) def test_del(self): self.groupby_result['count'] = 200 del self.groupby_result['total'] self.assertNotIn('total', self.groupby_result) del self.groupby_result['count'] self.assertNotIn('count', self.groupby_result) self.assertEqual(len(self.groupby_result), 0) def test_raise_key_error(self): with self.assertRaises(KeyError): self.groupby_result['unknown_key']
class GroupByResultDictLikeTest(unittest.TestCase): """Test dict like behaviors""" def setUp(self): self.groupby_result = GroupByResult({'total': 100}) def test_in(self): self.assertNotIn('a', self.groupby_result) self.assertIn('total', self.groupby_result) def test_key(self): self.assertTrue(self.groupby_result.keys(), ['total']) def test_setdefault(self): ret_val = self.groupby_result.setdefault('count', {}) self.assertEqual(ret_val, {}) ret_val = self.groupby_result.setdefault('total', 200) self.assertEqual(ret_val, 100) def test_setitem(self): self.groupby_result['count'] = 200 self.assertEqual(self.groupby_result['count'], 200) self.groupby_result['total'] = 999 self.assertEqual(self.groupby_result['total'], 999) def test_get(self): ret_val = self.groupby_result.get('total') self.assertEqual(ret_val, 100) ret_val = self.groupby_result.get('count', 999) self.assertEqual(ret_val, 999) ret_val = self.groupby_result.get('xxx') self.assertEqual(ret_val, None) def test_len(self): self.assertEqual(len(self.groupby_result), 1) def test_del(self): self.groupby_result['count'] = 200 del self.groupby_result['total'] self.assertNotIn('total', self.groupby_result) del self.groupby_result['count'] self.assertNotIn('count', self.groupby_result) self.assertEqual(len(self.groupby_result), 0)