本文整理汇总了Python中models.TestResult类的典型用法代码示例。如果您正苦于以下问题:Python TestResult类的具体用法?Python TestResult怎么用?Python TestResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_merge
def test_merge(self):
branch, platform, builder = _create_some_builder()
some_build = _create_build(branch, platform, builder)
some_result = TestResult.get_or_insert_from_parsed_json('some-test', some_build, 50)
some_test = Test.update_or_insert('some-test', branch, platform)
other_build = _create_build(branch, platform, builder, 'other-build')
other_result = TestResult.get_or_insert_from_parsed_json('other-test', other_build, 30)
other_test = Test.update_or_insert('other-test', branch, platform)
self.assertOnlyInstances([some_result, other_result])
self.assertNotEqual(some_result.key(), other_result.key())
self.assertOnlyInstances([some_test, other_test])
self.assertRaises(AssertionError, some_test.merge, (some_test))
self.assertOnlyInstances([some_test, other_test])
some_test.merge(other_test)
results_for_some_test = TestResult.all()
results_for_some_test.filter('name =', 'some-test')
results_for_some_test = results_for_some_test.fetch(5)
self.assertEqual(len(results_for_some_test), 2)
self.assertEqual(results_for_some_test[0].name, 'some-test')
self.assertEqual(results_for_some_test[1].name, 'some-test')
if results_for_some_test[0].value == 50:
self.assertEqual(results_for_some_test[1].value, 30)
else:
self.assertEqual(results_for_some_test[1].value, 50)
示例2: post
def post(self):
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
log_id = int(self.request.get('id', 0))
log = ReportLog.get_by_id(log_id)
if not log or not log.commit:
self.response.out.write("Not processed")
return
branch = log.branch()
platform = log.platform()
build = Build.get_or_insert_from_log(log)
for test_name, result in log.results().iteritems():
test = Test.update_or_insert(test_name, branch, platform)
TestResult.get_or_insert_from_parsed_json(test_name, build, result)
schedule_runs_update(test.id, branch.id, platform.id)
log = ReportLog.get(log.key())
log.delete()
# We need to update dashboard and manifest because they are affected by the existance of test results
schedule_dashboard_update()
schedule_manifest_update()
self.response.out.write('OK')
示例3: _create_results
def _create_results(self, branch, platform, builder, test_name, values, timestamps=None):
results = []
for i, value in enumerate(values):
build = Build(branch=branch, platform=platform, builder=builder,
buildNumber=i, revision=100 + i, timestamp=timestamps[i] if timestamps else datetime.now())
build.put()
result = TestResult(name=test_name, build=build, value=value)
result.put()
results.append(result)
return results
示例4: test_replace_to_change_test_name_overrides_conflicting_result
def test_replace_to_change_test_name_overrides_conflicting_result(self):
branch, platform, builder = _create_some_builder()
build = _create_build(branch, platform, builder)
self.assertThereIsNoInstanceOf(TestResult)
result = TestResult.get_or_insert_from_parsed_json('some-test', build, 20)
self.assertOnlyInstance(result)
conflicting_result = TestResult.get_or_insert_from_parsed_json('other-test', build, 10)
new_result = result.replace_to_change_test_name('other-test')
self.assertNotEqual(result, new_result)
self.assertOnlyInstance(new_result)
self.assertEqual(new_result.name, 'other-test')
self.assertEqual(TestResult.get(conflicting_result.key()).value, 20)
示例5: post
def post(self):
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
log_id = int(self.request.get('id', 0))
log = ReportLog.get_by_id(log_id)
if not log or not log.commit:
self.response.out.write("Not processed")
return
branch = log.branch()
platform = log.platform()
build = Build.get_or_insert_from_log(log)
for test_name, result_value in log.results().iteritems():
unit = result_value.get('unit') if isinstance(result_value, dict) else None
test = Test.update_or_insert(test_name, branch, platform, unit)
result = TestResult.get_or_insert_from_parsed_json(test_name, build, result_value)
if not result:
continue
runs = Runs.get_by_objects(branch, platform, test)
regenerate_runs = True
if runs:
runs.update_incrementally(build, result)
regenerate_runs = False
schedule_runs_update(test.id, branch.id, platform.id, regenerate_runs)
log = ReportLog.get(log.key())
log.delete()
# We need to update dashboard and manifest because they are affected by the existance of test results
schedule_dashboard_update()
schedule_manifest_update()
self.response.out.write('OK')
示例6: get
def get(self):
self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
try:
testId = int(self.request.get('id', 0))
branchId = int(self.request.get('branchid', 0))
platformId = int(self.request.get('platformid', 0))
except TypeError:
# FIXME: Output an error here
testId = 0
branchId = 0
platformId = 0
# FIXME: Just fetch builds specified by "days"
# days = self.request.get('days', 365)
cacheKey = Test.cacheKey(testId, branchId, platformId)
cache = memcache.get(cacheKey)
if cache:
self.response.out.write(cache)
return
builds = Build.all()
builds.filter('branch =', modelFromNumericId(branchId, Branch))
builds.filter('platform =', modelFromNumericId(platformId, Platform))
test = modelFromNumericId(testId, Test)
testName = test.name if test else None
test_runs = []
averages = {}
values = []
timestamps = []
for build in builds:
results = TestResult.all()
results.filter('name =', testName)
results.filter('build =', build)
for result in results:
builderId = build.builder.key().id()
posixTimestamp = mktime(build.timestamp.timetuple())
test_runs.append([result.key().id(),
[build.key().id(), build.buildNumber, build.revision],
posixTimestamp, result.value, 0, [], builderId])
# FIXME: Calculate the average; in practice, we wouldn't have more than one value for a given revision
averages[build.revision] = result.value
values.append(result.value)
timestamps.append(posixTimestamp)
result = json.dumps({
'test_runs': test_runs,
'averages': averages,
'min': min(values) if values else None,
'max': max(values) if values else None,
'date_range': [min(timestamps), max(timestamps)] if timestamps else None,
'stat': 'ok'})
self.response.out.write(result)
memcache.add(cacheKey, result)
示例7: _generate_runs
def _generate_runs(branch, platform, test_name):
builds = Build.all()
builds.filter('branch =', branch)
builds.filter('platform =', platform)
for build in builds:
results = TestResult.all()
results.filter('name =', test_name)
results.filter('build =', build)
for result in results:
yield build, result
raise StopIteration
示例8: test_get_or_insert_value
def test_get_or_insert_value(self):
branch, platform, builder = _create_some_builder()
build = _create_build(branch, platform, builder)
self.assertThereIsNoInstanceOf(TestResult)
result = TestResult.get_or_insert_from_parsed_json('some-test', build, 50)
self.assertOnlyInstance(result)
self.assertEqual(result.name, 'some-test')
self.assertEqual(result.build.key(), build.key())
self.assertEqual(result.value, 50.0)
self.assertEqual(result.valueMedian, None)
self.assertEqual(result.valueStdev, None)
self.assertEqual(result.valueMin, None)
self.assertEqual(result.valueMax, None)
示例9: test_get_or_insert_stat_value
def test_get_or_insert_stat_value(self):
branch, platform, builder = _create_some_builder()
build = _create_build(branch, platform, builder)
self.assertThereIsNoInstanceOf(TestResult)
result = TestResult.get_or_insert_from_parsed_json('some-test', build,
{"avg": 40, "median": "40.1", "stdev": 3.25, "min": 30.5, "max": 45})
self.assertOnlyInstance(result)
self.assertEqual(result.name, 'some-test')
self.assertEqual(result.build.key(), build.key())
self.assertEqual(result.value, 40.0)
self.assertEqual(result.valueMedian, 40.1)
self.assertEqual(result.valueStdev, 3.25)
self.assertEqual(result.valueMin, 30.5)
self.assertEqual(result.valueMax, 45)
示例10: post
def post(self):
"""
Create a new test result
:return: status of the request
:raise HTTPError
"""
# check for request payload
if self.json_args is None:
raise HTTPError(HTTP_BAD_REQUEST)
# check for missing parameters in the request payload
if self.json_args.get("project_name") is None:
raise HTTPError(HTTP_BAD_REQUEST)
if self.json_args.get("case_name") is None:
raise HTTPError(HTTP_BAD_REQUEST)
# check for pod_name instead of id,
# keeping id for current implementations
if self.json_args.get("pod_name") is None:
raise HTTPError(HTTP_BAD_REQUEST)
# TODO : replace checks with jsonschema
# check for project
mongo_dict = yield self.db.test_projects.find_one({"name": self.json_args.get("project_name")})
if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND, "Could not find project [{}] ".format(self.json_args.get("project_name")))
# check for case
mongo_dict = yield self.db.test_cases.find_one({"name": self.json_args.get("case_name")})
if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND, "Could not find case [{}] ".format(self.json_args.get("case_name")))
# check for pod
mongo_dict = yield self.db.pod.find_one({"name": self.json_args.get("pod_name")})
if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND, "Could not find POD [{}] ".format(self.json_args.get("pod_name")))
# convert payload to object
test_result = TestResult.test_result_from_dict(self.json_args)
test_result.creation_date = datetime.now()
future = self.db.test_results.insert(test_result.format(), check_keys=False)
result = yield future
test_result._id = result
self.finish_request(test_result.format_http())
示例11: test_replace_to_change_test_name
def test_replace_to_change_test_name(self):
branch, platform, builder = _create_some_builder()
build = _create_build(branch, platform, builder)
self.assertThereIsNoInstanceOf(TestResult)
result = TestResult.get_or_insert_from_parsed_json('some-test', build, 50)
self.assertOnlyInstance(result)
self.assertEqual(result.name, 'some-test')
new_result = result.replace_to_change_test_name('other-test')
self.assertNotEqual(result, new_result)
self.assertOnlyInstance(new_result)
self.assertEqual(new_result.name, 'other-test')
self.assertEqual(new_result.build.key(), result.build.key())
self.assertEqual(new_result.value, result.value)
self.assertEqual(new_result.valueMedian, None)
self.assertEqual(new_result.valueStdev, None)
self.assertEqual(new_result.valueMin, None)
self.assertEqual(new_result.valueMax, None)
示例12: process_request
def process_request(self, request):
#noinspection PyBroadException
if not AB_TEST_ACTIVE:
return None
try:
sessionTests = request.session.get(AB_TEST_SESSION_NAME, {})
if sessionTests is None: sessionTests = {}
newSessionTests = {}
requestTests = ABTestRequest()
for activeTest in Test.objects.filter(active=True):
if activeTest.pk in sessionTests and TestResult.objects.filter(pk=sessionTests[activeTest.pk]).exists():
activeTestResult = TestResult.objects.get(pk=sessionTests[activeTest.pk])
else:
activeTestResult = TestResult.chooseExperiment(request, activeTest)
newSessionTests[activeTest.pk] = activeTestResult.pk
requestTests[activeTest] = activeTestResult
request.session[AB_TEST_SESSION_NAME] = newSessionTests
setattr(request, AB_TEST_REQUEST_NAME, requestTests)
except Exception as ex:
getLogger(AB_TEST_LOGGER_MIDDLEWARE).error("error processing request: %s", ex)
if not AB_TEST_FAIL_SILENT_MIDDLEWARE:
raise
return None
示例13: report_start
def report_start(request, mac):
host, _ = Host.objects.get_or_create(_mac=mac)
new_result = TestResult(host=host)
new_result.save()
return HttpResponse(host)
示例14: get
def get(self, result_id=None):
"""
Retrieve result(s) for a test project on a specific POD.
Available filters for this request are :
- project : project name
- case : case name
- pod : pod name
- version : platform version (Arno-R1, ...)
- installer (fuel, ...)
- build_tag : Jenkins build tag name
- period : x (x last days)
:param result_id: Get a result by ID
:raise HTTPError
GET /results/project=functest&case=vPing&version=Arno-R1 \
&pod=pod_name&period=15
=> get results with optional filters
"""
project_arg = self.get_query_argument("project", None)
case_arg = self.get_query_argument("case", None)
pod_arg = self.get_query_argument("pod", None)
version_arg = self.get_query_argument("version", None)
installer_arg = self.get_query_argument("installer", None)
build_tag_arg = self.get_query_argument("build_tag", None)
period_arg = self.get_query_argument("period", None)
# prepare request
get_request = dict()
if result_id is None:
if project_arg is not None:
get_request["project_name"] = project_arg
if case_arg is not None:
get_request["case_name"] = case_arg
if pod_arg is not None:
get_request["pod_name"] = pod_arg
if version_arg is not None:
get_request["version"] = version_arg
if installer_arg is not None:
get_request["installer"] = installer_arg
if build_tag_arg is not None:
get_request["build_tag"] = build_tag_arg
if period_arg is not None:
try:
period_arg = int(period_arg)
except:
raise HTTPError(HTTP_BAD_REQUEST)
if period_arg > 0:
period = datetime.now() - timedelta(days=period_arg)
obj = {"$gte": str(period)}
get_request["creation_date"] = obj
else:
get_request["_id"] = result_id
print get_request
res = []
# fetching results
cursor = self.db.test_results.find(get_request)
while (yield cursor.fetch_next):
test_result = TestResult.test_result_from_dict(cursor.next_object())
res.append(test_result.format_http())
# building meta object
meta = dict()
meta["total"] = len(res)
# final response object
answer = dict()
answer["test_results"] = res
answer["meta"] = meta
self.finish_request(answer)
示例15: test_get_or_insert_stat_value_with_values
def test_get_or_insert_stat_value_with_values(self):
branch, platform, builder = _create_some_builder()
build = _create_build(branch, platform, builder)
result = TestResult.get_or_insert_from_parsed_json('some-test', build,
{"avg": 40, "median": "40.1", "stdev": 3.25, "min": 30.5, "max": 45, "values": [1.0, 2.0, 3.0]})
self.assertEqual(result.values, [1.0, 2.0, 3.0])