예제 #1
0
def test_git_add_has_call_with_expected_command_with_all_flag_when_all_is_true(
        mocker, mock_process):
    cmd = ['git', 'add', '--all', '.']
    repo = Repository('path')
    repo.add(all=True)

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #2
0
def test_git_init_creates_a_repository_on_path(mocker, mock_process):
    path = 'some_path'
    cmd = ['git', 'init', path]
    repo = Repository(path)
    repo.init()

    mock_process.call.assert_called_once_with(cmd)
예제 #3
0
def test_git_init_creates_a_repository_on_path(mocker, mock_process):
    path = 'some_path'
    cmd = ['git', 'init', path]
    repo = Repository(path)
    repo.init()

    mock_process.call.assert_called_once_with(cmd)
예제 #4
0
def test_git_pull_rebase_calls_expected_command_when_remote_branch_is_passed(
        mocker, mock_process):
    cmd = ['git', 'pull', '--rebase', 'another_origin', 'another_branch']
    repo = Repository('path')
    repo.pull_rebase(remote='another_origin', branch='another_branch')

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #5
0
def test_git_commit_calls_push_when_autopush_set(mocker, mock_process):
    message = 'Initial commit'
    cmd = ['git', 'commit', '-m', message]
    repo = Repository('path', autopush=['origin', 'master'])
    mocker.patch.object(repo, 'push')

    repo.commit(message)
    assert repo.push.called
예제 #6
0
def test_git_commit_calls_push_when_autopush_set(mocker, mock_process):
    message = 'Initial commit'
    cmd = ['git', 'commit', '-m', message]
    repo = Repository('path', autopush=['origin', 'master'])
    mocker.patch.object(repo, 'push')

    repo.commit(message)
    assert repo.push.called
예제 #7
0
def test_reset_doesnt_call_git_reset_hard_on_commit_when_not_found(mocker, mock_process):
    sha_list = []
    index = 0

    repo = Repository('path')
    mocker.patch.object(repo, 'sha_list', return_value=sha_list)
    repo.reset(index)

    mock_process.call.called is False
예제 #8
0
def test_git_commit_list_has_expected_commit_list(mocker, mock_process):
    commit_list = ['another commit', 'initial commit']
    mock_process.call.return_value = ("\n".join(commit_list), 'no error')
    cmd = ['git', 'log', '--reverse', '--pretty=format:%s']
    repo = Repository('path')
    commits = repo.commit_list()

    assert len(repo.commit_list()) == len(commits)
    mock_process.call.assert_any_call(cmd, cwd=repo.path)
예제 #9
0
def test_git_sha_list_has_call_with_expected_command(mocker, mock_process):
    output = 'a\nb'
    mock_process.call.return_value = (output, '')
    cmd = ['git', 'log', '--reverse', '--pretty=format:%h']
    repo = Repository('path')
    result = repo.sha_list()

    assert result == output.splitlines()
    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #10
0
def test_git_sha_list_has_call_with_expected_command(mocker, mock_process):
    output = 'a\nb'
    mock_process.call.return_value = (output, '')
    cmd = ['git', 'log', '--reverse', '--pretty=format:%h']
    repo = Repository('path')
    result = repo.sha_list()

    assert result == output.splitlines()
    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #11
0
def test_git_commit_creates_commit_with_message(mocker, mock_process):
    message = 'Initial commit'
    cmd = ['git', 'commit', '-m', message]
    repo = Repository('path')
    mocker.patch.object(repo, 'add')

    repo.commit(message)

    repo.add.assert_called_once_with(all=True)
    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #12
0
def test_reset_doesnt_call_git_reset_hard_on_commit_when_not_found(
        mocker, mock_process):
    sha_list = []
    index = 0

    repo = Repository('path')
    mocker.patch.object(repo, 'sha_list', return_value=sha_list)
    repo.reset(index)

    mock_process.call.called is False
