本文整理汇总了Python中tcms.core.db.GroupByResult.get方法的典型用法代码示例。如果您正苦于以下问题:Python GroupByResult.get方法的具体用法?Python GroupByResult.get怎么用?Python GroupByResult.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tcms.core.db.GroupByResult
的用法示例。
在下文中一共展示了GroupByResult.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GroupByResultDictLikeTest
# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import get [as 别名]
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)
示例2: GroupByResultDictLikeTest
# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import get [as 别名]
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)