From b90d9a215cd170ea8f5430174e7e1e5c59e423f3 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Thu, 8 Aug 2024 23:45:19 +0300 Subject: [PATCH] test,fix: work around resolve() bug in win py38,39 --- src/darker/tests/test_main.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/darker/tests/test_main.py b/src/darker/tests/test_main.py index 6a14f3536..80d938765 100644 --- a/src/darker/tests/test_main.py +++ b/src/darker/tests/test_main.py @@ -8,6 +8,7 @@ import random import re import string +import sys from argparse import ArgumentError from io import BytesIO from pathlib import Path @@ -29,7 +30,7 @@ from darker.verification import NotEquivalentError from darkgraylib.git import WORKTREE, RevisionRange from darkgraylib.testtools.highlighting_helpers import BLUE, CYAN, RESET, WHITE, YELLOW -from darkgraylib.utils import TextDocument, joinlines +from darkgraylib.utils import TextDocument, joinlines, WINDOWS pytestmark = pytest.mark.usefixtures("find_project_root_cache_clear") @@ -945,12 +946,16 @@ def test_stdout_path_resolution(git_repo, capsys): @pytest.mark.parametrize("newline", ["\n", "\r\n"], ids=["unix", "windows"]) -def test_stdout_newlines(capsysbinary, newline): +def test_stdout_newlines(tmp_path, monkeypatch, capsysbinary, newline): """When using ``--stdout``, newlines are not duplicated. See: https://github.com/akaihola/darker/issues/604 """ + if WINDOWS and sys.version_info < (3, 10): + # See https://bugs.python.org/issue38671 + monkeypatch.chdir(tmp_path) + Path("new-file.py").touch() code = f"import collections{newline}import sys{newline}".encode() with patch("sys.stdin.buffer.read", return_value=code): @@ -963,12 +968,16 @@ def test_stdout_newlines(capsysbinary, newline): @pytest.mark.parametrize("newline", ["\n", "\r\n"], ids=["unix", "windows"]) -def test_stdout_newlines_subprocess(newline): +def test_stdout_newlines_subprocess(tmp_path, monkeypatch, newline): """When using ``--stdout``, newlines are not duplicated. See: https://github.com/akaihola/darker/issues/604 """ + if WINDOWS and sys.version_info < (3, 10): + # See https://bugs.python.org/issue38671 + monkeypatch.chdir(tmp_path) + Path("new-file.py").touch() code = f"import collections{newline}import sys{newline}".encode() try: