Exemple #1
0
    def prepare(self, previous_values):
        mkdir(self.test_env['working_dir'])
        sync_tree(self.test_env['test_dir'], self.test_env['working_dir'])

        # Create .gps
        self.gps_home = os.path.join(self.test_env['working_dir'], '.gps')
        mkdir(self.gps_home)
        mkdir(os.path.join(self.gps_home, 'plug-ins'))
        mkdir(os.path.join(self.gps_home, 'log_files'))
        echo_to_file(os.path.join(self.gps_home, 'preferences.xml'), PREFS)
        echo_to_file(os.path.join(self.gps_home, "gnatinspect_traces.cfg"),
                     ">gnatinspect.log\n")
Exemple #2
0
def test_svn_repo():
    cwd = os.getcwd()

    # --- create local project
    project_path = os.path.join(cwd, "test_project")
    mkdir(project_path)
    mkdir(os.path.join(project_path, "trunk"))
    hello_relative_path = os.path.join("trunk", "hello.txt")
    hello_path = os.path.join(project_path, hello_relative_path)
    echo_to_file(hello_path, "hello")

    # --- create a SVN repository from that project
    repos_path = os.path.join(cwd, "repos")
    project_url = SVNRepository.create(repo_path=repos_path)
    project_url = project_url + "/Test_Project"
    p = Run(
        ["svn", "import", project_path, project_url, "-m", "initial import"])
    assert p.status == 0, p.out

    # --- checkout project into working dir A
    working_copy_a_path = os.path.join(cwd, "working_copy_a")
    svn_a = SVNRepository(working_copy_a_path)
    with pytest.raises(SVNError):
        svn_a.update()
    with pytest.raises(SVNError):
        svn_a.update(url=file_url("bad_url"))
    local_change = svn_a.update(project_url)
    assert local_change
    local_change = svn_a.update()
    assert not local_change
    # verify the content of the working dir A and its revision
    assert svn_a.url == project_url
    assert os.path.exists(
        os.path.join(working_copy_a_path,
                     hello_relative_path)), "checkout failed"
    assert svn_a.current_revision == "1"
    # modify the working dir, commit the change,
    # update the working dir and verify the new current revision
    echo_to_file(os.path.join(working_copy_a_path, hello_relative_path), "bye")
    svn_a.svn_cmd(["commit", "-m", "modify hello"])
    svn_a.update()
    assert svn_a.current_revision == "2"
    svn_a.update(revision="1")
    assert svn_a.current_revision == "1"
    with pytest.raises(SVNError):
        svn_a.update(revision="404")

    # make local changes in the working dir B before updating it
    working_copy_b_path = os.path.join(cwd, "working_copy_b")
    svn_b = SVNRepository(working_copy_b_path)
    svn_b.update(project_url)
    foo_path = os.path.join(working_copy_b_path, "trunk", "foo")
    touch(foo_path)
    hello_b_path = os.path.join(working_copy_b_path, hello_relative_path)
    echo_to_file(hello_b_path, "kitty")
    local_change = svn_b.update()
    assert local_change
    assert os.path.exists(foo_path)
    with open(hello_b_path, "r") as f:
        assert "kitty" in f.read()
    # update and cancel all changes
    svn_b.update(force_and_clean=True)
    assert not os.path.exists(foo_path)
    with open(hello_b_path, "r") as f:
        assert "bye" in f.read()

    # checkout into an existing path (not versioned)
    working_copy_c_path = os.path.join(cwd, "working_copy_c")
    svn_c = SVNRepository(working_copy_c_path)
    touch(working_copy_c_path)
    with pytest.raises(SVNError) as err:
        svn_c.update(url=project_url)
    assert "not empty" in str(err)
    rm(working_copy_c_path)
    mkdir(working_copy_c_path)

    bar_path = os.path.join(working_copy_c_path, "bar")
    touch(bar_path)
    # verify failures without the force option
    with pytest.raises(SVNError) as err:
        svn_c.update(url=project_url)
    assert "not empty" in str(err)
    touch(os.path.join(working_copy_c_path, ".svn"))
    with pytest.raises(SVNError):
        svn_c.update(url=project_url)
    svn_c.update(url=project_url, force_and_clean=True)
    # verify that the working dir C is clean
    assert not os.path.exists(bar_path)

    # modify a working dir and update it with a new project
    svn_d = SVNRepository(working_copy_c_path)
    touch(bar_path)
    svn_d.update()  # update with the last URL used for this dir
    svn_d.update(url=project_url)  # update with the same URL
    assert os.path.exists(bar_path)
    project2_url = project_url + "2"
    p = Run(
        ["svn", "import", project_path, project2_url, "-m", "initial import"])
    assert p.status == 0, p.out
    with pytest.raises(SVNError) as err:
        svn_d.update(url=project2_url)  # update with new URL
    assert "not empty" in str(err)
    svn_d.update(url=project2_url, force_and_clean=True)
    assert svn_d.url == project2_url
