Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
def to_bytes(str_or_bytes, encoding=ENCODING):
if isinstance(str_or_bytes, str):
return str_or_bytes.encode(encoding)
return str_or_bytes
def to_unicode(str_or_bytes, encoding=ENCODING):
if isinstance(str_or_bytes, bytes):
return str_or_bytes.decode(encoding)
return str_or_bytes
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
def to_unicode(text_type, encoding=ENCODING):
if isinstance(text_type, bytes):
return text_type.decode(encoding)
return text_type