Esempio n. 1
0
def test_Progress_extra_info_not_last_item(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    item1 = progress.item("first repo")
    progress.item("second repo")
    compare(
        buf.getvalue(), '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
        '\r                          \r'
        '{brown}second repo{reset}\n'
        '\r[####################] 2/0\r')
    item1.extra_info("wow such magic")
    compare(
        buf.getvalue(),
        '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
        '\r                          \r'
        '{brown}second repo{reset}\n'
        '\r[####################] 2/0\r'
        # new output
        '{up1}{ins1}    wow such magic\n'
        # plus a redraw of everything below the updated item in case the
        # insertion pushed the progress bar offscreen
        '{brown}second repo{reset}\n'
        '\r                          \r'
        '\r[####################] 2/0\r')
    assert show_ansi_result(buf.getvalue()) == ('first repo\n'
                                                '    wow such magic\n'
                                                'second repo\n'
                                                '[####################] 2/0')
Esempio n. 2
0
def test_Progress_error_info(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    item = progress.item("first repo")
    compare(
        buf.getvalue(),
        '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
    )
    item.error_info("oopsies")
    compare(
        buf.getvalue(),
        '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
        # new output
        '{ins1}    {red}oopsies{reset}\n'
        # plus a redraw in case the insertion pushed the progress bar offscreen
        '\r                          \r'
        '\r[####################] 1/0\r'
    )
    assert show_ansi_result(buf.getvalue()) == (
        'first repo\n'
        '    oopsies\n'
        '[####################] 1/0'
    )
Esempio n. 3
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}")
Esempio n. 4
0
def test_Progress_extra_info_multiple_lines(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    item = progress.item("first repo")
    compare(
        buf.getvalue(),
        '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
    )
    item.extra_info("hi\nho")
    compare(
        buf.getvalue(),
        '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
        # new output
        '{ins2}    hi\n'
        '    ho\n'
        '\r                          \r'
        '\r[####################] 1/0\r'
    )
    assert show_ansi_result(buf.getvalue()) == (
        'first repo\n'
        '    hi\n'
        '    ho\n'
        '[####################] 1/0'
    )
Esempio n. 5
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
Esempio n. 6
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")
Esempio n. 7
0
def test_Progress_context_manager(capsys):
    buf = StringIO()
    with pytest.raises(KeyboardInterrupt):
        with ghcloneall.Progress(stream=buf) as progress:
            progress.item()
            raise KeyboardInterrupt()
    assert buf.getvalue() == ('\r[####################] 1/0\r'
                              '\r                          \r'
                              'Interrupted\n')
    assert show_ansi_result(buf.getvalue()) == ('Interrupted')
Esempio n. 8
0
def test_Progress_extra_info_but_not_really(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    item = progress.item("first repo")
    compare(buf.getvalue(), '{brown}first repo{reset}\n'
            '\r[####################] 1/0\r')
    item.extra_info("")
    compare(buf.getvalue(), '{brown}first repo{reset}\n'
            '\r[####################] 1/0\r')
    assert show_ansi_result(buf.getvalue()) == ('first repo\n'
                                                '[####################] 1/0')
Esempio n. 9
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")
Esempio n. 10
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")
Esempio n. 11
0
def test_Progress(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    progress.status("hello")
    progress.status("world")
    progress.finish("bye")
    assert buf.getvalue() == ('\rhello\r'
                              '\r     \r'
                              '\rworld\r'
                              '\r     \r'
                              'bye\n')
    assert show_ansi_result(buf.getvalue()) == ('bye')
Esempio n. 12
0
def test_Progress_item_finished_and_hidden(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    item = progress.item("first repo")
    compare(buf.getvalue(), '{brown}first repo{reset}\n'
            '\r[####################] 1/0\r')
    item.finished(hide=True)
    compare(
        buf.getvalue(), '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
        '{up1}{del1}')
    assert show_ansi_result(buf.getvalue()) == ('[####################] 1/0')
Esempio n. 13
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
Esempio n. 14
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
Esempio n. 15
0
def test_Progress_no_output_after_finish(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    progress.status("hi")
    progress.finish()
    # these are all ignored
    progress.status("ho")
    progress.clear()
    item = progress.item("boo")
    item.hide()
    item.extra_info("hooo")
    assert buf.getvalue() == ('\rhi\r' '\r  \r')
    assert show_ansi_result(buf.getvalue()) == ''
Esempio n. 16
0
def test_Progress_item_failure(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    item = progress.item("first repo")
    compare(buf.getvalue(), '{brown}first repo{reset}\n'
            '\r[####################] 1/0\r')
    item.update(" - all bad", failed=True)
    compare(
        buf.getvalue(), '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
        '\r{up1}{red}first repo - all bad{reset}\r{down1}')
    assert show_ansi_result(buf.getvalue()) == ('first repo - all bad\n'
                                                '[####################] 1/0')
Esempio n. 17
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
Esempio n. 18
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
Esempio n. 19
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
Esempio n. 20
0
def test_Progress_progress(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    progress.progress()
    assert buf.getvalue() == ('\r[....................] 0/0\r')
    progress.set_limit(5)
    assert buf.getvalue() == ('\r[....................] 0/0\r'
                              '\r                          \r'
                              '\r[....................] 0/5\r')
    progress.item()
    assert buf.getvalue() == ('\r[....................] 0/0\r'
                              '\r                          \r'
                              '\r[....................] 0/5\r'
                              '\r                          \r'
                              '\r[####................] 1/5\r')
    assert show_ansi_result(buf.getvalue()) == ('[####................] 1/5')
Esempio n. 21
0
def test_Progress_extra_info(capsys):
    buf = StringIO()
    progress = ghcloneall.Progress(stream=buf)
    item = progress.item("first repo")
    compare(buf.getvalue(), '{brown}first repo{reset}\n'
            '\r[####################] 1/0\r')
    item.extra_info("this is a very good repo btw")
    compare(
        buf.getvalue(),
        '{brown}first repo{reset}\n'
        '\r[####################] 1/0\r'
        '{ins1}    this is a very good repo btw\n'
        # plus a redraw in case the insertion pushed the progress bar offscreen
        '\r                          \r'
        '\r[####################] 1/0\r')
    assert show_ansi_result(
        buf.getvalue()) == ('first repo\n'
                            '    this is a very good repo btw\n'
                            '[####################] 1/0')
Esempio n. 22
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