Fixing tests for new gametime tests
It appears that some mocks setup for gametime in the contrib library were causing issues with the gametime tests. I've switched those mocks to be patches instead so they are cleared out when the test finishes.
This commit is contained in:
parent
a18e724e0b
commit
73f82d0ad1
2 changed files with 13 additions and 7 deletions
|
|
@ -222,6 +222,8 @@ class ForceUTCDatetime(datetime.datetime):
|
|||
|
||||
|
||||
@patch('evennia.contrib.extended_room.datetime.datetime', ForceUTCDatetime)
|
||||
# mock gametime to return April 9, 2064, at 21:06 (spring evening)
|
||||
@patch('evennia.utils.gametime.gametime', new=Mock(return_value=2975000766))
|
||||
class TestExtendedRoom(CommandTest):
|
||||
room_typeclass = extended_room.ExtendedRoom
|
||||
DETAIL_DESC = "A test detail."
|
||||
|
|
@ -236,8 +238,6 @@ class TestExtendedRoom(CommandTest):
|
|||
self.room1.db.details = {'testdetail': self.DETAIL_DESC}
|
||||
self.room1.db.spring_desc = self.SPRING_DESC
|
||||
self.room1.db.desc = self.OLD_DESC
|
||||
# mock gametime to return April 9, 2064, at 21:06 (spring evening)
|
||||
gametime.gametime = Mock(return_value=2975000766)
|
||||
|
||||
def test_return_appearance(self):
|
||||
# get the appearance of a non-extended room for contrast purposes
|
||||
|
|
@ -607,11 +607,8 @@ def _testcallback():
|
|||
pass
|
||||
|
||||
|
||||
@patch('evennia.utils.gametime.gametime', new=Mock(return_value=2975000898.46))
|
||||
class TestCustomGameTime(EvenniaTest):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
gametime.gametime = Mock(return_value=2975000898.46) # does not seem to work
|
||||
|
||||
def tearDown(self):
|
||||
if hasattr(self, "timescript"):
|
||||
self.timescript.stop()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ Unit tests for the utilities of the evennia.utils.gametime module.
|
|||
import time
|
||||
from unittest.mock import Mock
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
from evennia.utils import gametime
|
||||
|
|
@ -13,12 +14,18 @@ time.time = Mock(return_value=1555595378.0)
|
|||
|
||||
|
||||
class TestGametime(TestCase):
|
||||
def setUp(self):
|
||||
def setUp(self) -> None:
|
||||
gametime.SERVER_RUNTIME = 600.0
|
||||
gametime.SERVER_START_TIME = time.time() - 300
|
||||
gametime.SERVER_RUNTIME_LAST_UPDATED = time.time() - 30
|
||||
gametime.TIMEFACTOR = 5.0
|
||||
|
||||
def tearDown(self) -> None:
|
||||
gametime.SERVER_RUNTIME_LAST_UPDATED = 0.0
|
||||
gametime.SERVER_RUNTIME = 0.0
|
||||
gametime.SERVER_START_TIME = 0.0
|
||||
gametime.TIMEFACTOR = settings.TIME_FACTOR
|
||||
|
||||
def test_runtime(self):
|
||||
self.assertAlmostEqual(gametime.runtime(), 630.0)
|
||||
|
||||
|
|
@ -69,6 +76,7 @@ class TestGametime(TestCase):
|
|||
self.assertIsInstance(script, gametime.TimeScript)
|
||||
self.assertAlmostEqual(script.interval, 17280)
|
||||
self.assertEqual(script.repeats, 1)
|
||||
script.stop()
|
||||
|
||||
def test_repeat_schedule(self):
|
||||
callback = Mock()
|
||||
|
|
@ -76,3 +84,4 @@ class TestGametime(TestCase):
|
|||
self.assertIsInstance(script, gametime.TimeScript)
|
||||
self.assertAlmostEqual(script.interval, 12)
|
||||
self.assertEqual(script.repeats, -1)
|
||||
script.stop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue