added config validation to install tests

This commit is contained in:
Ken Struys 2014-03-13 18:53:58 -07:00
parent 905b99917f
commit 95d9e29996
2 changed files with 25 additions and 17 deletions

View file

@ -41,7 +41,7 @@ CONFIG_JSON_SCHEMA = {
}
validate_manifest = get_validator(
validate_config = get_validator(
C.CONFIG_FILE,
CONFIG_JSON_SCHEMA,
InvalidConfigError,
@ -60,7 +60,7 @@ def run(argv):
args = parser.parse_args(argv)
try:
validate_manifest(args.filename)
validate_config(args.filename)
except InvalidConfigError as e:
print(e.args[0])
# If we have more than one exception argument print the stringified

View file

@ -1,8 +1,10 @@
import jsonschema
import pytest
import os
from plumbum import local
import pre_commit.constants as C
from plumbum import local
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
from pre_commit.installer.repo_installer import create_repo_in_env
from pre_commit.installer.repo_installer import install_pre_commit
@ -26,9 +28,8 @@ def test_install_python_repo_in_env(empty_git_dir, python_pre_commit_git_repo):
assert os.path.exists(os.path.join(python_pre_commit_git_repo, C.PRE_COMMIT_DIR, sha, 'py_env'))
@pytest.mark.integration
def test_install_config(empty_git_dir, python_pre_commit_git_repo):
@pytest.fixture
def simple_config(python_pre_commit_git_repo):
config = [
{
'repo': python_pre_commit_git_repo,
@ -36,17 +37,24 @@ def test_install_config(empty_git_dir, python_pre_commit_git_repo):
'hooks': [
{
'id': 'foo',
'args': [
{
'type': 'files',
'opt': '*.py'
},
]
}
'files': '*.py',
}
],
},
]
for repo in config:
},
]
jsonschema.validate(config, CONFIG_JSON_SCHEMA)
return config
@pytest.mark.integration
def test_install_config(empty_git_dir, python_pre_commit_git_repo, simple_config):
for repo in simple_config:
install_pre_commit(repo['repo'], repo['sha'])
assert os.path.exists(os.path.join(python_pre_commit_git_repo, C.PRE_COMMIT_DIR, config[0]['sha'], 'py_env'))
assert os.path.exists(
os.path.join(
python_pre_commit_git_repo,
C.PRE_COMMIT_DIR, simple_config[0]['sha'],
'py_env',
),
)