-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_decorator.py
More file actions
39 lines (28 loc) · 1.17 KB
/
test_decorator.py
File metadata and controls
39 lines (28 loc) · 1.17 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
# -*- coding: utf-8 -*-
import logging
import unittest
import hutils
class DecoratorTests(unittest.TestCase):
def setUp(self):
logging.disable(logging.CRITICAL)
def test_context_manager(self):
with self.assertRaises(IOError), hutils.catches(ValueError, TypeError, raises=IOError()):
raise ValueError("should wrap this error")
with self.assertRaises(IOError), hutils.catches(ValueError, TypeError, raises=lambda x: IOError(str(x))):
raise TypeError("should wrap this error")
def test_decorator(self):
@hutils.catches(ValueError, raises=IOError(), logger=__name__)
def raise_io_error():
raise ValueError("should wrap this error")
with self.assertRaises(IOError):
raise_io_error()
def test_mute(self):
def value_error():
raise ValueError()
mute_value_error = hutils.mutes(ValueError, returns=42)(value_error)
self.assertEqual(42, mute_value_error())
with hutils.mutes(ValueError):
value_error()
with self.assertRaises(ValueError), hutils.mutes(IOError):
value_error()
self.assertTrue(True)