Exemple #3
0
def test_svn_repo():
    cwd = os.getcwd()

    # --- create local project
    project_path = os.path.join(cwd, 'test_project')
    mkdir(project_path)
    mkdir(os.path.join(project_path, 'trunk'))
    hello_relative_path = os.path.join('trunk', 'hello.txt')
    hello_path = os.path.join(project_path, hello_relative_path)
    echo_to_file(hello_path, 'hello')

    # --- create a SVN repository from that project
    repos_path = os.path.join(cwd, 'repos')
    project_url = file_url(repos_path + '/Test_project')
    p = Run(['svnadmin', 'create', repos_path])
    assert p.status == 0, p.out
    p = Run(
        ['svn', 'import', project_path, project_url, '-m', 'initial import'])
    assert p.status == 0, p.out

    # --- checkout project into working dir A
    working_copy_a_path = os.path.join(cwd, 'working_copy_a')
    svn_a = SVNRepository(working_copy_a_path)
    with pytest.raises(SVNError):
        svn_a.update()
    with pytest.raises(SVNError):
        svn_a.update(url=file_url('bad_url'))
    local_change = svn_a.update(project_url)
    assert local_change
    local_change = svn_a.update()
    assert not local_change
    # verify the content of the working dir A and its revision
    assert svn_a.url == project_url
    assert os.path.exists(
        os.path.join(working_copy_a_path,
                     hello_relative_path)), 'checkout failed'
    assert svn_a.current_revision == '1'
    # modify the working dir, commit the change,
    # update the working dir and verify the new current revision
    echo_to_file(os.path.join(working_copy_a_path, hello_relative_path), 'bye')
    svn_a.svn_cmd(['commit', '-m', 'modify hello'])
    svn_a.update()
    assert svn_a.current_revision == '2'
    svn_a.update(revision='1')
    assert svn_a.current_revision == '1'
    with pytest.raises(SVNError):
        svn_a.update(revision='404')

    # make local changes in the working dir B before updating it
    working_copy_b_path = os.path.join(cwd, 'working_copy_b')
    svn_b = SVNRepository(working_copy_b_path)
    svn_b.update(project_url)
    foo_path = os.path.join(working_copy_b_path, 'trunk', 'foo')
    touch(foo_path)
    hello_b_path = os.path.join(working_copy_b_path, hello_relative_path)
    echo_to_file(hello_b_path, 'kitty')
    local_change = svn_b.update()
    assert local_change
    assert os.path.exists(foo_path)
    with open(hello_b_path, 'r') as f:
        assert 'kitty' in f.read()
    # update and cancel all changes
    svn_b.update(force_and_clean=True)
    assert not os.path.exists(foo_path)
    with open(hello_b_path, 'r') as f:
        assert 'bye' in f.read()

    # checkout into an existing path (not versioned)
    working_copy_c_path = os.path.join(cwd, 'working_copy_c')
    svn_c = SVNRepository(working_copy_c_path)
    touch(working_copy_c_path)
    with pytest.raises(SVNError) as err:
        svn_c.update(url=project_url)
    assert 'not empty' in str(err)
    rm(working_copy_c_path)
    mkdir(working_copy_c_path)

    bar_path = os.path.join(working_copy_c_path, 'bar')
    touch(bar_path)
    # verify failures without the force option
    with pytest.raises(SVNError) as err:
        svn_c.update(url=project_url)
    assert 'not empty' in str(err)
    touch(os.path.join(working_copy_c_path, '.svn'))
    with pytest.raises(SVNError):
        svn_c.update(url=project_url)
    svn_c.update(url=project_url, force_and_clean=True)
    # verify that the working dir C is clean
    assert not os.path.exists(bar_path)

    # modify a working dir and update it with a new project
    svn_d = SVNRepository(working_copy_c_path)
    touch(bar_path)
    svn_d.update()  # update with the last URL used for this dir
    svn_d.update(url=project_url)  # update with the same URL
    assert os.path.exists(bar_path)
    project2_url = project_url + '2'
    p = Run(
        ['svn', 'import', project_path, project2_url, '-m', 'initial import'])
    assert p.status == 0, p.out
    with pytest.raises(SVNError) as err:
        svn_d.update(url=project2_url)  # update with new URL
    assert 'not empty' in str(err)
    svn_d.update(url=project2_url, force_and_clean=True)
    assert svn_d.url == project2_url
