当前位置: 首页>>代码示例>>Python>>正文


Python GroupByResult.iteritems方法代码示例

本文整理汇总了Python中tcms.core.db.GroupByResult.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python GroupByResult.iteritems方法的具体用法?Python GroupByResult.iteritems怎么用?Python GroupByResult.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tcms.core.db.GroupByResult的用法示例。


在下文中一共展示了GroupByResult.iteritems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GroupByResultCalculationTest

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import iteritems [as 别名]
class GroupByResultCalculationTest(TestCase):
    '''Test calculation of GroupByResult'''

    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1: GroupByResult({'a': 1,
                              'b': 2,
                              'c': 3}),
            2: GroupByResult({1: 1,
                              2: 2}),
            3: GroupByResult({'PASSED': 10,
                              'WAIVED': 20,
                              'FAILED': 30,
                              'PAUSED': 40}),
        })

    def _sample_total(self):
        return sum(count for key, count in self.groupby_result.iteritems())

    def _sample_nested_total(self):
        total = 0
        for key, nested_result in self.nested_groupby_result.iteritems():
            for n, count in nested_result.iteritems():
                total += count
        return total

    def test_total(self):
        total = self.groupby_result.total
        self.assertEqual(total, self._sample_total())

    def test_nested_total(self):
        total = self.nested_groupby_result.total
        self.assertEqual(total, self._sample_nested_total())
开发者ID:Aaln1986,项目名称:Nitrate,代码行数:41,代码来源:tests.py

示例2: GroupByResultCalculationTest

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import iteritems [as 别名]
class GroupByResultCalculationTest(unittest.TestCase):
    """Test calculation of GroupByResult"""

    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1: GroupByResult({'a': 1,
                              'b': 2,
                              'c': 3}),
            2: GroupByResult({1: 1,
                              2: 2}),
            3: GroupByResult({'PASSED': 10,
                              'WAIVED': 20,
                              'FAILED': 30,
                              'PAUSED': 40}),
        })

    def _sample_total(self):
        return sum(count for key, count in self.groupby_result.iteritems())

    def _sample_nested_total(self):
        total = 0
        for key, nested_result in self.nested_groupby_result.iteritems():
            for n, count in nested_result.iteritems():
                total += count
        return total

    def test_total(self):
        total = self.groupby_result.total
        self.assertEqual(total, self._sample_total())

    def test_nested_total(self):
        total = self.nested_groupby_result.total
        self.assertEqual(total, self._sample_nested_total())

    def test_get_total_after_add_data_based_on_empty_initial_data(self):
        result = GroupByResult()
        result['RUNNING'] = 100
        result['PASSED'] = 100
        self.assertEqual(200, result.total)

    def test_get_total_after_add_data_based_on_initial_data(self):
        result = GroupByResult({'FAILED': 20})
        result['RUNNING'] = 100
        result['PASSED'] = 100
        self.assertEqual(220, result.total)

    def test_total_is_updated_after_del_item(self):
        result = GroupByResult({'FAILED': 20, 'RUNNING': 20, 'PASSED': 10})
        del result['RUNNING']
        self.assertEqual(30, result.total)

    def test_total_is_updated_after_del_item_several_times(self):
        result = GroupByResult({'FAILED': 20, 'RUNNING': 20, 'PASSED': 10})
        del result['RUNNING']
        del result['FAILED']
        self.assertEqual(10, result.total)

    def test_percentage(self):
        result = GroupByResult({
            'IDLE': 20,
            'PASSED': 20,
            'RUNNING': 10,
        })
        self.assertEqual(40.0, result.PASSED_percent)

    def test_zero_percentage(self):
        result = GroupByResult({})
        self.assertEqual(.0, result.PASSED_percent)

    def test_default_zero(self):
        result = GroupByResult()
        result['RUNNING'] += 1
        self.assertEqual(1, result['RUNNING'])
开发者ID:tkdchen,项目名称:Nitrate,代码行数:81,代码来源:test_core.py


注:本文中的tcms.core.db.GroupByResult.iteritems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。