Skip to content

Commit

Permalink
Refactor test_spiunner to deprecate unittest in favor of pytest (Sign…
Browse files Browse the repository at this point in the history
…ificant-Gravitas#3532)

Co-authored-by: Nicholas Tindle <[email protected]>
  • Loading branch information
rihp and ntindle authored Apr 29, 2023
1 parent 095883c commit 4f72ee7
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions tests/unit/test_spinner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by CodiumAI
import time
import unittest

from autogpt.spinner import Spinner

Expand Down Expand Up @@ -29,40 +28,43 @@
PLEASE_WAIT = "Please wait..."


class TestSpinner(unittest.TestCase):
def test_spinner_initializes_with_default_values(self):
"""Tests that the spinner initializes with default values."""
with Spinner() as spinner:
self.assertEqual(spinner.message, "Loading...")
self.assertEqual(spinner.delay, 0.1)

def test_spinner_initializes_with_custom_values(self):
"""Tests that the spinner initializes with custom message and delay values."""
with Spinner(message=PLEASE_WAIT, delay=0.2) as spinner:
self.assertEqual(spinner.message, PLEASE_WAIT)
self.assertEqual(spinner.delay, 0.2)

#
def test_spinner_stops_spinning(self):
"""Tests that the spinner starts spinning and stops spinning without errors."""
with Spinner() as spinner:
time.sleep(1)
spinner.update_message(ALMOST_DONE_MESSAGE)
time.sleep(1)
self.assertFalse(spinner.running)

def test_spinner_updates_message_and_still_spins(self):
"""Tests that the spinner message can be updated while the spinner is running and the spinner continues spinning."""
with Spinner() as spinner:
self.assertTrue(spinner.running)
time.sleep(1)
spinner.update_message(ALMOST_DONE_MESSAGE)
time.sleep(1)
self.assertEqual(spinner.message, ALMOST_DONE_MESSAGE)
self.assertFalse(spinner.running)

def test_spinner_can_be_used_as_context_manager(self):
"""Tests that the spinner can be used as a context manager."""
with Spinner() as spinner:
self.assertTrue(spinner.running)
self.assertFalse(spinner.running)
def test_spinner_initializes_with_default_values():
"""Tests that the spinner initializes with default values."""
with Spinner() as spinner:
assert spinner.message == "Loading..."
assert spinner.delay == 0.1


def test_spinner_initializes_with_custom_values():
"""Tests that the spinner initializes with custom message and delay values."""
with Spinner(message=PLEASE_WAIT, delay=0.2) as spinner:
assert spinner.message == PLEASE_WAIT
assert spinner.delay == 0.2


#
def test_spinner_stops_spinning():
"""Tests that the spinner starts spinning and stops spinning without errors."""
with Spinner() as spinner:
time.sleep(1)
spinner.update_message(ALMOST_DONE_MESSAGE)
time.sleep(1)
assert spinner.running == False


def test_spinner_updates_message_and_still_spins():
"""Tests that the spinner message can be updated while the spinner is running and the spinner continues spinning."""
with Spinner() as spinner:
assert spinner.running == True
time.sleep(1)
spinner.update_message(ALMOST_DONE_MESSAGE)
time.sleep(1)
assert spinner.message == ALMOST_DONE_MESSAGE
assert spinner.running == False


def test_spinner_can_be_used_as_context_manager():
"""Tests that the spinner can be used as a context manager."""
with Spinner() as spinner:
assert spinner.running == True
assert spinner.running == False

0 comments on commit 4f72ee7

Please sign in to comment.