def get_test_stats(cls, project_slug): response = api_client.get('/projects/{project}/'.format( project=project_slug)) last_build = response['lastPassingBuild'] if not last_build: # use a failing build if no build has passed yet last_build = response['lastBuild'] if not last_build: return {}, 0 # XXX(dcramer): ideally this would be abstracted via an API job_list = db.session.query(Job.id).filter( Job.build_id == last_build['id'], ) if job_list: test_durations = dict(db.session.query( TestCase.name, TestCase.duration ).filter( TestCase.job_id.in_(job_list), )) else: test_durations = dict() test_names = [] total_count, total_duration = 0, 0 for test in test_durations: test_names.append(test) total_duration += test_durations[test] total_count += 1 test_stats = {} if test_names: sep = TestCase(name=test_names[0]).sep tree = build_flat_tree(test_names, sep=sep) for group_name, group_tests in tree.iteritems(): segments = cls._normalize_test_segments(group_name) test_stats[segments] = sum(test_durations[t] for t in group_tests) # the build report can contain different test suites so this isnt the # most accurate if total_duration > 0: avg_test_time = int(total_duration / total_count) else: avg_test_time = 0 return test_stats, avg_test_time
def get_test_stats(cls, project_slug): response = api_client.get( '/projects/{project}/'.format(project=project_slug)) last_build = response['lastPassingBuild'] if not last_build: # use a failing build if no build has passed yet last_build = response['lastBuild'] if not last_build: return {}, 0 # XXX(dcramer): ideally this would be abstracted via an API job_list = db.session.query(Job.id).filter( Job.build_id == last_build['id'], ) if job_list: test_durations = dict( db.session.query(TestCase.name, TestCase.duration).filter( TestCase.job_id.in_(job_list), )) else: test_durations = dict() test_names = [] total_count, total_duration = 0, 0 for test in test_durations: test_names.append(test) total_duration += test_durations[test] total_count += 1 test_stats = {} if test_names: sep = TestCase(name=test_names[0]).sep tree = build_flat_tree(test_names, sep=sep) for group_name, group_tests in tree.iteritems(): segments = cls._normalize_test_segments(group_name) test_stats[segments] = sum(test_durations[t] for t in group_tests) # the build report can contain different test suites so this isnt the # most accurate if total_duration > 0: avg_test_time = int(total_duration / total_count) else: avg_test_time = 0 return test_stats, avg_test_time
def get_target_stats(cls, project_slug): # type: (str) -> Tuple[Dict[str, int], int] """Collect the run time statistics for targets. Arguments: project_slug (str) Returns: Tuple[Dict[str, int], int]: The first item is the mapping from target names to run duration, in ms. The second item is the average run duration across all targets. If a target has no duration recorded, it is excluded from all calculations and mapping. """ response = api_client.get('/projects/{project}/'.format( project=project_slug)) last_build = response['lastPassingBuild'] if not last_build: # use a failing build if no build has passed yet last_build = response['lastBuild'] if not last_build: return {}, 0 job_list = db.session.query(Job.id).filter( Job.build_id == last_build['id'], ) if job_list: target_durations = dict(db.session.query( BazelTarget.name, BazelTarget.duration ).filter( BazelTarget.job_id.in_(job_list), ~BazelTarget.duration.is_(None), )) else: target_durations = dict() total_duration = sum(target_durations.itervalues()) if total_duration > 0: avg_test_time = int(total_duration / len(target_durations)) else: avg_test_time = 0 return target_durations, avg_test_time
def get_target_stats(cls, project_slug): # type: (str) -> Tuple[Dict[str, int], int] """Collect the run time statistics for targets. Arguments: project_slug (str) Returns: Tuple[Dict[str, int], int]: The first item is the mapping from target names to run duration, in ms. The second item is the average run duration across all targets. If a target has no duration recorded, it is excluded from all calculations and mapping. """ response = api_client.get( '/projects/{project}/'.format(project=project_slug)) last_build = response['lastPassingBuild'] if not last_build: # use a failing build if no build has passed yet last_build = response['lastBuild'] if not last_build: return {}, 0 job_list = db.session.query(Job.id).filter( Job.build_id == last_build['id'], ) if job_list: target_durations = dict( db.session.query(BazelTarget.name, BazelTarget.duration).filter( BazelTarget.job_id.in_(job_list), ~BazelTarget.duration.is_(None), )) else: target_durations = dict() total_duration = sum(target_durations.itervalues()) if total_duration > 0: avg_test_time = int(total_duration / len(target_durations)) else: avg_test_time = 0 return target_durations, avg_test_time
def test_simple(self): # HACK: relies on existing endpoint result = api_client.get('/projects/') assert type(result) == list