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)
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.') print print 'Will run these tests:' for job in jobs: if args.dry_run: print ' %s: "%s"' % (job.shortname, ' '.join(job.cmdline)) else: print ' %s' % job.shortname print if args.filter_pr_tests: print 'IMPORTANT: Test filtering is not active; this is only for testing.' relevant_jobs = filter_tests(jobs, args.base_branch) # todo(mattkwong): add skipped tests to report.xml print if len(relevant_jobs) == len(jobs): print '(TESTING) No tests will be skipped.' else: print '(TESTING) These tests will be skipped:' for job in list(set(jobs) - set(relevant_jobs)): print ' %s' % job.shortname print if args.dry_run: print '--dry_run was used, exiting' sys.exit(1) jobset.message('START', 'Running test matrix.', do_newline=True)