File: test_blob_filter.py

package info (click to toggle)
python-git 3.1.30-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,596 kB
  • sloc: python: 15,725; makefile: 80; sh: 28
file content (32 lines) | stat: -rw-r--r-- 963 bytes parent folder | download
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
"""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