mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Updated tests for validate manifest
This commit is contained in:
parent
e5f4c61608
commit
74923ef252
3 changed files with 17 additions and 52 deletions
|
|
@ -55,7 +55,11 @@ def test_defaults_to_backup_filename(noop_validator):
|
|||
|
||||
def test_raises_for_failing_schema(array_validator):
|
||||
with pytest.raises(ValueError):
|
||||
array_validator('tests/data/non_parseable_yaml_file.yaml')
|
||||
array_validator('tests/data/valid_yaml_but_invalid_manifest.yaml')
|
||||
|
||||
|
||||
def test_passes_array_schema(array_validator):
|
||||
array_validator('tests/data/array_yaml_file.yaml')
|
||||
|
||||
|
||||
def test_raises_when_additional_validation_fails(additional_validator):
|
||||
|
|
|
|||
|
|
@ -1,62 +1,21 @@
|
|||
|
||||
import __builtin__
|
||||
import pytest
|
||||
import mock
|
||||
from plumbum import local
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.clientlib.validate_manifest import run, InvalidManifestError, \
|
||||
additional_manifest_check
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def print_mock():
|
||||
with mock.patch.object(__builtin__, 'print', autospec=True) as print_mock_obj:
|
||||
yield print_mock_obj
|
||||
|
||||
|
||||
def test_run_returns_1_for_non_existent_module(print_mock):
|
||||
non_existent_filename = 'file_that_does_not_exist'
|
||||
ret = run([non_existent_filename])
|
||||
assert ret == 1
|
||||
print_mock.assert_called_once_with(
|
||||
'File {0} does not exist'.format(non_existent_filename),
|
||||
)
|
||||
|
||||
|
||||
def test_run_returns_1_for_non_yaml_file(print_mock):
|
||||
non_parseable_filename = 'tests/data/non_parseable_yaml_file.yaml'
|
||||
ret = run([non_parseable_filename])
|
||||
assert ret == 1
|
||||
print_mock.assert_any_call(
|
||||
'File {0} is not a valid yaml file'.format(non_parseable_filename),
|
||||
)
|
||||
|
||||
|
||||
def test_returns_1_for_valid_yaml_file_but_invalid_manifest(print_mock):
|
||||
invalid_manifest = 'tests/data/valid_yaml_but_invalid_manifest.yaml'
|
||||
ret = run([invalid_manifest])
|
||||
assert ret == 1
|
||||
print_mock.assert_any_call(
|
||||
'File {0} is not a valid file'.format(invalid_manifest)
|
||||
)
|
||||
from pre_commit.clientlib.validate_manifest import additional_manifest_check
|
||||
from pre_commit.clientlib.validate_manifest import InvalidManifestError
|
||||
from pre_commit.clientlib.validate_manifest import run
|
||||
|
||||
|
||||
def test_returns_0_for_valid_manifest():
|
||||
valid_manifest = 'example_manifest.yaml'
|
||||
ret = run([valid_manifest])
|
||||
assert ret == 0
|
||||
assert run(['example_manifest.yaml']) == 0
|
||||
|
||||
|
||||
def test_uses_default_manifest_file_at_root_of_git(empty_git_dir):
|
||||
local.path(C.MANIFEST_FILE).write("""
|
||||
-
|
||||
id: foo
|
||||
name: Foo
|
||||
entry: foo
|
||||
""")
|
||||
ret = run([])
|
||||
assert ret == 0
|
||||
def test_returns_0_for_our_manifest():
|
||||
assert run([]) == 0
|
||||
|
||||
|
||||
def test_returns_1_for_failing():
|
||||
assert run(['tests/data/valid_yaml_but_invalid_manifest.yaml']) == 1
|
||||
|
||||
|
||||
def test_additional_manifest_check_raises_for_bad_language():
|
||||
|
|
|
|||
2
tests/data/array_yaml_file.yaml
Normal file
2
tests/data/array_yaml_file.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
- foo
|
||||
- bar
|
||||
Loading…
Add table
Add a link
Reference in a new issue