How to use the yaspin.compat.iteritems function in yaspin

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_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 / yaspin / core.py View on Github external
def _set_color(value):
        # type: (str) -> str
        available_values = [k for k, v in iteritems(COLOR_MAP) if v == "color"]

        if value not in available_values:
            raise ValueError(
                "'{0}': unsupported color value. Use one of the: {1}".format(
                    value, ", ".join(available_values)
                )
            )
        return value
github pavdmyt / yaspin / yaspin / core.py View on Github external
def _register_signal_handlers(self):
        # SIGKILL cannot be caught or ignored, and the receiving
        # process cannot perform any clean-up upon receiving this
        # signal.
        if signal.SIGKILL in self._sigmap.keys():
            raise ValueError(
                "Trying to set handler for SIGKILL signal. "
                "SIGKILL cannot be cought or ignored in POSIX systems."
            )

        for sig, sig_handler in iteritems(self._sigmap):
            # A handler for a particular signal, once set, remains
            # installed until it is explicitly reset. Store default
            # signal handlers for subsequent reset at cleanup phase.
            dfl_handler = signal.getsignal(sig)
            self._dfl_sigmap[sig] = dfl_handler

            # ``signal.SIG_DFL`` and ``signal.SIG_IGN`` are also valid
            # signal handlers and are not callables.
            if callable(sig_handler):
                # ``signal.signal`` accepts handler function which is
                # called with two arguments: signal number and the
                # interrupted stack frame. ``functools.partial`` solves
                # the problem of passing spinner instance into the handler
                # function.
                sig_handler = functools.partial(sig_handler, spinner=self)
github pavdmyt / yaspin / yaspin / core.py View on Github external
def _reset_signal_handlers(self):
        for sig, sig_handler in iteritems(self._dfl_sigmap):
            signal.signal(sig, sig_handler)
github pavdmyt / yaspin / yaspin / core.py View on Github external
def _set_on_color(value):
        # type: (str) -> str
        available_values = [
            k for k, v in iteritems(COLOR_MAP) if v == "on_color"
        ]
        if value not in available_values:
            raise ValueError(
                "'{0}': unsupported on_color value. "
                "Use one of the: {1}".format(
                    value, ", ".join(available_values)
                )
            )
        return value