|
14 | 14 | from io import BytesIO |
15 | 15 | from pathlib import Path |
16 | 16 | from typing import Any, Callable, NoReturn |
17 | | -from unittest.mock import Mock |
| 17 | +from unittest.mock import Mock, patch |
18 | 18 |
|
19 | 19 | import pytest |
20 | 20 |
|
|
33 | 33 | HiddenText, |
34 | 34 | build_netloc, |
35 | 35 | build_url_from_netloc, |
| 36 | + display_path, |
36 | 37 | format_size, |
37 | 38 | get_prog, |
38 | 39 | hide_url, |
@@ -320,6 +321,39 @@ def test_rmtree_retries_for_3sec(monkeypatch: pytest.MonkeyPatch) -> None: |
320 | 321 | ) |
321 | 322 |
|
322 | 323 |
|
| 324 | +class Test_display_path: |
| 325 | + on_unix = pytest.mark.skipif("sys.platform == 'win32'") |
| 326 | + on_win32 = pytest.mark.skipif("sys.platform != 'win32'") |
| 327 | + |
| 328 | + @pytest.mark.parametrize( |
| 329 | + "path, fake_cwd, expected", |
| 330 | + [ |
| 331 | + pytest.param( |
| 332 | + *("/home/name/project", Path("/home/name"), "./project"), |
| 333 | + marks=on_unix, |
| 334 | + ), |
| 335 | + pytest.param( |
| 336 | + *("/home", Path("/home/name"), "/home"), |
| 337 | + marks=on_unix, |
| 338 | + id="not-go-up", |
| 339 | + ), |
| 340 | + pytest.param( |
| 341 | + *("C:\\Name\\Project", Path("C:\\Name"), ".\\Project"), |
| 342 | + marks=on_win32, |
| 343 | + ), |
| 344 | + pytest.param( |
| 345 | + *("D:\\Data", Path("C:\\Name"), "D:\\Data"), |
| 346 | + marks=on_win32, |
| 347 | + ), |
| 348 | + ], |
| 349 | + ) |
| 350 | + def test_display(self, path: str, fake_cwd: Path, expected: str) -> None: |
| 351 | + with patch("pathlib.Path.cwd") as cwd_func: |
| 352 | + cwd_func.return_value = fake_cwd |
| 353 | + got = display_path(path) |
| 354 | + assert got == expected |
| 355 | + |
| 356 | + |
323 | 357 | class Test_normalize_path: |
324 | 358 | # Technically, symlinks are possible on Windows, but you need a special |
325 | 359 | # permission bit to create them, and Python 2 doesn't support it anyway, so |
|
0 commit comments