summaryrefslogtreecommitdiffstats
path: root/tests/prefix_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:05:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:05:20 +0000
commitc86df75ab11643fa4649cfe6ed5c4692d4ee342b (patch)
treede847f47ec2669e74b9a3459319579346b7c99df /tests/prefix_test.py
parentInitial commit. (diff)
downloadpre-commit-c86df75ab11643fa4649cfe6ed5c4692d4ee342b.tar.xz
pre-commit-c86df75ab11643fa4649cfe6ed5c4692d4ee342b.zip
Adding upstream version 3.6.2.upstream/3.6.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/prefix_test.py')
-rw-r--r--tests/prefix_test.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/prefix_test.py b/tests/prefix_test.py
new file mode 100644
index 0000000..1eac087
--- /dev/null
+++ b/tests/prefix_test.py
@@ -0,0 +1,46 @@
+from __future__ import annotations
+
+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')
+
+
+def test_star(tmpdir):
+ for f in ('a.txt', 'b.txt', 'c.py'):
+ tmpdir.join(f).ensure()
+ assert set(Prefix(str(tmpdir)).star('.txt')) == {'a.txt', 'b.txt'}