forked from micropython/micropython-lib
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
35 lines (27 loc) · 886 Bytes
/
tests.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
importunittest
fromucontextlibimportcontextmanager
classContextManagerTestCase(unittest.TestCase):
defsetUp(self):
self._history= []
@contextmanager
defmanager(x):
self._history.append("start")
try:
yieldx
finally:
self._history.append("finish")
self._manager=manager
deftest_context_manager(self):
withself._manager(123) asx:
self.assertEqual(x, 123)
self.assertEqual(self._history, ["start", "finish"])
deftest_context_manager_on_error(self):
exc=Exception()
try:
withself._manager(123):
raiseexc
exceptExceptionase:
self.assertEqual(exc, e)
self.assertEqual(self._history, ["start", "finish"])
if__name__=="__main__":
unittest.main()