-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathtest_client.py
45 lines (34 loc) · 1.24 KB
/
test_client.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
36
37
38
39
40
41
42
43
44
45
import pytest
import warnings
import ipfshttpclient
def test_assert_version():
with warnings.catch_warnings():
# Minimum required version
ipfshttpclient.assert_version("0.1.0", "0.1.0", "0.2.0", ["0.1.2"])
warnings.simplefilter("error")
# Too high version
with pytest.warns(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.2.0", "0.1.0", "0.2.0", ["0.1.2"])
# Too low version
with pytest.warns(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.0.5", "0.1.0", "0.2.0", ["0.1.2"])
# Blacklisted version
with pytest.warns(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.1.2-1", "0.1.0", "0.2.0", ["0.1.2"])
def test_client_session_param():
client = ipfshttpclient.Client(session=True)
assert client._client._session is not None
try:
with pytest.raises(Exception):
with client:
pass # Should fail because a session is already open
assert client._client._session is not None
finally:
client.close()
assert client._client._session is None
def test_client_session_context():
client = ipfshttpclient.Client()
assert client._client._session is None
with client:
assert client._client._session is not None
assert client._client._session is None