Example #1
0
def test_git_cmd_returns_std_out():
    with fleeting_repo() as test_repo:
        commit_msg = 'I remain committed.'
        test_repo.commit([('test.txt', 'testing\n')],
                         commit_msg=commit_msg)

        with git_cmd(["log"], cwd=test_repo.repo_root) as output_f:
            ok_(commit_msg in util.utf8(output_f.read()))
Example #2
0
def test_find_git_root():
    with fleeting_repo() as test_repo:
        test_repo.commit([('test_proj/test.txt', 'testing\n')])
        git_root = test_repo.repo_root
        test_proj_root = os.path.join(git_root, 'test_proj')
        # should work both for subdirectories
        eq_(git_root, find_git_root(test_proj_root))
        # and for top-level projects
        eq_(git_root, find_git_root(git_root))
Example #3
0
def test_parse_log_stream():
    # do from 1 to 3 commits
    for num_commits in range(1, 3):
        for commit_infos in itertools.permutations(TEST_COMMIT_INFOS,
                                                   num_commits):
            with fleeting_repo() as test_repo:
                for commit_info in commit_infos:
                    _commit_to_test_txt(test_repo, **commit_info._asdict())
                test_txt = os.path.join(test_repo.repo_root, 'test.txt')
                yield _check_parsed_log_entries, test_txt, commit_infos
Example #4
0
def test_parse_log_stream():
    # do from 1 to 3 commits
    for num_commits in range(1, 3):
        for commit_infos in itertools.permutations(TEST_COMMIT_INFOS,
                                                   num_commits):
            with fleeting_repo() as test_repo:
                for commit_info in commit_infos:
                    _commit_to_test_txt(test_repo, **commit_info._asdict())
                test_txt = os.path.join(test_repo.repo_root, 'test.txt')
                yield _check_parsed_log_entries, test_txt, commit_infos
Example #5
0
def test_ls():
    with fleeting_repo() as test_repo:
        test_repo.commit([('test_proj/test.txt', 'testing\n'),
                          ('test_proj/test2.txt', 'testing\n'),
                          ('test3.txt', 'testing\n')])
        git_root = test_repo.repo_root
        test_proj_root = os.path.join(git_root, 'test_proj')
        # ls on the sub-dir project should not include test3.
        eq_(sorted([os.path.join(test_proj_root, f)
                    for f
                    in ('test.txt', 'test2.txt')]),
            project.ls(test_proj_root))
        # ls on the sub-dir project should include test3.
        eq_(sorted([os.path.join(test_proj_root, f)
                    for f
                    in ('test.txt', 'test2.txt')] +
                   [os.path.join(git_root, 'test3.txt')]),
            project.ls(git_root))
Example #6
0
def test_gen_diffscuss_with_path():
    testy_mc = "Testy McTesterson <*****@*****.**>"
    with fleeting_repo() as repo:
        repo.do_git(["config", "user.name", "Testy McTesterson"])
        repo.do_git(["config", "user.email", "*****@*****.**"])
        repo.commit([('README.txt', 'dweezel')],
                    commit_msg="Initial commit")
        repo.commit([('test.txt', 'test!'),
                     ('subdir/foo.txt', 'foo file')],
                    author=testy_mc,
                    commit_msg="First commit message.")
        repo.commit([('test.txt', 'teeest!!'),
                     ('subdir/bar.txt', 'bar file')],
                    author=testy_mc,
                    commit_msg="Second commit message.")

        diffscussion = _run_gen_diffscuss(cwd=repo.repo_root,
                                          revs="HEAD~2..HEAD",
                                          path=['subdir'])

        # Again, not the first commit
        ok_("Initial commit" not in diffscussion)

        # But the yes to the other two...
        ok_("First commit message" in diffscussion)
        ok_("Second commit message" in diffscussion)

        # Nothing about test.txt
        ok_("test.txt" not in diffscussion)
        ok_("+this is the changed first line" not in diffscussion)
        ok_("+this is the second line" not in diffscussion)
        ok_("+this is the new third line" not in diffscussion)

        # But everything else on 'subdir'
        ok_("subdir/foo.txt" in diffscussion)
        ok_("subdir/bar.txt" in diffscussion)
        ok_("+foo file" in diffscussion)
        ok_("+bar file" in diffscussion)
Example #7
0
def test_gen_diffscuss_basics():
    testy_mc = "Testy McTesterson <*****@*****.**>"
    with fleeting_repo() as repo:
        repo.do_git(["config", "user.name", "Testy McTesterson"])
        repo.do_git(["config", "user.email", "*****@*****.**"])
        repo.commit([('README.txt', 'dweezel')],
                    commit_msg="Initial commit")
        repo.commit([('test.txt', '\n'.join(['this is the first line',
                                             'this is the second line',
                                             '']))],
                    author=testy_mc,
                    commit_msg="First commit message.")
        repo.commit([('test.txt', '\n'.join(['this is the changed first line',
                                             'this is the second line',
                                             'this is the new third line',
                                             '']))],
                    author=testy_mc,
                    commit_msg="Second commit message.")

        diffscussion = _run_gen_diffscuss(cwd=repo.repo_root,
                                          revs="HEAD~2..HEAD")

        # do some cheesy tests to make sure strings we expect have /
        # haven't have made it into the diffscussion, before we do
        # line by line comparison, to make it easier to see what's
        # actually going wrong

        # we shouldn't have the initial commit msg
        ok_("Initial commit" not in diffscussion)
        # or the initial commit's diffs
        ok_('README.txt' not in diffscussion)
        ok_('dweezel' not in diffscussion)

        # both included commit logs msgs should be in there
        ok_("First commit message" in diffscussion)
        ok_("Second commit message" in diffscussion)
        # and they should be in chrono order
        ok_(diffscussion.find("First commit message") <
            diffscussion.find("Second commit message"))

        # make sure the diffs came through
        ok_("+this is the changed first line" in diffscussion)
        ok_("+this is the second line" in diffscussion)
        ok_("+this is the new third line" in diffscussion)

        # make sure the author was picked up
        ok_("author: Testy McTesterson" in diffscussion)
        # and the email
        ok_("email: [email protected]" in diffscussion)

        # and some cheesy line by line structure
        lines = diffscussion.split("\n")

        eq_("#* ", lines[0])
        eq_("#* author: Testy McTesterson", lines[1])
        eq_("#* email: [email protected]", lines[2])
        ok_(lines[3].startswith("#* date: "))
        eq_("#* ", lines[4])
        eq_("#- First commit message.", lines[5])
        eq_("#- ", lines[6])
        eq_("#- ", lines[7])
        eq_("#- Second commit message.", lines[8])
        eq_("#- ", lines[9])
        eq_("#- ", lines[10])
        ok_(lines[11].startswith("diff --git"))
        ok_(lines[12].startswith("new file mode"))
        ok_(lines[13].startswith("index"))
        ok_(lines[14].startswith("---"))
        ok_(lines[15].startswith("+++"))
        ok_(lines[16].startswith("@@"))
        eq_("+this is the changed first line", lines[17])
        eq_("+this is the second line", lines[18])
        eq_("+this is the new third line", lines[19])