def test_filtering(self, changed_files=[], labels=_LIST_OF_LANGUAGE_LABELS): """ Default args should filter no tests because changed_files is empty and default labels should be able to match all jobs :param changed_files: mock list of changed_files from pull request :param labels: list of job labels that should be skipped """ all_jobs = self.generate_all_tests() # Replacing _get_changed_files function to allow specifying changed files in filter_tests function def _get_changed_files(foo): return changed_files filter_pull_request_tests._get_changed_files = _get_changed_files print() filtered_jobs = filter_pull_request_tests.filter_tests( all_jobs, "test") # Make sure sanity tests aren't being filtered out sanity_tests_in_all_jobs = 0 sanity_tests_in_filtered_jobs = 0 for job in all_jobs: if "sanity" in job.labels: sanity_tests_in_all_jobs += 1 all_jobs = [job for job in all_jobs if "sanity" not in job.labels] for job in filtered_jobs: if "sanity" in job.labels: sanity_tests_in_filtered_jobs += 1 filtered_jobs = [ job for job in filtered_jobs if "sanity" not in job.labels ] self.assertEquals(sanity_tests_in_all_jobs, sanity_tests_in_filtered_jobs) for label in labels: for job in filtered_jobs: self.assertNotIn(label, job.labels) jobs_matching_labels = 0 for label in labels: for job in all_jobs: if (label in job.labels): jobs_matching_labels += 1 self.assertEquals(len(filtered_jobs), len(all_jobs) - jobs_matching_labels)
def test_filtering(self, changed_files=[], labels=_LIST_OF_LANGUAGE_LABELS): """ Default args should filter no tests because changed_files is empty and default labels should be able to match all jobs :param changed_files: mock list of changed_files from pull request :param labels: list of job labels that should be skipped """ all_jobs = self.generate_all_tests() # Replacing _get_changed_files function to allow specifying changed files in filter_tests function def _get_changed_files(foo): return changed_files filter_pull_request_tests._get_changed_files = _get_changed_files print() filtered_jobs = filter_pull_request_tests.filter_tests(all_jobs, "test") # Make sure sanity tests aren't being filtered out sanity_tests_in_all_jobs = 0 sanity_tests_in_filtered_jobs = 0 for job in all_jobs: if "sanity" in job.labels: sanity_tests_in_all_jobs += 1 all_jobs = [job for job in all_jobs if "sanity" not in job.labels] for job in filtered_jobs: if "sanity" in job.labels: sanity_tests_in_filtered_jobs += 1 filtered_jobs = [ job for job in filtered_jobs if "sanity" not in job.labels ] self.assertEquals(sanity_tests_in_all_jobs, sanity_tests_in_filtered_jobs) for label in labels: for job in filtered_jobs: self.assertNotIn(label, job.labels) jobs_matching_labels = 0 for label in labels: for job in all_jobs: if (label in job.labels): jobs_matching_labels += 1 self.assertEquals( len(filtered_jobs), len(all_jobs) - jobs_matching_labels)
if not jobs: jobset.message('FAILED', 'No test suites match given criteria.', do_newline=True) sys.exit(1) print( 'IMPORTANT: The changes you are testing need to be locally committed') print('because only the committed changes in the current branch will be') print('copied to the docker environment or into subworkspaces.') skipped_jobs = [] if args.filter_pr_tests: print('Looking for irrelevant tests to skip...') relevant_jobs = filter_tests(jobs, args.base_branch) if len(relevant_jobs) == len(jobs): print('No tests will be skipped.') else: print('These tests will be skipped:') skipped_jobs = list(set(jobs) - set(relevant_jobs)) # Sort by shortnames to make printing of skipped tests consistent skipped_jobs.sort(key=lambda job: job.shortname) for job in list(skipped_jobs): print(' %s' % job.shortname) jobs = relevant_jobs print('Will run these tests:') for job in jobs: if args.dry_run: print(' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)))
jobs.append(job) if not jobs: jobset.message('FAILED', 'No test suites match given criteria.', do_newline=True) sys.exit(1) print('IMPORTANT: The changes you are testing need to be locally committed') print('because only the committed changes in the current branch will be') print('copied to the docker environment or into subworkspaces.') skipped_jobs = [] if args.filter_pr_tests: print('Looking for irrelevant tests to skip...') relevant_jobs = filter_tests(jobs, args.base_branch) if len(relevant_jobs) == len(jobs): print('No tests will be skipped.') else: print('These tests will be skipped:') skipped_jobs = list(set(jobs) - set(relevant_jobs)) # Sort by shortnames to make printing of skipped tests consistent skipped_jobs.sort(key=lambda job: job.shortname) for job in list(skipped_jobs): print(' %s' % job.shortname) jobs = relevant_jobs print('Will run these tests:') for job in jobs: if args.dry_run: print(' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)))