示例#1
0
def test_RepoWrangler_list_repos_progress_bar(mock_requests_get):
    mock_requests_get.update(
        mock_multi_page_api_responses(
            url='https://api.github.com/users/test_user/repos',
            pages=[
                [
                    repo('xyzzy'),
                ],
                [
                    repo('project-foo'),
                ],
            ],
        ))
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress)
    result = wrangler.list_repos(user='******')
    assert result == [
        Repo('project-foo'),
        Repo('xyzzy'),
    ]
    compare(
        buf.getvalue(),
        "{cr}Fetching list of test_user's repositories from GitHub...{cr}"
        "{cr}                                                        {cr}"
        "{cr}Fetching list of test_user's repositories from GitHub... (1){cr}")
示例#2
0
def test_RepoTask_verify_unknown_files():
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress, verbose=2)
    task = wrangler.repo_task(Repo('xyzzy'))
    task.get_current_branch = lambda dir: 'master'
    task.get_remote_url = lambda dir: '[email protected]:test_user/xyzzy'
    task.get_unknown_files = lambda dir: [
        '.coverage', 'tags', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
    ]
    task.verify(task.repo, 'xyzzy')
    assert show_ansi_result(buf.getvalue()) == (
        '+ xyzzy (unknown files)\n'
        '    .coverage\n'
        '    tags\n'
        '    a\n'
        '    b\n'
        '    c\n'
        '    d\n'
        '    e\n'
        '    f\n'
        '    g\n'
        '    h\n'
        '    (and 2 more)\n'
        "[####################] 1/0"
    )
    assert task.dirty
示例#3
0
def test_RepoTask_check_call_status_handling(mock_subprocess_Popen):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress)
    task = wrangler.repo_task(Repo('xyzzy'))
    mock_subprocess_Popen.rc = 1
    task.check_call(['git', 'fail'])
    assert show_ansi_result(buf.getvalue()) == ('+ xyzzy (failed)\n'
                                                '    git fail exited with 1\n'
                                                "[####################] 1/0")
示例#4
0
def test_RepoTask_call_status_handling(mock_subprocess_Popen):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress)
    task = wrangler.repo_task(Repo('xyzzy'))
    mock_subprocess_Popen.rc = 1
    assert task.call(['git', 'diff', '--quiet']) == 1
    # no failure message should be shown because a non-zero status code is
    # not a failure!
    assert show_ansi_result(buf.getvalue()) == ('+ xyzzy\n'
                                                "[####################] 1/0")
示例#5
0
def test_RepoTask_call_error_handling(mock_subprocess_Popen):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress)
    task = wrangler.repo_task(Repo('xyzzy'))
    mock_subprocess_Popen.stdout = b'oh no\n'
    mock_subprocess_Popen.rc = 0
    assert task.call(['git', 'fail', '--please']) == 0
    assert show_ansi_result(buf.getvalue()) == ('+ xyzzy\n'
                                                '    oh no\n'
                                                '    git fail exited with 0\n'
                                                "[####################] 1/0")
示例#6
0
def test_RepoTask_run_in_quiet_mode(monkeypatch):
    monkeypatch.setattr(os.path, 'exists', lambda dir: True)
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress, quiet=True)
    task = wrangler.repo_task(Repo('xyzzy'))
    task.get_current_branch = lambda dir: 'master'
    task.run()
    assert show_ansi_result(buf.getvalue()) == ("[####################] 1/0")
    assert wrangler.n_repos == 1
    assert wrangler.n_new == 0
    assert wrangler.n_updated == 0
    assert wrangler.n_dirty == 0
示例#7
0
def test_RepoTask_aborted(monkeypatch):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress, quiet=True)
    task = wrangler.repo_task(Repo('xyzzy'))
    task.get_current_branch = lambda dir: 'master'
    task.aborted()
    assert show_ansi_result(buf.getvalue()) == ('+ xyzzy (aborted)\n'
                                                "[####################] 1/0")
    assert wrangler.n_repos == 1
    assert wrangler.n_new == 0
    assert wrangler.n_updated == 0
    assert wrangler.n_dirty == 0
示例#8
0
def test_RepoWrangler_list_repos_for_org(mock_requests_get):
    mock_requests_get.update(mock_multi_page_api_responses(
        url='https://api.github.com/orgs/test_org/repos',
        pages=[
            [
                repo('xyzzy'),
            ],
        ],
    ))
    wrangler = ghcloneall.RepoWrangler()
    result = wrangler.list_repos(organization='test_org')
    assert result == [
        Repo('xyzzy'),
    ]
示例#9
0
def test_RepoWrangler_repo_task(monkeypatch):
    monkeypatch.setattr(os.path, 'exists', lambda dir: False)
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress)
    task = wrangler.repo_task(Repo('xyzzy'))
    compare(buf.getvalue(), "{brown}+ xyzzy{reset}\n"
            "{cr}[####################] 1/0{cr}")
    task.run()
    assert show_ansi_result(buf.getvalue()) == ('+ xyzzy (new)\n'
                                                "[####################] 1/0")
    assert wrangler.n_repos == 1
    assert wrangler.n_new == 1
    assert wrangler.n_updated == 0
    assert wrangler.n_dirty == 0
