How to use the yaspin.constants.ENCODING 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_in_out.py View on Github external
def test_write(capsys, text):
    sp = yaspin()
    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_pipes.py View on Github external
def to_bytes(str_or_bytes, encoding=ENCODING):
    if isinstance(str_or_bytes, str):
        return str_or_bytes.encode(encoding)
    return str_or_bytes
github pavdmyt / yaspin / tests / test_pipes.py View on Github external
def to_unicode(str_or_bytes, encoding=ENCODING):
    if isinstance(str_or_bytes, bytes):
        return str_or_bytes.decode(encoding)
    return str_or_bytes
github pavdmyt / yaspin / tests / test_in_out.py View on Github external
def test_write(capsys, text):
    sp = yaspin()
    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 / yaspin / helpers.py View on Github external
def to_unicode(text_type, encoding=ENCODING):
    if isinstance(text_type, bytes):
        return text_type.decode(encoding)
    return text_type