mirror of
https://github.com/pre-commit/pre-commit.git
synced 2025-12-31 22:10:04 -06:00
Write test for auto-validating manifest at root of repo
This commit is contained in:
@@ -8,6 +8,7 @@ import os.path
|
||||
import yaml
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import git
|
||||
|
||||
|
||||
class InvalidManifestError(ValueError): pass
|
||||
@@ -69,8 +70,7 @@ def run(argv):
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
if args.filename is None:
|
||||
# TODO: filename = git.get_root() + C.MANIFEST_FILE
|
||||
raise NotImplementedError
|
||||
filename = os.path.join(git.get_root(), C.MANIFEST_FILE)
|
||||
else:
|
||||
filename = args.filename
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user