Refactor test_spiunner to deprecate unittest in favor of pytest (#3532)

Co-authored-by: Nicholas Tindle <nick@ntindle.com>
pull/3425/head^2
Media 2023-04-29 19:40:32 +02:00 committed by GitHub
parent 095883ca54
commit 4f72ee7815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 34 deletions

View File

@ -1,6 +1,5 @@
# Generated by CodiumAI
import time
import unittest
from autogpt.spinner import Spinner
@ -29,40 +28,43 @@ ALMOST_DONE_MESSAGE = "Almost done..."
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_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(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_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_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_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