示例#10
0
def test_RepoTask_run_handles_errors(monkeypatch):
    monkeypatch.setattr(os.path, 'exists', lambda dir: False)
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress)
    task = wrangler.repo_task(Repo('xyzzy'))
    task.clone = raise_exception
    task.run()
    assert show_ansi_result(buf.getvalue()) == ('+ xyzzy\n'
                                                '    Exception: oh no\n'
                                                "[####################] 1/0")
    assert wrangler.n_repos == 1
    assert wrangler.n_new == 0
    assert wrangler.n_updated == 0
    assert wrangler.n_dirty == 0
示例#11
0
def test_RepoWrangler_list_repos_filter_by_name(mock_requests_get):
    mock_requests_get.update(mock_multi_page_api_responses(
        url='https://api.github.com/users/test_user/repos',
        pages=[
            [
                repo('xyzzy'),
                repo('project-foo'),
            ],
        ],
    ))
    wrangler = ghcloneall.RepoWrangler()
    result = wrangler.list_repos(user='******', pattern='pr*')
    assert result == [
        Repo('project-foo'),
    ]
示例#12
0
def test_RepoTask_run_updates(monkeypatch, ):
    monkeypatch.setattr(os.path, 'exists', lambda dir: True)
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress)
    task = wrangler.repo_task(Repo('xyzzy'))
    responses = ['aaaaa', 'bbbbb']
    task.get_current_commit = lambda dir: responses.pop(0)
    task.get_current_branch = lambda dir: 'master'
    task.run()
    assert show_ansi_result(buf.getvalue()) == ('+ xyzzy (updated)\n'
                                                "[####################] 1/0")
    assert wrangler.n_repos == 1
    assert wrangler.n_new == 0
    assert wrangler.n_updated == 1
    assert wrangler.n_dirty == 0
示例#13
0
def test_RepoWrangler_list_gists_filtering(mock_requests_get):
    mock_requests_get.update(mock_multi_page_api_responses(
        url='https://api.github.com/users/test_user/gists',
        extra='',
        pages=[
            [
                gist('9999'),
                gist('1234'),
            ],
        ],
    ))
    wrangler = ghcloneall.RepoWrangler()
    result = wrangler.list_gists(user='******', pattern='9*')
    assert result == [
        Gist('9999'),
    ]
示例#14
0
def test_RepoWrangler_list_repos_filter_by_status(mock_requests_get):
    mock_requests_get.update(
        mock_multi_page_api_responses(
            url='https://api.github.com/users/test_user/repos',
            pages=[
                [
                    repo('a', archived=True),
                    repo('f', fork=True),
                    repo('p', private=True),
                    repo('d', private=True, disabled=True),
                    repo('c'),
                ],
            ],
        ))
    wrangler = ghcloneall.RepoWrangler()
    result = wrangler.list_repos(user='******')
    assert result == [
        Repo('c'),
        Repo('d', private=True, disabled=True),
        Repo('p', private=True),
    ]
    result = wrangler.list_repos(user='******', include_archived=True)
    assert result == [
        Repo('a', archived=True),
        Repo('c'),
        Repo('d', private=True, disabled=True),
        Repo('p', private=True),
    ]
    result = wrangler.list_repos(user='******', include_forks=True)
    assert result == [
        Repo('c'),
        Repo('d', private=True, disabled=True),
        Repo('f', fork=True),
        Repo('p', private=True),
    ]
    result = wrangler.list_repos(user='******', include_disabled=False)
    assert result == [
        Repo('c'),
        Repo('p', private=True),
    ]
    result = wrangler.list_repos(user='******', include_private=False)
    assert result == [
        Repo('c'),
    ]
示例#15
0
def test_RepoTask_verify():
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    wrangler = ghcloneall.RepoWrangler(progress=progress, verbose=2)
    task = wrangler.repo_task(Repo('xyzzy'))
    task.get_current_branch = lambda dir: 'boo'
    task.get_remote_url = lambda dir: '[email protected]:test_user/xyzzy'
    task.has_local_changes = lambda dir: True
    task.has_staged_changes = lambda dir: True
    task.has_local_commits = lambda dir: True
    task.verify(task.repo, 'xyzzy')
    # NB: we can see that the output doesn't work right when the terminal
    # width is 80 instead of 100, but I'm not up to fixing it today
    assert show_ansi_result(buf.getvalue(), width=100) == (
        '+ xyzzy (local changes) (staged changes) (local commits)'
        ' (not on master) (wrong remote url)\n'
        '    branch: boo\n'
        '    remote: [email protected]:test_user/xyzzy.git\n'
        '    expected: [email protected]:test_user/xyzzy.git\n'
        '    alternatively: https://github.com/test_user/xyzzy\n'
        "[####################] 1/0")
    assert task.dirty
示例#16
0
def test_RepoWrangler_list_repos_missing_arguments():
    wrangler = ghcloneall.RepoWrangler()
    with pytest.raises(ValueError):
        wrangler.list_repos()
示例#17
0
def test_RepoWrangler_auth():
    token = 'UNITTEST'
    wrangler = ghcloneall.RepoWrangler(token=token)
    assert wrangler.session.auth == ('', token)