-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utilities.py
35 lines (25 loc) · 981 Bytes
/
test_utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from unittest import TestCase
from unittest.mock import MagicMock
from utilities import retry_for_exception, retry_for_exception_decorator
class UtilitiesTest(TestCase):
def test_retryForException_whenThrowException_shouldRetry(self):
mock = MagicMock()
def call():
raise KeyError
mock.side_effect = call
try:
retry_for_exception(KeyError, mock, 10)
except Exception as e:
self.assertIsInstance(e, KeyError)
self.assertEquals(10, mock.call_count)
def test_retryForExceptionDecorator_whenThrowException_shouldRetry(self):
mock = MagicMock()
def call():
raise KeyError
mock.side_effect = call
mock_with_decorator = retry_for_exception_decorator(KeyError, 10)(mock)
try:
mock_with_decorator()
except Exception as e:
self.assertIsInstance(e, KeyError)
self.assertEquals(10, mock.call_count)