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


Python GroupByResult.setdefault方法代码示例

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


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

示例1: GroupByResultDictLikeTest

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [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)
开发者ID:Aaln1986,项目名称:Nitrate,代码行数:60,代码来源:tests.py

示例2: status_matrix

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
    def status_matrix(self, form):
        status_matrix = GroupByResult()
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'run__plan',
                'run__plan__name',
                'case_run_status__name'
            ).filter(
                case_run_status__name__in=('PASSED', 'FAILED')
            ).annotate(
                total_count=Count('run', distinct=True)
            )
        )

        for row in query:
            plan_id = row['run__plan']
            plan_name = row['run__plan__name']
            status_name = row['case_run_status__name']
            total_count = row['total_count']
            plan = TestPlan(pk=plan_id, name=plan_name)
            status_subtotal = status_matrix.setdefault(plan, GroupByResult())
            status_subtotal[status_name] = total_count

        return status_matrix
开发者ID:MrSenko,项目名称:Nitrate,代码行数:27,代码来源:data.py

示例3: status_matrix

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
    def status_matrix(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_plan_build_detail_status_matrix)
        rows = SQLExecution(sql, params, with_field_name=False).rows
        status_matrix = GroupByResult()

        plan_ids = build_ids = run_ids = []
        for plan_id, build_id, run_id, status_name, _ in rows:
            plan_ids.append(plan_id)
            build_ids.append(build_id)
            run_ids.append(run_id)

        plans = {
            plan.pk: plan for plan in TestPlan.objects.filter(
                pk__in=plan_ids).only('pk', 'name')
        }
        test_builds = {
            build.pk: build for build in TestBuild.objects.filter(
                pk__in=build_ids).only('pk', 'name')
        }
        runs = {
            run.pk: run for run in TestRun.objects.filter(
                pk__in=run_ids).only('pk', 'summary')
        }

        for row in rows:
            plan_id, build_id, run_id, status_name, total_count = row
            builds = status_matrix.setdefault(plans[plan_id], GroupByResult())
            runs = builds.setdefault(test_builds[build_id], GroupByResult())
            status_subtotal = runs.setdefault(runs[run_id], GroupByResult())
            status_subtotal[status_name] = total_count

        return status_matrix
开发者ID:tkdchen,项目名称:Nitrate,代码行数:35,代码来源:data.py

示例4: status_matrix_groupby_builds

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
    def status_matrix_groupby_builds(self, form):
        builds = GroupByResult({})
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'build',
                'tested_by',
                'case_run_status__name'
            ).annotate(
                total_count=Count('pk')
            )
        )

        for row in query:
            build_id = row['build']
            tested_by_id = row['tested_by']
            name = row['case_run_status__name']
            total_count = row['total_count']

            tested_by_ids = builds.setdefault(build_id, GroupByResult({}))
            status_subtotal = tested_by_ids.setdefault(tested_by_id,
                                                       GroupByResult({}))
            status_subtotal[name] = total_count

        return builds
开发者ID:MrSenko,项目名称:Nitrate,代码行数:27,代码来源:data.py

示例5: GroupByResultDictLikeTest

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [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)
开发者ID:tkdchen,项目名称:Nitrate,代码行数:49,代码来源:test_core.py

示例6: status_matrix

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
 def status_matrix(self, form):
     sql, params = self._prepare_sql(form,
                                     sqls.by_plan_build_status_matrix)
     rows = SQLExecution(sql, params, with_field_name=False).rows
     status_matrix = GroupByResult()
     for plan_id, plan_name, status_name, total_count in rows:
         plan = TestPlan(pk=plan_id, name=plan_name)
         status_subtotal = status_matrix.setdefault(plan, GroupByResult())
         status_subtotal[status_name] = total_count
     return status_matrix
开发者ID:Aaln1986,项目名称:Nitrate,代码行数:12,代码来源:data.py

示例7: passed_failed_case_runs_subtotal

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
    def passed_failed_case_runs_subtotal(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_plan_tags_passed_failed_case_runs_subtotal)
        sql_executor = SQLExecution(sql, params, with_field_name=False)
        rows = sql_executor.rows
        tags = GroupByResult()

        for tag_id, name, total_count in rows:
            status_subtotal = tags.setdefault(tag_id, GroupByResult())
            status_subtotal[name] = total_count

        return tags
开发者ID:tkdchen,项目名称:Nitrate,代码行数:14,代码来源:data.py

示例8: runs_subtotal_groupby_builds

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
    def runs_subtotal_groupby_builds(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_case_run_tester_runs_subtotal_groupby_build)
        sql_executor = SQLExecution(sql, params,
                                    with_field_name=False)
        rows = sql_executor.rows

        builds = GroupByResult({})

        for build_id, tested_by_id, total_count in rows:
            tested_by_ids = builds.setdefault(build_id, GroupByResult({}))
            tested_by_ids[tested_by_id] = total_count

        return builds
开发者ID:tkdchen,项目名称:Nitrate,代码行数:16,代码来源:data.py

示例9: status_matrix_groupby_builds

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
    def status_matrix_groupby_builds(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_case_run_tester_status_matrix_groupby_build)
        sql_executor = SQLExecution(sql, params,
                                    with_field_name=False)

        builds = GroupByResult({})

        for build_id, tested_by_id, name, total_count in sql_executor.rows:
            tested_by_ids = builds.setdefault(
                build_id, GroupByResult({}))
            status_subtotal = tested_by_ids.setdefault(tested_by_id,
                                                       GroupByResult({}))
            status_subtotal[name] = total_count

        return builds
开发者ID:tkdchen,项目名称:Nitrate,代码行数:18,代码来源:data.py

示例10: runs_subtotal_groupby_builds

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
    def runs_subtotal_groupby_builds(self, form):
        builds = GroupByResult({})
        query = self._filter_query(
            form,
            TestCaseRun.objects.values('tested_by', 'run', 'build').distinct()
        )

        for row in query:
            build_id = row['build']
            tested_by_id = row['tested_by']

            tested_by_ids = builds.setdefault(build_id, GroupByResult({}))
            if tested_by_id in tested_by_ids.keys():
                tested_by_ids[tested_by_id] += 1
            else:
                tested_by_ids[tested_by_id] = 1

        return builds
开发者ID:MrSenko,项目名称:Nitrate,代码行数:20,代码来源:data.py

示例11: passed_failed_case_runs_subtotal

# 需要导入模块: from tcms.core.db import GroupByResult [as 别名]
# 或者: from tcms.core.db.GroupByResult import setdefault [as 别名]
    def passed_failed_case_runs_subtotal(self, form):
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'run__plan__tag', 'case_run_status__name'
            ).filter(case_run_status__name__in=['PASSED', 'FAILED']).annotate(
                total_count=Count('case_run_status')
            )
        )

        tags = GroupByResult()
        for row in query:
            tag_id = row['run__plan__tag']
            name = row['case_run_status__name']
            total_count = row['total_count']

            status_subtotal = tags.setdefault(tag_id, GroupByResult())
            status_subtotal[name] = total_count

        from pprint import pprint
        pprint(tags)

        return tags
开发者ID:MrSenko,项目名称:Nitrate,代码行数:25,代码来源:data.py


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