Repository now parses languages and manifests

This commit is contained in:
Anthony Sottile 2014-03-13 20:33:42 -07:00
parent d77d01cd22
commit 5ca8f4ffa8
8 changed files with 114 additions and 23 deletions

View file

@ -64,4 +64,9 @@ def test_passes_array_schema(array_validator):
def test_raises_when_additional_validation_fails(additional_validator):
with pytest.raises(AdditionalValidatorError):
additional_validator()
additional_validator()
def test_returns_object_after_validating(noop_validator):
ret = noop_validator('tests/data/array_yaml_file.yaml')
assert ret == ['foo', 'bar']

View file

@ -29,7 +29,7 @@ def test_additional_manifest_check_raises_for_bad_language():
@pytest.mark.parametrize(('obj'), (
[{}],
[{'language': 'python'}],
[{'language': 'python>2.6'}],
[{'language': 'ruby'}],
))
def test_additional_manifest_check_is_ok_with_missing_language(obj):
additional_manifest_check(obj)

View file

@ -31,22 +31,17 @@ def dummy_git_repo(empty_git_dir):
@pytest.yield_fixture
def dummy_pre_commit_hooks_git_repo(dummy_git_repo):
def python_pre_commit_git_repo(dummy_git_repo):
local.path(C.MANIFEST_FILE).write("""
hooks:
-
id: foo
name: Foo
entry: foo
language: python>2.6
-
id: foo
name: Foo
entry: foo
language: python
""")
add_and_commit()
yield dummy_git_repo
@pytest.yield_fixture
def python_pre_commit_git_repo(dummy_pre_commit_hooks_git_repo):
local.path('setup.py').write("""
from setuptools import find_packages
from setuptools import setup
@ -61,8 +56,7 @@ setup(
],
}
)
"""
)
""")
foo_module = local.path('foo')
@ -73,12 +67,11 @@ setup(
local.path('main.py').write("""
def func():
return 0
"""
)
""")
add_and_commit()
yield dummy_pre_commit_hooks_git_repo
yield dummy_git_repo
@pytest.fixture

View file

@ -1,9 +1,10 @@
import os
import jsonschema
import pytest
from pre_commit import git
import pre_commit.constants as C
from pre_commit import git
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
from pre_commit.repository import Repository
@ -40,3 +41,36 @@ def test_install_python_repo_in_env(python_pre_commit_git_repo, config_for_pytho
'py_env',
),
)
@pytest.fixture
def mock_repo_config():
config = {
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
'sha': '5e713f8878b7d100c0e059f8cc34be4fc2e8f897',
'hooks': [{
'id': 'pyflakes',
'files': '*.py',
}],
}
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
return config
def test_repo_url(mock_repo_config):
repo = Repository(mock_repo_config)
assert repo.repo_url == 'git@github.com:pre-commit/pre-commit-hooks'
def test_sha(mock_repo_config):
repo = Repository(mock_repo_config)
assert repo.sha == '5e713f8878b7d100c0e059f8cc34be4fc2e8f897'
@pytest.mark.integration
def test_languages(config_for_python_pre_commit_git_repo):
repo = Repository(config_for_python_pre_commit_git_repo)
assert repo.languages == set(['python'])