예제 #1
0
def test_perform_git_commit(mock_log_git, capsys):
    with mock_git_repo():
        os.system("echo \"hello world\" >> file.txt")

        _perform_git_commit(filename='file.txt',
                            git_commit=True,
                            git_message='added file.txt')

        # Assert that commit took place
        assert os.popen(
            'git show -s --format=%s HEAD').read().strip() == 'added file.txt'

        # Assert that it was logged
        expected_result = "[jovian] Git repository identified. Performing git commit..."
        captured = capsys.readouterr()
        assert captured.out.strip() == expected_result

        mock_log_git.assert_called_with(
            {
                'repository': 'https://github.com/JovianML/mock_repo',
                'commit': ANY,
                'filename': 'file.txt',
                'path': '.',
                'branch': 'master'
            },
            verbose=False)
예제 #2
0
def test_git_commit_push(mock_git_push):
    with mock_git_repo():
        message = 'sample commit'
        expected_result = {
            'remote': get_remote(),
            'branch': get_branch(),
            'commit': get_current_commit()
        }

        assert git_commit_push(message) == expected_result
        mock_git_push.assert_called_with()
예제 #3
0
def test_get_relative_path():
    with mock_git_repo():
        os.makedirs("nested/folder/deep")
        os.chdir("nested/folder/deep")

        assert get_relative_path() == "nested/folder/deep"
예제 #4
0
def test_git_push_other_branch(mock_system):
    with mock_git_repo():
        check_call("git checkout -b sample_branch".split())

        git_push()
        mock_system.assert_called_with("git push origin sample_branch")
예제 #5
0
def test_commit():
    with mock_git_repo():
        os.system('touch file')
        message = 'sample commit'
        assert commit(message) == 0
예제 #6
0
def test_git_push_master(mock_system):
    with mock_git_repo():
        git_push()
        mock_system.assert_called_with("git push origin master")
예제 #7
0
def test_get_current_commit():
    with mock_git_repo():
        expected_result = os.popen('git rev-parse HEAD').read().strip()

        assert get_current_commit() == expected_result
예제 #8
0
def test_get_repository_root():
    with mock_git_repo():
        assert get_repository_root().endswith('mock_git_repo')
예제 #9
0
def test_get_remote():
    with mock_git_repo():
        expected_result = 'https://github.com/JovianML/mock_repo'
        assert get_remote() == expected_result
예제 #10
0
def test_get_branch():
    with mock_git_repo():
        assert get_branch() == "master"

        os.system('git checkout -b sample_branch')
        assert get_branch() == "sample_branch"
예제 #11
0
def test_is_git():
    with mock_git_repo():
        assert is_git()