test: convert to pytest

Instead of built-in `unittest`, now use `pytest`. Find versions that work, convert tests.

ref: N25B-168
This commit is contained in:
Twirre Meulenbelt
2025-10-21 13:55:06 +02:00
parent 45be0366ba
commit 5631a55697
5 changed files with 166 additions and 158 deletions

View File

@@ -1,4 +1,4 @@
import unittest
import time
import mock
@@ -10,31 +10,28 @@ class AnyFloat(object):
return isinstance(other, float)
class TestTimeBlock(unittest.TestCase):
def test_no_limit(self):
callback = mock.Mock()
def test_no_limit():
callback = mock.Mock()
with TimeBlock(callback):
pass
with TimeBlock(callback):
pass
callback.assert_called_once_with(AnyFloat())
def test_exceed_limit(self):
callback = mock.Mock()
with TimeBlock(callback, 0):
pass
callback.assert_called_once_with(AnyFloat())
def test_within_limit(self):
callback = mock.Mock()
with TimeBlock(callback, 5):
pass
callback.assert_not_called()
callback.assert_called_once_with(AnyFloat())
if __name__ == '__main__':
unittest.main()
def test_exceed_limit():
callback = mock.Mock()
with TimeBlock(callback, 0):
time.sleep(0.001)
callback.assert_called_once_with(AnyFloat())
def test_within_limit():
callback = mock.Mock()
with TimeBlock(callback, 5):
pass
callback.assert_not_called()