mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-05-03 05:49:14 -05:00
Simplify prefix a bit
This commit is contained in:
+10
-27
@@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -12,30 +12,16 @@ def norm_slash(*args):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('input', 'expected_prefix'), (
|
||||
norm_slash('.', './'),
|
||||
norm_slash('foo', 'foo/'),
|
||||
norm_slash('bar/', 'bar/'),
|
||||
norm_slash('foo/bar', 'foo/bar/'),
|
||||
norm_slash('foo/bar/', 'foo/bar/'),
|
||||
('prefix', 'path_end', 'expected_output'),
|
||||
(
|
||||
norm_slash('foo', '', 'foo'),
|
||||
norm_slash('foo', 'bar', 'foo/bar'),
|
||||
norm_slash('foo/bar', '../baz', 'foo/baz'),
|
||||
norm_slash('./', 'bar', 'bar'),
|
||||
norm_slash('./', '', '.'),
|
||||
norm_slash('/tmp/foo', '/tmp/bar', '/tmp/bar'),
|
||||
),
|
||||
)
|
||||
def test_init_normalizes_path_endings(input, expected_prefix):
|
||||
instance = Prefix(input)
|
||||
assert instance.prefix_dir == expected_prefix
|
||||
|
||||
|
||||
PATH_TESTS = (
|
||||
norm_slash('foo', '', 'foo'),
|
||||
norm_slash('foo', 'bar', 'foo/bar'),
|
||||
norm_slash('foo/bar', '../baz', 'foo/baz'),
|
||||
norm_slash('./', 'bar', 'bar'),
|
||||
norm_slash('./', '', '.'),
|
||||
norm_slash('/tmp/foo', '/tmp/bar', '/tmp/bar'),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('prefix', 'path_end', 'expected_output'), PATH_TESTS)
|
||||
def test_path(prefix, path_end, expected_output):
|
||||
instance = Prefix(prefix)
|
||||
ret = instance.path(path_end)
|
||||
@@ -48,10 +34,7 @@ def test_path_multiple_args():
|
||||
assert ret == os.path.join('foo', 'bar', 'baz')
|
||||
|
||||
|
||||
def test_exists_does_not_exist(tmpdir):
|
||||
def test_exists(tmpdir):
|
||||
assert not Prefix(str(tmpdir)).exists('foo')
|
||||
|
||||
|
||||
def test_exists_does_exist(tmpdir):
|
||||
tmpdir.ensure('foo')
|
||||
assert Prefix(str(tmpdir)).exists('foo')
|
||||
|
||||
Reference in New Issue
Block a user