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_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)
# ``\n`` is required to flush stdout during
# the hidden state of the spinner
sys.stdout.write("{0}\n".format(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
sp.show()
# ensure that hidden spinner flag was cleared
assert not sp._hide_spin.is_set()
out, _ = capsys.readouterr()
# ensure that text was cleared before resuming the spinner
assert out[:4] == "\r\033[K"
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 test_text_setter(text):
swirl = yaspin()
swirl.text = text
assert isinstance(swirl._text, str)
assert swirl._text == to_unicode(text)
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)
def case_id():
return str(uuid.uuid4())
def _compose_out(self, frame, mode=None):
# Ensure Unicode input
assert isinstance(frame, str)
assert isinstance(self._text, str)
frame = frame.encode(ENCODING) if PY2 else frame
text = self._text.encode(ENCODING) if PY2 else self._text
# 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)
def _compose_out(self, frame, mode=None):
# Ensure Unicode input
assert isinstance(frame, str)
assert isinstance(self._text, str)
frame = frame.encode(ENCODING) if PY2 else frame
text = self._text.encode(ENCODING) if PY2 else self._text
# 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: