forked from tayler6000/pyVoIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_util.py
31 lines (27 loc) · 951 Bytes
/
test_util.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
from pyVoIP.util import acquired_lock_and_unblocked_socket
from threading import Lock
from socket import socket
import pytest
def test_acquired_lock_and_unblocked_socket():
l = Lock()
s = socket()
assert l.locked() is False
assert s.getblocking() is True
with acquired_lock_and_unblocked_socket(l, s):
assert l.locked() is True
assert s.getblocking() is False
assert l.locked() is False
assert s.getblocking() is True
def test_acquired_lock_and_unblocked_socket__with_exception():
l = Lock()
s = socket()
assert l.locked() is False
assert s.getblocking() is True
with pytest.raises(Exception):
with acquired_lock_and_unblocked_socket(l, s):
assert l.locked() is True
assert s.getblocking() is False
raise Exception("Uh oh")
assert False, "Should never execute"
assert l.locked() is False
assert s.getblocking() is True