| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import queue |
| 4 |
from unittest import mock |
| 5 |
|
| 6 |
import pytest |
| 7 |
|
| 8 |
from urllib3 import HTTPConnectionPool |
| 9 |
from urllib3.exceptions import EmptyPoolError |
| 10 |
|
| 11 |
|
| 12 |
class BadError(Exception): |
| 13 |
""" |
| 14 |
This should not be raised. |
| 15 |
""" |
| 16 |
|
| 17 |
|
| 18 |
class TestMonkeypatchResistance: |
| 19 |
""" |
| 20 |
Test that connection pool works even with a monkey patched Queue module, |
| 21 |
see obspy/obspy#1599, psf/requests#3742, urllib3/urllib3#1061. |
| 22 |
""" |
| 23 |
|
| 24 |
def test_queue_monkeypatching(self) -> None: |
| 25 |
with mock.patch.object(queue, "Empty", BadError): |
| 26 |
with HTTPConnectionPool(host="localhost", block=True) as http: |
| 27 |
http._get_conn() |
| 28 |
with pytest.raises(EmptyPoolError): |
| 29 |
http._get_conn(timeout=0) |