summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2022-07-02 08:35:17 +0800
committerGitHub <noreply@github.com>2022-07-02 08:35:17 +0800
commitca2cf108522b0a298caf8f32e72df1c6006abcf8 (patch)
tree73cf137bca275170e4cadd80f4fdc619c8ba2cb8 /test
parent275c37f685504b3892a79a8f5d039ad4dafd50b3 (diff)
parentda59d7481668a7133eebcd12b4d5ecfb655296a6 (diff)
downloadgitpython-ca2cf108522b0a298caf8f32e72df1c6006abcf8.tar.gz
Merge pull request #1459 from AustinScola/ascola/fix-blob-filter-types
Fix blob filter types
Diffstat (limited to 'test')
-rw-r--r--test/test_blob_filter.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test_blob_filter.py b/test/test_blob_filter.py
new file mode 100644
index 00000000..cbaa30b8
--- /dev/null
+++ b/test/test_blob_filter.py
@@ -0,0 +1,32 @@
+"""Test the blob filter."""
+from pathlib import Path
+from typing import Sequence, Tuple
+from unittest.mock import MagicMock
+
+import pytest
+
+from git.index.typ import BlobFilter, StageType
+from git.objects import Blob
+from git.types import PathLike
+
+
+# fmt: off
+@pytest.mark.parametrize('paths, path, expected_result', [
+ ((Path("foo"),), Path("foo"), True),
+ ((Path("foo"),), Path("foo/bar"), True),
+ ((Path("foo/bar"),), Path("foo"), False),
+ ((Path("foo"), Path("bar")), Path("foo"), True),
+])
+# fmt: on
+def test_blob_filter(paths: Sequence[PathLike], path: PathLike, expected_result: bool) -> None:
+ """Test the blob filter."""
+ blob_filter = BlobFilter(paths)
+
+ binsha = MagicMock(__len__=lambda self: 20)
+ stage_type: StageType = 0
+ blob: Blob = Blob(repo=MagicMock(), binsha=binsha, path=path)
+ stage_blob: Tuple[StageType, Blob] = (stage_type, blob)
+
+ result = blob_filter(stage_blob)
+
+ assert result == expected_result