Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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]
Ejemplo n.º 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
Ejemplo n.º 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]
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)))))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)))))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)