Skip to content

Commit f00a9cb

Browse files
committed
Simplify test/unit/test_client.py::test_assert_version using pytest.warns and fix errors in previous commit
1 parent 724e7b2 commit f00a9cb

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

ipfshttpclient/client/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import os
99
import typing as ty
10+
import warnings
1011

1112
import multiaddr
1213

test/functional/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def is_available(): # noqa
2020
if not isinstance(__is_available, bool):
2121
try:
2222
ipfshttpclient.connect()
23-
except ipfshttpclient.exceptions.Error as error:
23+
except ipfshttpclient.exceptions.Error:
2424
__is_available = False
2525
else:
2626
__is_available = True

test/unit/test_client.py

+5-30
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,27 @@
1-
import warnings
2-
31
import pytest
42

53
import ipfshttpclient
64

75

86
def test_assert_version():
9-
with warnings.catch_warnings(record=True) as w:
10-
# Cause all warnings to always be triggered.
11-
warnings.simplefilter("always")
12-
7+
with pytest.warns(None) as warnings:
138
# Minimum required version
149
ipfshttpclient.assert_version("0.1.0", "0.1.0", "0.2.0", ["0.1.2"])
1510

16-
assert len(w) == 0
11+
assert len(warnings) == 0
1712

1813
# Too high version
19-
with warnings.catch_warnings(record=True) as w:
20-
# Cause all warnings to always be triggered.
21-
warnings.simplefilter("always")
22-
14+
with pytest.warns(ipfshttpclient.exceptions.VersionMismatch):
2315
ipfshttpclient.assert_version("0.2.0", "0.1.0", "0.2.0", ["0.1.2"])
2416

25-
assert len(w) == 1
26-
assert issubclass(w[-1].category, ipfshttpclient.exceptions.VersionMismatch)
27-
28-
2917
# Too low version
30-
with warnings.catch_warnings(record=True) as w:
31-
# Cause all warnings to always be triggered.
32-
warnings.simplefilter("always")
33-
18+
with pytest.warns(ipfshttpclient.exceptions.VersionMismatch):
3419
ipfshttpclient.assert_version("0.0.5", "0.1.0", "0.2.0", ["0.1.2"])
3520

36-
assert len(w) == 1
37-
assert issubclass(w[-1].category, ipfshttpclient.exceptions.VersionMismatch)
38-
39-
4021
# Blacklisted version
41-
with warnings.catch_warnings(record=True) as w:
42-
# Cause all warnings to always be triggered.
43-
warnings.simplefilter("always")
44-
22+
with pytest.warns(ipfshttpclient.exceptions.VersionMismatch):
4523
ipfshttpclient.assert_version("0.1.2-1", "0.1.0", "0.2.0", ["0.1.2"])
4624

47-
assert len(w) == 1
48-
assert issubclass(w[-1].category, ipfshttpclient.exceptions.VersionMismatch)
49-
5025

5126
def test_client_session_param():
5227
client = ipfshttpclient.Client(session=True)

0 commit comments

Comments
 (0)