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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user