Ejemplo n.º 1
0
def test_python_init(gitrepo):
    """ Test whether the __init__.py file is properly accepted """

    file_ini = util.write_file(gitrepo, '__init__.py', '')
    assert githooks.precommit_hook(util.install_path())

    util.cmd(gitrepo, 'git add ' + file_ini)
    assert githooks.precommit_hook(util.install_path())

    util.cmd(gitrepo, 'git commit -m python_fail')
    assert githooks.precommit_hook(util.install_path())
Ejemplo n.º 2
0
def test_basic_style_ok(gitrepo):
    """Test whether the basic_style hook will pass when everything is ok"""

    # Create file 'a'
    file_a = util.write_file(gitrepo, 'a.ml', '')
    assert githooks.precommit_hook(util.install_path())

    # Add 'a'
    util.cmd(gitrepo, 'git add ' + file_a)
    assert githooks.precommit_hook(util.install_path())

    # Commit 'a'
    util.cmd(gitrepo, 'git commit -m msg')
    assert githooks.precommit_hook(util.install_path())
Ejemplo n.º 3
0
def test_basic_style_problem(gitrepo):
    """Test whether the basic_style hook will fail when something is wrong"""

    # Create file 'a'
    file_a = util.write_file(gitrepo, 'a.java', ' ')
    assert githooks.precommit_hook(util.install_path())

    # Add 'a'
    util.cmd(gitrepo, 'git add ' + file_a)
    assert not githooks.precommit_hook(util.install_path())

    # Commit 'a'
    util.cmd(gitrepo, 'git commit -m msg')
    assert githooks.precommit_hook(util.install_path())
Ejemplo n.º 4
0
def test_python_problem(gitrepo):
    """Test whether the python hook will fail when something is wrong"""

    # Create file 'a'
    file_a = util.write_file(gitrepo, 'a.py', ' ')
    assert githooks.precommit_hook(util.install_path())

    # Add 'a'
    util.cmd(gitrepo, 'git add ' + file_a)
    assert not githooks.precommit_hook(util.install_path())

    # Commit 'a'
    util.cmd(gitrepo, 'git commit -m python_fail')
    assert githooks.precommit_hook(util.install_path())
Ejemplo n.º 5
0
def test_python_ok(gitrepo):
    """Test whether the python hook will fail when everything is ok"""

    # Create file 'a'
    file_a = util.write_ok_pyfile(gitrepo, 'a.py')
    assert githooks.precommit_hook(util.install_path())

    # Add 'a'
    util.cmd(gitrepo, 'git add ' + file_a)
    assert githooks.precommit_hook(util.install_path())

    file_a = util.write_file(gitrepo, 'a.py', ' ')
    assert githooks.precommit_hook(util.install_path())

    # Commit 'a'
    util.cmd(gitrepo, 'git commit -m python_ok')
    assert githooks.precommit_hook(util.install_path())
Ejemplo n.º 6
0
def test_message_update_fail(gitrepo):
    """ Test whether the update hook will fail when a message is wrong """

    # Create file 'a'
    file_a = util.write_file(gitrepo, 'a.ml', '')
    assert githooks.precommit_hook(util.install_path())

    # Add 'a'
    util.cmd(gitrepo, 'git add ' + file_a)
    assert githooks.precommit_hook(util.install_path())

    # Commit 'a'
    util.cmd(gitrepo, 'git commit -m VFTEST-0')
    assert githooks.precommit_hook(util.install_path())

    start = gitinfo.current_commit_hash()

    # Create file 'b'
    file_b = util.write_file(gitrepo, 'b.ml', '')
    assert githooks.precommit_hook(util.install_path())

    # Add 'b'
    util.cmd(gitrepo, 'git add ' + file_b)
    assert githooks.precommit_hook(util.install_path())

    # Commit 'b'
    util.cmd(gitrepo, 'git commit -m VFTEST-X')
    assert githooks.precommit_hook(util.install_path())

    end = gitinfo.current_commit_hash()

    assert not githooks.update_hook("master", start, end, util.install_path())
Ejemplo n.º 7
0
def test_tmp_score(gitrepo):
    """ Test whether a tmp file has the same score as its original """
    file_a = util.write_ok_pyfile(gitrepo, 'a.py')
    assert githooks.precommit_hook(util.install_path())

    # Add 'a'
    util.cmd(gitrepo, 'git add ' + file_a)
    assert githooks.precommit_hook(util.install_path())

    # Commit 'a'
    util.cmd(gitrepo, 'git commit -m python_ok')
    assert githooks.precommit_hook(util.install_path())

    config = pylint.config_from_pylintrc()

    real_out = pylint.pylint(config, file_a)

    file_tmp = gitinfo.revision_tmp_file(gitinfo.current_commit(), file_a)

    tmp_out = pylint.pylint(config, file_tmp)
    print tmp_out

    assert pylint.parse_score(real_out) == pylint.parse_score(tmp_out)