How to use yaspin - 10 common examples

To help you get started, we’ve selected a few yaspin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pavdmyt / yaspin / tests / test_signals.py View on Github external
def test_sigmap_signals_get_registered(sigmap_test_cases):
    sigmap = sigmap_test_cases
    if not sigmap:
        pytest.skip("{0!r} - unsupported case".format(sigmap))

    sp = yaspin(sigmap=sigmap)
    # If test fails, the spinner may infinitely stuck ignoring
    # signals, except of SIGKILL; try-finally block ensures
    # that spinner get stopped.
    try:
        sp.start()
        for sig, sig_handler in iteritems(sigmap):
            handler = signal.getsignal(sig)
            is_partial = isinstance(handler, functools.partial)

            if callable(sig_handler) and is_partial:
                # Handler function is wrapped into ``partial`` and
                # is accesible via ``func`` attribute.
                assert sig_handler == handler.func
            else:
                # SIG_DFL and SIG_IGN cases
                assert sig_handler == handler
    finally:
        sp.stop()
github pavdmyt / yaspin / tests / test_attrs.py View on Github external
    "attr", sorted([k for k, v in iteritems(COLOR_MAP) if v == "attrs"])
)
def test_attrs(attr):
    sp = yaspin()
    getattr(sp, attr)
    assert sp.attrs == [attr]
    assert sp._color_func.keywords["attrs"] == [attr]
github pavdmyt / yaspin / tests / test_spinners.py View on Github external
from __future__ import absolute_import

import json
from collections import OrderedDict

import pytest

from yaspin.compat import iteritems
from yaspin.spinners import SPINNERS_DATA, Spinners


spinners_dict = OrderedDict(json.loads(SPINNERS_DATA))


test_cases = [
    (name, v["frames"], v["interval"]) for name, v in iteritems(spinners_dict)
]


def test_len():
    assert len(Spinners) == len(spinners_dict)


# Entry example:
# ('balloon', [' ', '.', 'o', 'O', '@', '*', ' '], 140)
@pytest.mark.parametrize("name, frames, interval", test_cases)
def test_spinners(name, frames, interval):
    assert getattr(Spinners, name).frames == frames
    assert getattr(Spinners, name).interval == interval
github pavdmyt / yaspin / tests / test_properties.py View on Github external
def test_text_getter(text):
    swirl = yaspin(text=text)
    assert swirl.text == to_unicode(text)
github pavdmyt / yaspin / tests / test_properties.py View on Github external
def test_text_setter(text):
    swirl = yaspin()
    swirl.text = text
    assert isinstance(swirl._text, str)
    assert swirl._text == to_unicode(text)
github pavdmyt / yaspin / tests / test_yaspin.py View on Github external
        (Spinner("", 42), default_spinner),
        # Both attrs, not interval
        (Spinner("-\\|/", 0), default_spinner),
        # Both attrs, are set
        (Spinner("-\\|/", 42), Spinner("-\\|/", 42)),
    ],
)
def test_set_spinner(spinner, expected):
    swirl = yaspin(spinner)
    assert swirl.spinner == expected
github pavdmyt / yaspin / tests / test_properties.py View on Github external
def test_spinner_setter(frames, interval):
    swirl = yaspin()
    assert swirl._spinner == default_spinner
    assert isinstance(swirl._frames, str)
    assert swirl._interval == swirl._spinner.interval * 0.001
    assert isinstance(repr(swirl), builtin_str)

    new_spinner = Spinner(frames, interval)
    swirl.spinner = new_spinner
    assert swirl._spinner == swirl._set_spinner(new_spinner)

    if isinstance(swirl._frames, basestring):
        assert isinstance(swirl._frames, str)

    if isinstance(swirl._frames, (list, tuple)):
        assert isinstance(swirl._frames[0], str)

    assert swirl._interval == swirl._spinner.interval * 0.001
    assert isinstance(repr(swirl), builtin_str)
github pavdmyt / yaspin / tests / test_yaspin.py View on Github external
        (Spinner("", 0), default_spinner),
        # Both attrs, not frames
        (Spinner("", 42), default_spinner),
        # Both attrs, not interval
        (Spinner("-\\|/", 0), default_spinner),
        # Both attrs, are set
        (Spinner("-\\|/", 42), Spinner("-\\|/", 42)),
    ],
)
def test_set_spinner(spinner, expected):
    swirl = yaspin(spinner)
    assert swirl.spinner == expected
github pavdmyt / yaspin / tests / test_yaspin.py View on Github external
        (Spinner("-\\|/", 0), default_spinner),
        # Both attrs, are set
        (Spinner("-\\|/", 42), Spinner("-\\|/", 42)),
    ],
)
def test_set_spinner(spinner, expected):
    swirl = yaspin(spinner)
    assert swirl.spinner == expected
github pavdmyt / yaspin / tests / test_properties.py View on Github external
def test_spinner_getter(frames, interval):
    swirl = yaspin()
    assert swirl.spinner == default_spinner

    new_spinner = Spinner(frames, interval)
    swirl.spinner = new_spinner
    assert swirl.spinner == swirl._set_spinner(new_spinner)