* pyupgrade
* various new codemods
* manual removal of Py2/3 compat imports
* manual adjustment of docs, examples, tests
* to_str is now the new to_unicode, deprecated
redirection to to_bytes has been removed
* to_native_str has been redirected to point to
to_str
* to_unicode has been redirected to point to
to_str
* atomic_write refactored to use
NamedTemporaryDirectory
* various other fixes/refactorings all over the
place
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
__author__ = "Gina Häußge <osd@foosel.net>"
|
|
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
|
|
__copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
|
|
|
import time
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from octoprint.util import ResettableTimer
|
|
|
|
|
|
class ResettableTimerTest(unittest.TestCase):
|
|
def setUp(self):
|
|
pass
|
|
|
|
def test_function(self):
|
|
timer_task = mock.MagicMock()
|
|
|
|
timer = ResettableTimer(10, timer_task)
|
|
timer.start()
|
|
|
|
# wait for it
|
|
timer.join()
|
|
|
|
self.assertEqual(1, timer_task.call_count)
|
|
|
|
def test_reset_callback(self):
|
|
timer_task = mock.MagicMock()
|
|
on_reset_cb = mock.MagicMock()
|
|
|
|
timer = ResettableTimer(10, timer_task, on_reset=on_reset_cb)
|
|
timer.start()
|
|
|
|
timer.reset()
|
|
|
|
# wait for it
|
|
timer.join()
|
|
|
|
self.assertEqual(1, timer_task.call_count)
|
|
self.assertEqual(1, on_reset_cb.call_count)
|
|
|
|
def test_canceled_callback(self):
|
|
timer_task = mock.MagicMock()
|
|
on_cancelled_cb = mock.MagicMock()
|
|
|
|
timer = ResettableTimer(10, timer_task, on_cancelled=on_cancelled_cb)
|
|
timer.start()
|
|
|
|
time.sleep(5)
|
|
|
|
timer.cancel()
|
|
|
|
time.sleep(10)
|
|
|
|
self.assertEqual(0, timer_task.call_count)
|
|
self.assertEqual(1, on_cancelled_cb.call_count)
|