def test_collect_file_diffs(self): n = 10 filename = 'file{i}.py' with mock_repo() as repo: commits = make_mock_commits(repo, n=n, filename=filename) contrib_module_path = None commit_range = make_commit_range( commits[0], commits[-1]) travis_env_vars = { 'TRAVIS_BUILD_DIR': repo.working_tree_dir, 'TRAVIS_PULL_REQUEST': str(self.pr_num), 'TRAVIS_COMMIT_RANGE': commit_range, } with patch.dict('os.environ', travis_env_vars, clear=True): project_path = repo.working_tree_dir project = make_mock_project(repo, self.pr_num, project_path, contrib_module_path) change_collector = ChangeCollector(project) file_diffs = change_collector._collect_file_diffs() # checks on file_diffs self.assertEqual(len(file_diffs), n - 1) for diff in file_diffs: self.assertEqual(diff.change_type, 'A') self.assertTrue(diff.b_path.startswith('file')) self.assertTrue(diff.b_path.endswith('.py'))
def test_change_collector_collect_file_diffs_custom_differ(mock_repo): repo = mock_repo n = 10 filename = 'file{i}.py' commits = make_mock_commits(repo, n=n, filename=filename) project = None differ = CustomDiffer(endpoints=(commits[0], commits[-1])) change_collector = ChangeCollector(project, differ=differ) file_diffs = change_collector._collect_file_diffs() # checks on file_diffs assert len(file_diffs) == n - 1 for diff in file_diffs: assert diff.change_type == 'A' assert diff.b_path.startswith('file') assert diff.b_path.endswith('.py')