From c39db8164b6bf624caf7335117eeae8568c944a9 Mon Sep 17 00:00:00 2001 From: shouzy <82171453+realshouzy@users.noreply.github.com> Date: Fri, 5 Jan 2024 22:39:41 +0100 Subject: [PATCH] Fix test error on windows --- tests/args_handling_test.py | 12 +++++++++--- tests/utils_test.py | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/args_handling_test.py b/tests/args_handling_test.py index f9240cb..d6f8878 100644 --- a/tests/args_handling_test.py +++ b/tests/args_handling_test.py @@ -4,7 +4,7 @@ import argparse import json import platform -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Final import pytest @@ -33,6 +33,11 @@ from watchdog.observers.api import BaseObserver +if platform.system() == "Windows": + from pathlib import Path # actually import Path when on Windows + + DRIVE: Final[str] = Path().resolve().drive + @pytest.mark.skipif( platform.system() != "Windows", @@ -514,7 +519,8 @@ def test_handle_read_args_all_configs_windows( assert exit_code == 0 assert ( - capsys.readouterr().out == ".txt: C:\\path\\to\\txt\n.pdf: C:\\path\\to\\pdf\n" + capsys.readouterr().out + == f".txt: {DRIVE}\\path\\to\\txt\n.pdf: {DRIVE}\\path\\to\\pdf\n" ) assert ( @@ -569,7 +575,7 @@ def test_handle_read_args_selected_configs_windows( exit_code: int = handle_read_args(args) assert exit_code == 0 - assert capsys.readouterr().out == ".pdf: C:\\path\\to\\pdf\n" + assert capsys.readouterr().out == f".pdf: {DRIVE}\\path\\to\\pdf\n" assert ( "auto_file_sorter.args_handling", diff --git a/tests/utils_test.py b/tests/utils_test.py index 2cd38e1..ccdec3d 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -3,11 +3,15 @@ import platform from pathlib import Path +from typing import Final import pytest from auto_file_sorter.utils import resolved_path_from_str +if platform.system() == "Windows": + DRIVE: Final[str] = Path().resolve().drive + # pylint: disable=C0116 @@ -20,12 +24,12 @@ ( pytest.param( "/path/to/some/file.txt", - Path("C:/path/to/some/file.txt"), + Path(f"{DRIVE}/path/to/some/file.txt"), id="regular_str", ), pytest.param( " /path/to/some/file.txt ", - Path("C:/path/to/some/file.txt"), + Path(f"{DRIVE}/path/to/some/file.txt"), id="trailing_whitespaces_str", ), ),