Relax logger check for Windows (#1615)

* Relax logger check for Windows

* Update tests
This commit is contained in:
Antonin RAFFIN 2023-07-21 07:02:38 +02:00 committed by GitHub
parent 61e1060525
commit a730b9b66a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 6 deletions

View file

@ -4,7 +4,7 @@ Changelog
========== ==========
Release 2.1.0a1 (WIP) Release 2.1.0a2 (WIP)
-------------------------- --------------------------
Breaking Changes: Breaking Changes:
@ -25,6 +25,7 @@ New Features:
Bug Fixes: Bug Fixes:
^^^^^^^^^^ ^^^^^^^^^^
- Relaxed check in logger, that was causing issue on Windows with colorama
Deprecations: Deprecations:
^^^^^^^^^^^^^ ^^^^^^^^^^^^^

View file

@ -164,8 +164,10 @@ class HumanOutputFormat(KVWriter, SeqWriter):
if isinstance(filename_or_file, str): if isinstance(filename_or_file, str):
self.file = open(filename_or_file, "w") self.file = open(filename_or_file, "w")
self.own_file = True self.own_file = True
elif isinstance(filename_or_file, TextIOBase): elif isinstance(filename_or_file, TextIOBase) or hasattr(filename_or_file, "write"):
self.file = filename_or_file # Note: in theory `TextIOBase` check should be sufficient,
# in practice, libraries don't always inherit from it, see GH#1598
self.file = filename_or_file # type: ignore[assignment]
self.own_file = False self.own_file = False
else: else:
raise ValueError(f"Expected file or str, got {filename_or_file}") raise ValueError(f"Expected file or str, got {filename_or_file}")

View file

@ -1 +1 @@
2.1.0a1 2.1.0a2

View file

@ -437,8 +437,9 @@ def test_ep_buffers_stats_window_size(algo, stats_window_size):
assert model.ep_success_buffer.maxlen == stats_window_size assert model.ep_success_buffer.maxlen == stats_window_size
def test_human_output_format_custom_test_io(): @pytest.mark.parametrize("base_class", [object, TextIOBase])
class DummyTextIO(TextIOBase): def test_human_output_format_custom_test_io(base_class):
class DummyTextIO(base_class):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
self.lines = [[]] self.lines = [[]]