|
| 1 | +"""Test the blob filter.""" |
| 2 | +from pathlib import Path |
| 3 | +from typing import Sequence, Tuple |
| 4 | +from unittest.mock import MagicMock |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +from git.index.typ import BlobFilter, StageType |
| 9 | +from git.objects import Blob |
| 10 | +from git.types import PathLike |
| 11 | + |
| 12 | + |
| 13 | +# fmt: off |
| 14 | +@pytest.mark.parametrize('paths, stage_type, path, expected_result', [ |
| 15 | + ((Path("foo"),), 0, Path("foo"), True), |
| 16 | + ((Path("foo"),), 0, Path("foo/bar"), True), |
| 17 | + ((Path("foo/bar"),), 0, Path("foo"), False), |
| 18 | + ((Path("foo"), Path("bar")), 0, Path("foo"), True), |
| 19 | +]) |
| 20 | +# fmt: on |
| 21 | +def test_blob_filter(paths: Sequence[PathLike], stage_type: StageType, path: PathLike, expected_result: bool) -> None: |
| 22 | + """Test the blob filter.""" |
| 23 | + blob_filter = BlobFilter(paths) |
| 24 | + |
| 25 | + binsha = MagicMock(__len__=lambda self: 20) |
| 26 | + blob: Blob = Blob(repo=MagicMock(), binsha=binsha, path=path) |
| 27 | + stage_blob: Tuple[StageType, Blob] = (stage_type, blob) |
| 28 | + |
| 29 | + result = blob_filter(stage_blob) |
| 30 | + |
| 31 | + assert result == expected_result |
0 commit comments