From ed45d5b3c3d4e2d4520221037b40288dc85e428c Mon Sep 17 00:00:00 2001 From: Austin Scola Date: Tue, 28 Jun 2022 08:59:26 -0400 Subject: Fix blob filter path shorter than filter path --- test/test_blob_filter.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/test_blob_filter.py (limited to 'test') diff --git a/test/test_blob_filter.py b/test/test_blob_filter.py new file mode 100644 index 00000000..a8cd0c9c --- /dev/null +++ b/test/test_blob_filter.py @@ -0,0 +1,31 @@ +"""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, stage_type, path, expected_result', [ + ((Path("foo"),), 0, Path("foo"), True), + ((Path("foo"),), 0, Path("foo/bar"), True), + ((Path("foo/bar"),), 0, Path("foo"), False), + ((Path("foo"), Path("bar")), 0, Path("foo"), True), +]) +# fmt: on +def test_blob_filter(paths: Sequence[PathLike], stage_type: StageType, path: PathLike, expected_result: bool) -> None: + """Test the blob filter.""" + blob_filter = BlobFilter(paths) + + binsha = MagicMock(__len__=lambda self: 20) + 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 -- cgit v1.2.1