Skip to content
Myr

Add parametrized tests for `should_strip_ansi` (#2731)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Rowlando13 · committed by GitHub · parents 0cd28d6, cf0c36d · Browse files · 1 file+47 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+47 added−2 removed

  • tests:+47 added−2 removed

1 file+47 added−2 removed

modified:tests/test_compat.py+47 added-2 removed
1from click._compat import should_strip_ansi1from __future__ import annotations23import sys45import pytest67import click8910def test_is_jupyter_kernel_output():11 class JupyterKernelFakeStream:12 pass1314 # implementation detail, aka cheapskate test15 JupyterKernelFakeStream.__module__ = "ipykernel.faked"10 assert not should_strip_ansi(stream=JupyterKernelFakeStream())16 assert click._compat._is_jupyter_kernel_output(stream=JupyterKernelFakeStream())171819@pytest.mark.parametrize(20 "stream",21 [None, sys.stdin, sys.stderr, sys.stdout],22)23@pytest.mark.parametrize(24 ("color", "expected_override"),25 [26 (True, False),27 (False, True),28 (None, None),29 ],30)31@pytest.mark.parametrize(32 ("isatty", "is_jupyter", "expected"),33 [34 (True, False, False),35 (False, True, False),36 (False, False, True),37 ],38)39def test_should_strip_ansi(40 monkeypatch,41 stream,42 color: bool | None,43 expected_override: bool | None,44 isatty: bool,45 is_jupyter: bool,46 expected: bool,47) -> None:48 monkeypatch.setattr(click._compat, "isatty", lambda x: isatty)49 monkeypatch.setattr(50 click._compat, "_is_jupyter_kernel_output", lambda x: is_jupyter51 )5253 if expected_override is not None:54 expected = expected_override55 assert click._compat.should_strip_ansi(stream=stream, color=color) == expected