Exemple #4
0
def test_git_repo():
    working_tree = unixpath(os.path.join(os.getcwd(), 'working_tree'))
    working_tree2 = os.path.join(os.getcwd(), 'working_tree2')
    repo = GitRepository(working_tree)
    repo.init()
    os.chdir(working_tree)
    new_file = unixpath(os.path.join(working_tree, 'new.txt'))
    echo_to_file(new_file, 'new\n')
    repo.git_cmd(['add', 'new.txt'])
    repo.git_cmd(['config', 'user.email', '*****@*****.**'])
    repo.git_cmd(['config', 'user.name', 'e3 core'])
    repo.git_cmd(['commit', '-m', 'new file'])
    repo.git_cmd(['tag', '-a', '-m', 'new tag', '20.0855369232'])

    with open('log.txt', 'w') as f:
        repo.write_log(f)
    with open('log.txt', 'r') as f:
        commits = list(repo.parse_log(f))
        assert 'new file' in commits[0]['message']
        assert commits[0]['email'] == '*****@*****.**'
        new_sha = commits[0]['sha']

    assert '20.0855369232' in repo.describe()
    assert new_sha == repo.rev_parse()

    with pytest.raises(GitError) as err:
        repo.describe('g')
    assert 'describe --always g' in str(err)

    echo_to_file(new_file, 'new line\n', append=True)

    with open('commit1.diff', 'wb') as f:
        repo.write_local_diff(f)

    with open('commit1.diff', 'rb') as f:
        assert b'+new line' in f.read()

    echo_to_file(new_file, 10000 * '*')

    repo.git_cmd(['commit', '-a', '-m', 'file update'])
    with open('log2.txt', 'w') as f:
        repo.write_log(f)
    with open('log2.txt', 'r') as f:
        commits = list(repo.parse_log(f, max_diff_size=1000))
        # assert b'diff too long' not in commits[1]['diff']
        assert 'file update' in commits[0]['message']
        assert 'diff too long' in commits[0]['diff']
        assert 'new file' in commits[1]['message']
        assert commits[1]['sha'] != commits[0]['sha']
        assert commits[1]['diff'] != commits[0]['diff']

    repo2 = GitRepository(working_tree2)
    repo2.init(url=working_tree, remote='tree1')
    try:
        repo2.update(url=working_tree, refspec='master')
    except GitError:
        if sys.platform == 'win32':
            # some git versions on windows do not support that well
            # ignore this test for now???
            pass
    else:
        repo2.rev_parse() == repo.rev_parse()
