How to use the yaspin.compat.builtin_str 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_finalizers.py View on Github external
def test_freeze(final_text):
    sp = yaspin()
    sp._freeze(final_text)

    assert isinstance(sp._last_frame, builtin_str)
    assert sp._last_frame[-1] == "\n"
github pavdmyt / yaspin / tests / test_properties.py View on Github external
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_in_out.py View on Github external
def test_out_converted_to_builtin_str(text, frames, interval, reversal, side):
    sp = Spinner(frames, interval)
    sp = yaspin(sp, text, side=side, reversal=reversal)

    for _ in range(len(frames)):
        frame = next(sp._cycle)
        out = sp._compose_out(frame)
        assert isinstance(out, builtin_str)
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_finalizers.py View on Github external
def test_fail(final_text):
    sp = yaspin()
    sp.fail(final_text)

    assert isinstance(sp._last_frame, builtin_str)
    assert sp._last_frame[-1] == "\n"
github pavdmyt / yaspin / tests / test_in_out.py View on Github external
isinstance(attrs_exp, Exception),
        ]
    )
    if empty or is_exc:
        items = [repr(color_exp), repr(on_color_exp), repr(attrs_exp)]
        pytest.skip("{0} - unsupported case".format(items))

    # Actual test
    sp = yaspin(color=color, on_color=on_color, attrs=attrs)
    assert sp._color == color
    assert sp._on_color == on_color
    assert sp._attrs == set(attrs)

    out = sp._compose_out(frame=u"/")
    assert out.startswith("\r\033")
    assert isinstance(out, builtin_str)
github pavdmyt / yaspin / yaspin / core.py View on Github external
def write(self, text):
        """Write text in the terminal without breaking the spinner."""
        # similar to tqdm.write()
        # https://pypi.python.org/pypi/tqdm#writing-messages
        with self._stdout_lock:
            sys.stdout.write("\r")
            self._clear_line()

            _text = to_unicode(text)
            if PY2:
                _text = _text.encode(ENCODING)

            # Ensure output is bytes for Py2 and Unicode for Py3
            assert isinstance(_text, builtin_str)

            sys.stdout.write("{0}\n".format(_text))
github pavdmyt / yaspin / yaspin / core.py View on Github external
# Colors
        if self._color_func is not None:
            frame = self._color_func(frame)

        # Position
        if self._side == "right":
            frame, text = text, frame

        # Mode
        if not mode:
            out = "\r{0} {1}".format(frame, text)
        else:
            out = "{0} {1}\n".format(frame, text)

        # Ensure output is bytes for Py2 and Unicode for Py3
        assert isinstance(out, builtin_str)

        return out