Skip to content

Commit 5e0fec0

Browse files
committed
Add tests for relpath on Windows
1 parent a186acb commit 5e0fec0

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/test_paths.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
sort_paths,
3535
traverse_to_file
3636
)
37-
from domdf_python_tools.testing import not_pypy, not_windows
37+
from domdf_python_tools.testing import not_pypy, not_windows, only_windows
3838

3939

4040
def test_maybe_make(tmp_pathplus):
@@ -161,7 +161,7 @@ def test_parent_path(tmp_pathplus):
161161
assert str(paths.parent_path("spam/spam/spam")) == os.path.join("spam", "spam")
162162

163163

164-
@not_windows("Needs special-casing for Windows")
164+
@not_windows("Windows uses a different path structure.")
165165
@pytest.mark.parametrize(
166166
"relto, relpath",
167167
[
@@ -178,6 +178,26 @@ def test_relpath(relto, relpath):
178178
assert isinstance(paths.relpath(path, relative_to=relto), pathlib.Path)
179179

180180

181+
@only_windows("Windows uses a different path structure.")
182+
@pytest.mark.parametrize(
183+
"relto, relpath",
184+
[
185+
("c:/users/username/Documents/games/chess.py", "c:/users/username/Documents/letter.doc"),
186+
("c:/users/username/Documents", "letter.doc"),
187+
(
188+
pathlib.Path("c:/users/username/Documents/games/chess.py"),
189+
"c:/users/username/Documents/letter.doc"
190+
),
191+
(pathlib.Path("c:/users/username/Documents"), "letter.doc"),
192+
(None, pathlib.Path("c:/users/username/Documents/letter.doc")),
193+
],
194+
)
195+
def test_relpath_windows(relto, relpath):
196+
path = "c:/users/username/Documents/letter.doc"
197+
assert paths.relpath(path, relative_to=relto) == pathlib.Path(relpath)
198+
assert isinstance(paths.relpath(path, relative_to=relto), pathlib.Path)
199+
200+
181201
class TestCurrentDirOperations:
182202

183203
def test_append(self):

0 commit comments

Comments
 (0)