Exemple #5
0
def test_git_repo():
    working_tree = os.path.join(os.getcwd(), "working_tree")
    working_tree2 = os.path.join(os.getcwd(), "working_tree2")
    repo = GitRepository(working_tree)
    repo.init()
    os.chdir(working_tree)
    new_file = os.path.join(working_tree, "new.txt")
    echo_to_file(new_file, "new\n")

    commit_note = unixpath(os.path.join(working_tree, "commit_note.txt"))
    echo_to_file(
        commit_note,
        "\n".join((
            "Code-Review+2: Nobody <*****@*****.**>",
            "Submitted-by: Nobody <*****@*****.**>",
            "Submitted-at: Thu, 08 Jun 2017 18:40:11 +0200",
        )),
    )

    repo.git_cmd(["add", "new.txt"])
    repo.git_cmd(["config", "user.email", "*****@*****.**"])
    repo.git_cmd(["config", "user.name", "e3 core"])
    repo.git_cmd(["commit", "-m", "new file"])
    repo.git_cmd(["tag", "-a", "-m", "new tag", "20.0855369232"])
    repo.git_cmd(
        ["notes", "--ref", "review", "add", "HEAD", "-F", commit_note])

    # try with gerrit notes
    with open("log.txt", "w") as f:
        repo.write_log(f, with_gerrit_notes=True)
    with open("log.txt") as f:
        commits = list(repo.parse_log(f))
        assert "*****@*****.**" in commits[0]["notes"]["Code-Review+2"]

    # try with an invalid note
    repo.git_cmd([
        "notes", "--ref", "review", "add", "HEAD", "-f", "-m", "invalid-note"
    ])
    with open("log.txt", "w") as f:
        repo.write_log(f, with_gerrit_notes=True)
    with open("log.txt") as f:
        commits = list(repo.parse_log(f))
        assert commits[0]["notes"] is None

    # try again without gerrit notes
    with open("log.txt", "w") as f:
        repo.write_log(f)
    with open("log.txt") as f:
        commits = list(repo.parse_log(f))
        assert "new file" in commits[0]["message"]
        assert commits[0]["email"] == "*****@*****.**"
        new_sha = commits[0]["sha"]

    assert "20.0855369232" in repo.describe()
    assert new_sha == repo.rev_parse()

    with pytest.raises(GitError) as err:
        repo.describe("g")
    assert "describe --always g" in str(err)

    echo_to_file(new_file, "new line\n", append=True)

    with open("commit1.diff", "wb") as f:
        repo.write_local_diff(f)

    with open("commit1.diff", "rb") as f:
        assert b"+new line" in f.read()

    echo_to_file(new_file, 10000 * "*")

    repo.git_cmd(["commit", "-a", "-m", "file update"])
    with open("log2.txt", "w") as f:
        repo.write_log(f)
    with open("log2.txt") as f:
        commits = list(repo.parse_log(f, max_diff_size=1000))
        # assert b'diff too long' not in commits[1]['diff']
        assert "file update" in commits[0]["message"]
        assert "diff too long" in commits[0]["diff"]
        assert "new file" in commits[1]["message"]
        assert commits[1]["sha"] != commits[0]["sha"]
        assert commits[1]["diff"] != commits[0]["diff"]

    repo2 = GitRepository(working_tree2)
    giturl = "file://%s" % working_tree.replace("\\", "/")
    repo2.init(url=giturl, remote="tree1")
    repo2.update(url=giturl, refspec="master")
    repo2.rev_parse() == repo.rev_parse()

    repo2.fetch_gerrit_notes(url=giturl)
    p = repo2.git_cmd(["notes", "--ref=review", "show", new_sha],
                      output=subprocess.PIPE)
    assert "invalid-note" in p.out
