forked from pre-commit/pre-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefix_test.py
More file actions
40 lines (29 loc) · 991 Bytes
/
prefix_test.py
File metadata and controls
40 lines (29 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import unicode_literals
import os.path
import pytest
from pre_commit.prefix import Prefix
def norm_slash(*args):
return tuple(x.replace('/', os.sep) for x in args)
@pytest.mark.parametrize(
('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_path(prefix, path_end, expected_output):
instance = Prefix(prefix)
ret = instance.path(path_end)
assert ret == expected_output
def test_path_multiple_args():
instance = Prefix('foo')
ret = instance.path('bar', 'baz')
assert ret == os.path.join('foo', 'bar', 'baz')
def test_exists(tmpdir):
assert not Prefix(str(tmpdir)).exists('foo')
tmpdir.ensure('foo')
assert Prefix(str(tmpdir)).exists('foo')