Skip to content

Commit 3df0814

Browse files
committed
Support docker-py
1 parent 80099ac commit 3df0814

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

Diff for: setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def find_version(*file_paths):
5555
"pytest-cov",
5656
"pytest-httpbin",
5757
"pytest",
58+
"pytest-timeout",
59+
"docker",
5860
"requests>=2.22.0",
5961
"tornado",
6062
"urllib3",

Diff for: tests/integration/test_docker.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Integration tests with docker"""
2+
3+
import pytest
4+
import docker
5+
6+
import vcr
7+
8+
@pytest.mark.timeout(3)
9+
def test_docker(tmpdir, timeout=-3):
10+
with vcr.use_cassette(str(tmpdir.join("docker.yaml"))):
11+
client = docker.from_env()

Diff for: vcr/patch.py

+37
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def build(self):
122122
self._tornado(),
123123
self._aiohttp(),
124124
self._httpx(),
125+
self._docker(),
125126
self._build_patchers_from_mock_triples(self._cassette.custom_patches),
126127
)
127128

@@ -250,6 +251,42 @@ def _urllib3(self):
250251

251252
return self._urllib3_patchers(cpool, conn, urllib3_stubs)
252253

254+
def _docker(self):
255+
try:
256+
import docker.transport.unixconn as conn
257+
import docker.transport.unixconn as cpool
258+
except ImportError: # pragma: no cover
259+
return ()
260+
261+
from .stubs import docker_stubs as stubs
262+
263+
http_connection_remover = ConnectionRemover(
264+
self._get_cassette_subclass(stubs.VCRRequestsUnixHTTPConnection),
265+
)
266+
mock_triples = (
267+
(conn, "UnixHTTPConnection", stubs.VCRRequestsUnixHTTPConnection),
268+
(cpool.UnixHTTPConnectionPool, "ConnectionCls", stubs.VCRRequestsUnixHTTPConnection),
269+
)
270+
# These handle making sure that sessions only use the
271+
# connections of the appropriate type.
272+
mock_triples += (
273+
(
274+
cpool.UnixHTTPConnectionPool,
275+
"_get_conn",
276+
self._patched_get_conn(cpool.UnixHTTPConnectionPool, lambda: cpool.UnixHTTPConnection),
277+
),
278+
(
279+
cpool.UnixHTTPConnectionPool,
280+
"_new_conn",
281+
self._patched_new_conn(cpool.UnixHTTPConnectionPool, http_connection_remover),
282+
),
283+
)
284+
285+
return itertools.chain(
286+
self._build_patchers_from_mock_triples(mock_triples),
287+
(http_connection_remover,),
288+
)
289+
253290
@_build_patchers_from_mock_triples_decorator
254291
def _httplib2(self):
255292
try:

Diff for: vcr/stubs/docker_stubs.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Stubs for docker"""
2+
3+
from docker.transport.unixconn import UnixHTTPConnection
4+
from ..stubs import VCRHTTPConnection
5+
6+
# docker defines its own UnixHTTPConnection classes. It includes some polyfills
7+
# for newer features missing in older pythons.
8+
9+
10+
class VCRRequestsUnixHTTPConnection(VCRHTTPConnection, UnixHTTPConnection):
11+
_baseclass = UnixHTTPConnection

0 commit comments

Comments
 (0)