Exemple #6
0
def test_git_repo():
    working_tree = os.path.join(os.getcwd(), 'working_tree')
    working_tree2 = os.path.join(os.getcwd(), 'working_tree2')
    repo = GitRepository(working_tree)
    repo.init()
    os.chdir(working_tree)
    new_file = os.path.join(working_tree, 'new.txt')
    echo_to_file(new_file, 'new\n')

    commit_note = unixpath(os.path.join(working_tree, 'commit_note.txt'))
    echo_to_file(
        commit_note, '\n'.join(
            ('Code-Review+2: Nobody <*****@*****.**>',
             'Submitted-by: Nobody <*****@*****.**>',
             'Submitted-at: Thu, 08 Jun 2017 18:40:11 +0200')))

    repo.git_cmd(['add', 'new.txt'])
    repo.git_cmd(['config', 'user.email', '*****@*****.**'])
    repo.git_cmd(['config', 'user.name', 'e3 core'])
    repo.git_cmd(['commit', '-m', 'new file'])
    repo.git_cmd(['tag', '-a', '-m', 'new tag', '20.0855369232'])
    repo.git_cmd(
        ['notes', '--ref', 'review', 'add', 'HEAD', '-F', commit_note])

    # try with gerrit notes
    with open('log.txt', 'w') as f:
        repo.write_log(f, with_gerrit_notes=True)
    with open('log.txt', 'r') as f:
        commits = list(repo.parse_log(f))
        assert '*****@*****.**' in commits[0]['notes']['Code-Review+2']

    # try with an invalid note
    repo.git_cmd([
        'notes', '--ref', 'review', 'add', 'HEAD', '-f', '-m', 'invalid-note'
    ])
    with open('log.txt', 'w') as f:
        repo.write_log(f, with_gerrit_notes=True)
    with open('log.txt', 'r') as f:
        commits = list(repo.parse_log(f))
        assert commits[0]['notes'] is None

    # try again without gerrit notes
    with open('log.txt', 'w') as f:
        repo.write_log(f)
    with open('log.txt', 'r') as f:
        commits = list(repo.parse_log(f))
        assert 'new file' in commits[0]['message']
        assert commits[0]['email'] == '*****@*****.**'
        new_sha = commits[0]['sha']

    assert '20.0855369232' in repo.describe()
    assert new_sha == repo.rev_parse()

    with pytest.raises(GitError) as err:
        repo.describe('g')
    assert 'describe --always g' in str(err)

    echo_to_file(new_file, 'new line\n', append=True)

    with open('commit1.diff', 'wb') as f:
        repo.write_local_diff(f)

    with open('commit1.diff', 'rb') as f:
        assert b'+new line' in f.read()

    echo_to_file(new_file, 10000 * '*')

    repo.git_cmd(['commit', '-a', '-m', 'file update'])
    with open('log2.txt', 'w') as f:
        repo.write_log(f)
    with open('log2.txt', 'r') as f:
        commits = list(repo.parse_log(f, max_diff_size=1000))
        # assert b'diff too long' not in commits[1]['diff']
        assert 'file update' in commits[0]['message']
        assert 'diff too long' in commits[0]['diff']
        assert 'new file' in commits[1]['message']
        assert commits[1]['sha'] != commits[0]['sha']
        assert commits[1]['diff'] != commits[0]['diff']

    repo2 = GitRepository(working_tree2)
    giturl = 'file://%s' % working_tree.replace('\\', '/')
    repo2.init(url=giturl, remote='tree1')
    repo2.update(url=giturl, refspec='master')
    repo2.rev_parse() == repo.rev_parse()

    repo2.fetch_gerrit_notes(url=giturl)
    p = repo2.git_cmd(['notes', '--ref=review', 'show', new_sha],
                      output=subprocess.PIPE)
    assert 'invalid-note' in p.out