summaryrefslogtreecommitdiff
path: root/tests/test_compat.py
blob: 3c458e9c7240daaef813e85e58983569e4f3fa96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pytest

from click._compat import should_strip_ansi
from click._compat import WIN


def test_bash_func_name():
    from click._bashcomplete import get_completion_script

    script = get_completion_script("foo-bar baz_blah", "_COMPLETE_VAR", "bash").strip()
    assert script.startswith("_foo_barbaz_blah_completion()")
    assert "_COMPLETE_VAR=complete $1" in script


def test_zsh_func_name():
    from click._bashcomplete import get_completion_script

    script = get_completion_script("foo-bar", "_COMPLETE_VAR", "zsh").strip()
    assert script.startswith("#compdef foo-bar")
    assert "compdef _foo_bar_completion foo-bar;" in script
    assert "(( ! $+commands[foo-bar] )) && return 1" in script


@pytest.mark.xfail(WIN, reason="Jupyter not tested/supported on Windows")
def test_is_jupyter_kernel_output():
    class JupyterKernelFakeStream:
        pass

    # implementation detail, aka cheapskate test
    JupyterKernelFakeStream.__module__ = "ipykernel.faked"
    assert not should_strip_ansi(stream=JupyterKernelFakeStream())