-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
60 lines (37 loc) · 1.45 KB
/
tests.py
File metadata and controls
60 lines (37 loc) · 1.45 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import unittest
import logging
from unittest.mock import patch
from decorators import exception_handler
logging.disable(logging.CRITICAL)
class ExceptionHandlerTests(unittest.TestCase):
def test_exception_handler(self):
def handler_function(need_error, result):
return (result, need_error)
@exception_handler(error_message='TEST',
additional_handler=handler_function)
def testing_func(need_error, result):
if not need_error:
return result
raise Exception('test')
result = testing_func(False, 1)
self.assertEqual(result, 1)
handler_result = testing_func(True, 1)
self.assertEqual(handler_result, (1, True))
@exception_handler()
def only_err():
raise Exception('test')
result = only_err()
self.assertEqual(result, 0)
@exception_handler(error_message='TEST',
additional_handler=handler_function,
additional_log_data=lambda ne, res: str(res))
def testing_func_one(need_error, result):
if not need_error:
return result
raise Exception('test')
result = testing_func_one(False, 1)
self.assertEqual(result, 1)
handler_result = testing_func_one(True, 1)
self.assertEqual(handler_result, (1, True))
if __name__ == '__main__':
unittest.main()