def test_travis_pull_request_build_differ(mock_repo, commit_range): repo = mock_repo make_mock_commits(repo, n=3) travis_env_vars = { 'TRAVIS_BUILD_DIR': repo.working_tree_dir, 'TRAVIS_PULL_REQUEST': '1', 'TRAVIS_COMMIT_RANGE': commit_range, } with patch.dict('os.environ', travis_env_vars, clear=True): differ = TravisPullRequestBuildDiffer(repo) expected_a = repo.rev_parse('HEAD^') expected_b = repo.rev_parse('HEAD') actual_a, actual_b = differ._get_diff_endpoints() assert actual_a == expected_a assert actual_b == expected_b
def test_travis_pull_request_build_differ(self): with mock_repo() as repo: make_mock_commits(repo, n=3) pr_num = self.pr_num commit_range = 'HEAD^..HEAD' travis_env_vars = { 'TRAVIS_BUILD_DIR': repo.working_tree_dir, 'TRAVIS_PULL_REQUEST': str(pr_num), 'TRAVIS_COMMIT_RANGE': commit_range, } with patch.dict('os.environ', travis_env_vars, clear=True): differ = TravisPullRequestBuildDiffer(pr_num) expected_a = repo.rev_parse('HEAD^') expected_b = repo.rev_parse('HEAD') actual_a, actual_b = differ._get_diff_endpoints() self.assertEqual(actual_a, expected_a) self.assertEqual(actual_b, expected_b)
def test_travis_pull_request_build_differ_on_mock_commits(self): n = 4 i = 0 pr_num = self.pr_num feature_branch_name = 'pull/{}'.format(pr_num) with mock_repo() as repo: make_mock_commit(repo, path='readme.txt') expected_merge_base = repo.head.commit feature_branch = repo.create_head(feature_branch_name) # make commits on branch master commits = make_mock_commits(repo, n=3, filename='blah{i}.txt') master = repo.heads.master # make commits on feature branch feature_branch.checkout() commits = make_mock_commits(repo, n=n) end_commit = commits[-1] commit_range = ballet.util.git.make_commit_range( master, end_commit) travis_env_vars = { 'TRAVIS_BUILD_DIR': repo.working_tree_dir, 'TRAVIS_PULL_REQUEST': str(pr_num), 'TRAVIS_COMMIT_RANGE': commit_range, } with patch.dict('os.environ', travis_env_vars, clear=True): differ = TravisPullRequestBuildDiffer(pr_num) a, b = differ._get_diff_endpoints() self.assertEqual(a, expected_merge_base) self.assertEqual(b, end_commit) diffs = differ.diff() # there should be n diff objects, they should show files # 0 to n-1. merge base just created readme.txt, so all files # on feature branch are new. self.assertEqual(len(diffs), n) j = i for diff in diffs: self.assertEqual(diff.change_type, 'A') self.assertEqual(diff.b_path, 'file{j}.py'.format(j=j)) j += 1
def test_travis_pull_request_build_differ_on_mock_commits(mock_repo): repo = mock_repo n = 4 i = 0 feature_branch_name = 'alice/feature-x' make_mock_commit(repo, path='readme.txt') expected_merge_base = repo.head.commit feature_branch = repo.create_head(feature_branch_name) # make commits on branch master commits = make_mock_commits(repo, n=3, filename='blah{i}.txt') master = repo.heads.master # make commits on feature branch feature_branch.checkout() commits = make_mock_commits(repo, n=n) end_commit = commits[-1] commit_range = make_commit_range( master, end_commit) travis_env_vars = { 'TRAVIS_BUILD_DIR': repo.working_tree_dir, 'TRAVIS_PULL_REQUEST': '1', 'TRAVIS_COMMIT_RANGE': commit_range, } with patch.dict('os.environ', travis_env_vars, clear=True): differ = TravisPullRequestBuildDiffer(repo) a, b = differ._get_diff_endpoints() assert a == expected_merge_base assert b == end_commit diffs = differ.diff() # there should be n diff objects, they should show files # 0 to n-1. merge base just created readme.txt, so all # files on feature branch are new. assert len(diffs) == n j = i for diff in diffs: assert diff.change_type == 'A' assert diff.b_path == f'file{j}.py' j += 1