本文整理汇总了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)
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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