예제 #13
0
def test_git_commit_creates_commit_with_message(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    path = 'some_path'
    message = 'Initial commit'

    git = Repository(path)
    git.commit(message)

    MockRepo().git.add.assert_called_once_with(all=True)
    MockRepo().index.commit.assert_called_once_with(message)
예제 #14
0
def test_git_commit_creates_commit_with_message(mocker, mock_process):
    message = 'Initial commit'
    repo = Repository('path')
    mocker.patch.object(repo, 'add')
    cmd = ['git', 'commit', '--author={}'.format(repo.author), '-m', message]

    repo.commit(message)

    repo.add.assert_called_once_with(all=True)
    mock_process.call.assert_any_call(cmd, cwd=repo.path)
예제 #15
0
def test_git_commit_creates_commit_with_message(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    path = 'some_path'
    message = 'Initial commit'

    git = Repository(path)
    git.commit(message)

    MockRepo().git.add.assert_called_once_with(all=True)
    MockRepo().index.commit.assert_called_once_with(message)
예제 #16
0
def test_reset_doesnt_call_git_reset_hard_on_commit_when_not_found(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = []
    mock_repo.iter_commits.return_value = commits
    index = len(commits) + 1

    git = Repository('path')
    commit = git.reset(index)

    assert mock_repo.git.reset.called is False
예제 #17
0
def test_commit_by_index_returns_none_when_index_not_found(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = []
    mock_repo.iter_commits.return_value = commits
    index = len(commits) + 1

    git = Repository('path')
    commit = git.commit_by_index(index)

    assert commit is None
예제 #18
0
def test_commit_by_index_returns_none_when_index_not_found(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = []
    mock_repo.iter_commits.return_value = commits
    index = len(commits) + 1

    git = Repository('path')
    commit = git.commit_by_index(index)

    assert commit is None
예제 #19
0
def test_commit_by_index_returns_found_commit_when_index_exists(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = ['initial commit']
    mock_repo.iter_commits.return_value = commits
    index = 0

    git = Repository('path')
    commit = git.commit_by_index(index)

    assert commit == commits[0]
예제 #20
0
def test_reset_doesnt_call_git_reset_hard_on_commit_when_not_found(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = []
    mock_repo.iter_commits.return_value = commits
    index = len(commits) + 1

    git = Repository('path')
    commit = git.reset(index)

    assert mock_repo.git.reset.called is False
예제 #21
0
def test_commit_by_index_returns_found_commit_when_index_exists(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = ['initial commit']
    mock_repo.iter_commits.return_value = commits
    index = 0

    git = Repository('path')
    commit = git.commit_by_index(index)

    assert commit == commits[0]
예제 #22
0
def test_reset_call_git_reset_hard_on_commit_when_found(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = [MagicMock()]
    mock_repo.iter_commits.return_value = commits
    index = 0

    git = Repository('path')
    commit = git.reset(index)

    assert mock_repo.git.reset.called is True
    mock_repo.git.reset.assert_called_once_with('--hard', commits[0].hexsha)
예제 #23
0
def test_reset_call_git_reset_hard_on_commit_when_found(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = [MagicMock()]
    mock_repo.iter_commits.return_value = commits
    index = 0

    git = Repository('path')
    commit = git.reset(index)

    assert mock_repo.git.reset.called is True
    mock_repo.git.reset.assert_called_once_with('--hard', commits[0].hexsha)
예제 #24
0
def test_git_commit_list_has_expected_commit_list(mocker, mock_process):
    commit_list = [
        'another commit',
        'initial commit'
    ]
    mock_process.call.return_value = ("\n".join(commit_list), 'no error')
    cmd = ['git', 'log', '--reverse', '--pretty=format:%s']
    repo = Repository('path')
    commits = repo.commit_list()

    assert len(repo.commit_list()) == len(commits)
    mock_process.call.assert_any_call(cmd, cwd=repo.path)
예제 #25
0
def test_git_commit_list_has_expected_reversed_commits_with_index(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = ['another commit', 'initial commit']
    mock_repo.iter_commits.return_value = commits
    path = 'some_path'

    git = Repository(path)
    commit_list = git.commit_list()

    assert len(commit_list) == len(commits)
    assert [i for i, _ in commit_list
            ] == list(reversed(list(range(len(commits)))))
예제 #26
0
def test_reset_call_git_reset_hard_on_commit_when_found(mocker, mock_process):
    sha_list = [
        'd6b52b5',
        '34c5439',
        '5910c2b',
    ]
    index = 0
    cmd = ['git', 'reset', '--hard', sha_list[index]]

    repo = Repository('path')
    mocker.patch.object(repo, 'sha_list', return_value=sha_list)
    repo.reset(index)

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #27
0
def test_reset_call_git_reset_hard_on_commit_when_found(mocker, mock_process):
    sha_list = [
        'd6b52b5',
        '34c5439',
        '5910c2b',
    ]
    index = 0
    cmd = ['git', 'reset', '--hard', sha_list[index]]

    repo = Repository('path')
    mocker.patch.object(repo, 'sha_list', return_value=sha_list)
    repo.reset(index)

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #28
0
def test_git_commit_list_has_expected_reversed_commits_with_index(mocker):
    MockRepo = mocker.patch('passpie.history.Repo')
    mock_repo = MockRepo()
    commits = [
        'another commit',
        'initial commit'
    ]
    mock_repo.iter_commits.return_value = commits
    path = 'some_path'

    git = Repository(path)
    commit_list = git.commit_list()

    assert len(commit_list) == len(commits)
    assert [i for i, _ in commit_list] == list(reversed(list(range(len(commits)))))
예제 #29
0
def test_calls_pull_rebase_on_initialization_when_autopull_is_passed(
        mocker, mock_process):
    mocker.patch.object(Repository, 'pull_rebase')
    autopull = ['origin', 'master']
    repo = Repository('path', autopull)
    assert repo.pull_rebase.called
    repo.pull_rebase.assert_called_once_with(*autopull)
예제 #30
0
def test_git_push_calls_expected_command_when_remote_branch_is_passed(mocker, mock_process):
    cmd = ['git', 'push', 'another_origin', 'another_branch']
    repo = Repository('path')
    repo.push(remote='another_origin', branch='another_branch')

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #31
0
def test_git_push_calls_expected_command(mocker, mock_process):
    cmd = ['git', 'push', 'origin', 'master']
    repo = Repository('path')
    repo.push()

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #32
0
def test_git_add_has_call_with_expected_command(mocker, mock_process):
    cmd = ['git', 'add', '.']
    repo = Repository('path')
    repo.add()

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #33
0
def test_git_add_has_call_with_expected_command_with_all_flag_when_all_is_true(mocker, mock_process):
    cmd = ['git', 'add', '--all', '.']
    repo = Repository('path')
    repo.add(all=True)

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #34
0
def test_git_add_has_call_with_expected_command(mocker, mock_process):
    cmd = ['git', 'add', '.']
    repo = Repository('path')
    repo.add()

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)
예제 #35
0
def test_git_push_calls_expected_command(mocker, mock_process):
    cmd = ['git', 'push', 'origin', 'master']
    repo = Repository('path')
    repo.push()

    mock_process.call.assert_called_once_with(cmd, cwd=repo.path)