Skip to content

Commit 4e993ed

Browse files
committed
Added tests for utils.is_subpath
1 parent 51a8b47 commit 4e993ed

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

bumpversion/scm/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ def _update_from_latest_tag_info(self, latest_tag_info: LatestTagInfo):
185185

186186
def path_in_repo(self, path: Path | str) -> bool:
187187
"""Return whether a path is inside this repository."""
188-
print(path, self.repository_root)
189188
if self.repository_root is None:
190189
return True
191190
elif not Path(path).is_absolute():

tests/test_utils.py

+27
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Tests for the utils module."""
22

33
from itertools import combinations
4+
from pathlib import Path
45

56
import pytest
7+
from pytest import param
68
from bumpversion import utils
79

810

@@ -131,3 +133,28 @@ def test_returns_empty_string_when_no_flags(self):
131133

132134
# Assert
133135
assert actual_flags == expected
136+
137+
138+
@pytest.mark.parametrize(
139+
["parent", "path", "expected"],
140+
[
141+
param(Path("/parent"), Path("/parent/subpath"), True, id="absolute_path_within_parent_returns_true"),
142+
param("/parent", Path("/parent/subpath"), True, id="parent_as_string_path_as_path_1"),
143+
param(Path("/parent"), "/parent/subpath", True, id="parent_as_path_path_as_string_1"),
144+
param(Path("/parent"), Path("/other/subpath"), False, id="absolute_path_outside_of_parent_returns_false"),
145+
param("/parent", Path("/other/subpath"), False, id="parent_as_string_path_as_path_2"),
146+
param(Path("/parent"), "/other/subpath", False, id="parent_as_path_path_as_string_2"),
147+
param(Path("/parent"), Path("/parent"), True, id="identical_absolute_paths_return_true"),
148+
param("/parent", Path("/parent"), True, id="parent_as_string_path_as_path_3"),
149+
param(Path("/parent"), "/parent", True, id="parent_as_path_path_as_string_3"),
150+
param(Path("/parent"), Path("relative/path"), True, id="relative_path_returns_true"),
151+
param("/parent", Path("relative/path"), True, id="parent_as_string_path_as_path_4"),
152+
param(Path("/parent"), "relative/path", True, id="parent_as_path_path_as_string_4"),
153+
],
154+
)
155+
def test_is_subpath(parent: Path | str, path: Path | str, expected: bool) -> None:
156+
"""Test the is_subpath function."""
157+
# Act
158+
result = utils.is_subpath(parent, path)
159+
# Assert
160+
assert result is expected

0 commit comments

Comments
 (0)