mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Write test for auto-validating manifest at root of repo
This commit is contained in:
parent
37e94b1e1e
commit
9fa237fbe0
4 changed files with 27 additions and 22 deletions
|
|
@ -3,7 +3,9 @@ import __builtin__
|
|||
import jsonschema
|
||||
import pytest
|
||||
import mock
|
||||
from plumbum import local
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.clientlib.validate_manifest import check_is_valid_manifest
|
||||
from pre_commit.clientlib.validate_manifest import InvalidManifestError
|
||||
from pre_commit.clientlib.validate_manifest import run
|
||||
|
|
@ -48,6 +50,18 @@ def test_returns_0_for_valid_manifest():
|
|||
assert ret == 0
|
||||
|
||||
|
||||
def test_uses_default_manifest_file_at_root_of_git(empty_git_dir):
|
||||
local.path(C.MANIFEST_FILE).write("""
|
||||
hooks:
|
||||
-
|
||||
id: foo
|
||||
name: Foo
|
||||
entry: foo
|
||||
""")
|
||||
ret = run([])
|
||||
assert ret == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('manifest', 'expected_exception_type'), (
|
||||
(
|
||||
"""
|
||||
|
|
|
|||
10
tests/conftest.py
Normal file
10
tests/conftest.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
import pytest
|
||||
from plumbum import local
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def empty_git_dir(tmpdir):
|
||||
with local.cwd(tmpdir.strpath):
|
||||
local['git']['init']()
|
||||
yield tmpdir.strpath
|
||||
|
|
@ -1,36 +1,17 @@
|
|||
|
||||
import contextlib
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from plumbum import local
|
||||
from pre_commit import git
|
||||
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def in_dir(dir):
|
||||
old_path = local.cwd.getpath()
|
||||
local.cwd.chdir(dir)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
local.cwd.chdir(old_path)
|
||||
|
||||
@pytest.yield_fixture
|
||||
def empty_git_dir(tmpdir):
|
||||
with in_dir(tmpdir.strpath):
|
||||
local['git']['init']()
|
||||
yield tmpdir.strpath
|
||||
|
||||
|
||||
def test_get_root(empty_git_dir):
|
||||
assert git.get_root() == empty_git_dir
|
||||
|
||||
foo = local.path('foo')
|
||||
foo.mkdir()
|
||||
|
||||
with in_dir(foo):
|
||||
with local.cwd(foo):
|
||||
assert git.get_root() == empty_git_dir
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue