From 9a1897c884ff4070646ed231aab424dfc6d4c8bb Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Fri, 10 Sep 2021 13:50:29 +0300 Subject: [PATCH 1/3] Fix patching of `io.TextWrapper` in tests `patch("io.TextIOWrapper")` wouldn't actually cause `io.TextIOWrapper()` to return the `StringIO` object created by the test. This started to fail as soon as `content=` is non-empty. --- tests/test_black.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_black.py b/tests/test_black.py index 398a528bee9..9d590c1c03d 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -25,7 +25,7 @@ ) import pytest import unittest -from unittest.mock import patch, MagicMock +from unittest.mock import patch, MagicMock, Mock from parameterized import parameterized import click @@ -1689,7 +1689,9 @@ def test_reformat_one_with_stdin_and_existing_path(self) -> None: def test_reformat_one_with_stdin_empty(self) -> None: output = io.StringIO() - with patch("io.TextIOWrapper", lambda *args, **kwargs: output): + mock_io = Mock() + mock_io.TextIOWrapper.return_value = output + with patch.object(black, "io", mock_io): try: black.format_stdin_to_stdout( fast=True, From c068ec3ab8ca19c7cc8805b487b0723f63d2e052 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Fri, 10 Sep 2021 13:52:40 +0300 Subject: [PATCH 2/3] Update change log --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4b5a291c7b9..bfb12b9676c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,10 @@ - Fix missing modules in self-contained binaries (#2466) - Fix missing toml extra used during installation (#2475) +### Tests + +- Fix patching of `io.TextWrapper` (#2489) + ## 21.8b0 ### _Black_ From a99ad3ab05059ffaad153ecd778324c5f5697ada Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Sat, 11 Sep 2021 18:55:02 +0300 Subject: [PATCH 3/3] Update CHANGES.md Co-authored-by: Jelle Zijlstra --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index bfb12b9676c..2961dbb320b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,7 +9,7 @@ ### Tests -- Fix patching of `io.TextWrapper` (#2489) +- Fix patching of `io.TextIOWrapper` (#2489) ## 21.8b0