|
1 |
| -import warnings |
2 |
| - |
3 | 1 | import pytest
|
4 | 2 |
|
5 | 3 | import ipfshttpclient
|
6 | 4 |
|
7 | 5 |
|
8 | 6 | 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: |
13 | 8 | # Minimum required version
|
14 | 9 | ipfshttpclient.assert_version("0.1.0", "0.1.0", "0.2.0", ["0.1.2"])
|
15 | 10 |
|
16 |
| - assert len(w) == 0 |
| 11 | + assert len(warnings) == 0 |
17 | 12 |
|
18 | 13 | # 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): |
23 | 15 | ipfshttpclient.assert_version("0.2.0", "0.1.0", "0.2.0", ["0.1.2"])
|
24 | 16 |
|
25 |
| - assert len(w) == 1 |
26 |
| - assert issubclass(w[-1].category, ipfshttpclient.exceptions.VersionMismatch) |
27 |
| - |
28 |
| - |
29 | 17 | # 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): |
34 | 19 | ipfshttpclient.assert_version("0.0.5", "0.1.0", "0.2.0", ["0.1.2"])
|
35 | 20 |
|
36 |
| - assert len(w) == 1 |
37 |
| - assert issubclass(w[-1].category, ipfshttpclient.exceptions.VersionMismatch) |
38 |
| - |
39 |
| - |
40 | 21 | # 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): |
45 | 23 | ipfshttpclient.assert_version("0.1.2-1", "0.1.0", "0.2.0", ["0.1.2"])
|
46 | 24 |
|
47 |
| - assert len(w) == 1 |
48 |
| - assert issubclass(w[-1].category, ipfshttpclient.exceptions.VersionMismatch) |
49 |
| - |
50 | 25 |
|
51 | 26 | def test_client_session_param():
|
52 | 27 | client = ipfshttpclient.Client(session=True)
|
|
0 commit comments