|
6 | 6 | import py
|
7 | 7 |
|
8 | 8 | import pytest
|
| 9 | +from _pytest.pathlib import bestrelpath |
| 10 | +from _pytest.pathlib import commonpath |
9 | 11 | from _pytest.pathlib import ensure_deletable
|
10 | 12 | from _pytest.pathlib import fnmatch_ex
|
11 | 13 | from _pytest.pathlib import get_extended_length_path_str
|
@@ -381,3 +383,21 @@ def test_suppress_error_removing_lock(tmp_path):
|
381 | 383 | # check now that we can remove the lock file in normal circumstances
|
382 | 384 | assert ensure_deletable(path, consider_lock_dead_if_created_before=mtime + 30)
|
383 | 385 | assert not lock.is_file()
|
| 386 | + |
| 387 | + |
| 388 | +def test_bestrelpath() -> None: |
| 389 | + curdir = Path("/foo/bar/baz/path") |
| 390 | + assert bestrelpath(curdir, curdir) == "." |
| 391 | + assert bestrelpath(curdir, curdir / "hello" / "world") == "hello" + os.sep + "world" |
| 392 | + assert bestrelpath(curdir, curdir.parent / "sister") == ".." + os.sep + "sister" |
| 393 | + assert bestrelpath(curdir, curdir.parent) == ".." |
| 394 | + assert bestrelpath(curdir, Path("hello")) == "hello" |
| 395 | + |
| 396 | + |
| 397 | +def test_commonpath() -> None: |
| 398 | + path = Path("/foo/bar/baz/path") |
| 399 | + subpath = path / "sampledir" |
| 400 | + assert commonpath(path, subpath) == path |
| 401 | + assert commonpath(subpath, path) == path |
| 402 | + assert commonpath(Path(str(path) + "suffix"), path) == path.parent |
| 403 | + assert commonpath(path, path.parent.parent) == path.parent.parent |
0 commit comments