tests: refactor CLI path utils tests

This commit is contained in:
bastimeyer 2024-04-03 23:11:16 +02:00 committed by Sebastian Meyer
parent 20247d4ca5
commit 4abb9ae9cf
1 changed files with 8 additions and 10 deletions

View File

@ -1,6 +1,4 @@
import os
from pathlib import Path
from unittest.mock import patch
import pytest
@ -68,14 +66,14 @@ def test_replace_path():
@pytest.mark.posix_only()
def test_replace_path_expanduser_posix():
with patch.object(os, "environ", {"HOME": "/home/foo"}):
assert replace_path("~/bar", lambda s: s) == Path("/home/foo/bar")
assert replace_path("foo/bar", lambda s: dict(foo="~").get(s, s)) == Path("~/bar")
@pytest.mark.parametrize("os_environ", [pytest.param({"HOME": "/home/foo"}, id="posix")], indirect=True)
def test_replace_path_expanduser_posix(os_environ):
assert replace_path("~/bar", lambda s: s) == Path("/home/foo/bar")
assert replace_path("foo/bar", lambda s: dict(foo="~").get(s, s)) == Path("~/bar")
@pytest.mark.windows_only()
def test_replace_path_expanduser_windows():
with patch.object(os, "environ", {"USERPROFILE": "C:\\Users\\foo"}):
assert replace_path("~\\bar", lambda s: s) == Path("C:\\Users\\foo\\bar")
assert replace_path("foo\\bar", lambda s: dict(foo="~").get(s, s)) == Path("~\\bar")
@pytest.mark.parametrize("os_environ", [pytest.param({"USERPROFILE": "C:\\Users\\foo"}, id="windows")], indirect=True)
def test_replace_path_expanduser_windows(os_environ):
assert replace_path("~\\bar", lambda s: s) == Path("C:\\Users\\foo\\bar")
assert replace_path("foo\\bar", lambda s: dict(foo="~").get(s, s)) == Path("~\\bar")