import unittest import mock from robot_interface.utils.timeblock import TimeBlock class AnyFloat(object): def __eq__(self, other): return isinstance(other, float) class TestTimeBlock(unittest.TestCase): def test_no_limit(self): callback = mock.Mock() 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() if __name__ == '__main__': unittest.main()