|
1 | 1 | """Tests for the utils module."""
|
2 | 2 |
|
3 | 3 | from itertools import combinations
|
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | import pytest
|
| 7 | +from pytest import param |
6 | 8 | from bumpversion import utils
|
7 | 9 |
|
8 | 10 |
|
@@ -131,3 +133,28 @@ def test_returns_empty_string_when_no_flags(self):
|
131 | 133 |
|
132 | 134 | # Assert
|
133 | 135 | 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