How to use the yaspin.compat.basestring 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_pipes.py View on Github external
def test_piping_output(text, frames, interval, case_id):
    py_fname = "spin-{0}.py".format(case_id)
    fname = "out-{0}.txt".format(case_id)

    def teardown():
        os.remove(py_fname)
        os.remove(fname)

    with open(py_fname, "wb") as f:
        if isinstance(frames, basestring):
            # enclosing characters in quotes
            # for basestring entries
            # to avoid SyntaxError
            frames = repr(to_unicode(frames))

        text = to_unicode(text)
        interval = to_unicode(interval)
        code = to_unicode(TEST_CODE)
        res = code % (frames, interval, text)
        f.write(to_bytes(res))

    try:
        # $ python spin.py > out.txt
        os.system("{0} {1} > {2}".format(sys.executable, py_fname, fname))
    except UnicodeEncodeError as err:
        pytest.fail(err)
github pavdmyt / yaspin / tests / test_in_out.py View on Github external
def test_input_converted_to_unicode(text, frames, interval, reversal, side):
    sp = Spinner(frames, interval)
    sp = yaspin(sp, text, side=side, reversal=reversal)

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

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

    assert isinstance(sp._text, str)
github pavdmyt / yaspin / tests / test_in_out.py View on Github external
sp.write(text)

    out, _ = capsys.readouterr()
    # cleans stdout from _clear_line and \r
    out = out.replace("\r\033[K", "")

    # handle out and text encodings (come out messy in PY2)
    # Under PY2 ``capsys.readouterr`` always produces ``out``
    # of type ``unicode``. Conversion to bytes is required
    # for proper ``out`` and ``text`` comparison.
    if PY2:
        out = out.encode(ENCODING)
        if isinstance(text, str):
            text = text.encode(ENCODING)

    assert isinstance(out, basestring)
    assert out[-1] == "\n"
    if text:
        assert out[:-1] == text
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 / yaspin / core.py View on Github external
def _set_frames(spinner, reversal):
        # type: (base_spinner.Spinner, bool) -> Union[str, List]
        uframes = None  # unicode frames
        uframes_seq = None  # sequence of unicode frames

        if isinstance(spinner.frames, basestring):
            uframes = to_unicode(spinner.frames) if PY2 else spinner.frames

        # TODO (pavdmyt): support any type that implements iterable
        if isinstance(spinner.frames, (list, tuple)):

            # Empty ``spinner.frames`` is handled by ``Yaspin._set_spinner``
            if spinner.frames and isinstance(spinner.frames[0], bytes):
                uframes_seq = [to_unicode(frame) for frame in spinner.frames]
            else:
                uframes_seq = spinner.frames

        _frames = uframes or uframes_seq
        if not _frames:
            # Empty ``spinner.frames`` is handled by ``Yaspin._set_spinner``.
            # This code is very unlikely to be executed. However, it's still
            # here to be on a safe side.