mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
use conditional requirements for backport libraries Fixes #147
This commit is contained in:
@@ -33,7 +33,7 @@ python:
|
|||||||
- 3.4
|
- 3.4
|
||||||
- pypy
|
- pypy
|
||||||
install:
|
install:
|
||||||
- pip install PyYAML pytest pytest-localserver --use-mirrors
|
- pip install .
|
||||||
- if [ $WITH_LIB = "requests1.x" ] ; then pip install requests==1.2.3; fi
|
- if [ $WITH_LIB = "requests1.x" ] ; then pip install requests==1.2.3; fi
|
||||||
- if [ $WITH_LIB = "requests2.2" ] ; then pip install requests==2.2.1; fi
|
- if [ $WITH_LIB = "requests2.2" ] ; then pip install requests==2.2.1; fi
|
||||||
- if [ $WITH_LIB = "requests2.3" ] ; then pip install requests==2.3.0; fi
|
- if [ $WITH_LIB = "requests2.3" ] ; then pip install requests==2.3.0; fi
|
||||||
|
|||||||
9
setup.py
9
setup.py
@@ -19,6 +19,7 @@ class PyTest(TestCommand):
|
|||||||
errno = pytest.main(self.test_args)
|
errno = pytest.main(self.test_args)
|
||||||
sys.exit(errno)
|
sys.exit(errno)
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='vcrpy',
|
name='vcrpy',
|
||||||
version='1.5.2',
|
version='1.5.2',
|
||||||
@@ -31,8 +32,12 @@ setup(
|
|||||||
author_email='me@kevinmccarthy.org',
|
author_email='me@kevinmccarthy.org',
|
||||||
url='https://github.com/kevin1024/vcrpy',
|
url='https://github.com/kevin1024/vcrpy',
|
||||||
packages=find_packages(exclude=("tests*",)),
|
packages=find_packages(exclude=("tests*",)),
|
||||||
install_requires=['PyYAML', 'mock', 'six>=1.5', 'contextlib2',
|
install_requires=['PyYAML', 'wrapt', 'six>=1.5'],
|
||||||
'wrapt', 'backport_collections'],
|
extras_require = {
|
||||||
|
':python_version in "2.4, 2.5, 2.6"':
|
||||||
|
['contextlib2', 'backport_collections', 'mock'],
|
||||||
|
':python_version in "2.7, 3.1, 3.2"': ['contextlib2', 'mock'],
|
||||||
|
},
|
||||||
license='MIT',
|
license='MIT',
|
||||||
tests_require=['pytest', 'mock', 'pytest-localserver'],
|
tests_require=['pytest', 'mock', 'pytest-localserver'],
|
||||||
cmdclass={'test': PyTest},
|
cmdclass={'test': PyTest},
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ import inspect
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from six.moves import http_client as httplib
|
from six.moves import http_client as httplib
|
||||||
import contextlib2
|
|
||||||
import mock
|
|
||||||
import pytest
|
import pytest
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from vcr.compat import mock, contextlib
|
||||||
from vcr.cassette import Cassette
|
from vcr.cassette import Cassette
|
||||||
from vcr.errors import UnhandledHTTPRequestError
|
from vcr.errors import UnhandledHTTPRequestError
|
||||||
from vcr.patch import force_reset
|
from vcr.patch import force_reset
|
||||||
@@ -158,7 +157,7 @@ def test_nesting_cassette_context_managers(*args):
|
|||||||
second_response = copy.deepcopy(first_response)
|
second_response = copy.deepcopy(first_response)
|
||||||
second_response['body']['string'] = b'second_response'
|
second_response['body']['string'] = b'second_response'
|
||||||
|
|
||||||
with contextlib2.ExitStack() as exit_stack:
|
with contextlib.ExitStack() as exit_stack:
|
||||||
first_cassette = exit_stack.enter_context(Cassette.use(path='test'))
|
first_cassette = exit_stack.enter_context(Cassette.use(path='test'))
|
||||||
exit_stack.enter_context(mock.patch.object(first_cassette, 'play_response',
|
exit_stack.enter_context(mock.patch.object(first_cassette, 'play_response',
|
||||||
return_value=first_response))
|
return_value=first_response))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import mock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from vcr.compat import mock
|
||||||
from vcr.serialize import deserialize
|
from vcr.serialize import deserialize
|
||||||
from vcr.serializers import yamlserializer, jsonserializer
|
from vcr.serializers import yamlserializer, jsonserializer
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import mock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from vcr import VCR, use_cassette
|
from vcr import VCR, use_cassette
|
||||||
|
from vcr.compat import mock
|
||||||
from vcr.request import Request
|
from vcr.request import Request
|
||||||
from vcr.stubs import VCRHTTPSConnection
|
from vcr.stubs import VCRHTTPSConnection
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,11 @@
|
|||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import contextlib2
|
|
||||||
import wrapt
|
import wrapt
|
||||||
try:
|
|
||||||
from collections import Counter
|
|
||||||
except ImportError:
|
|
||||||
from backport_collections import Counter
|
|
||||||
|
|
||||||
# Internal imports
|
# Internal imports
|
||||||
|
from .compat import contextlib, collections
|
||||||
from .errors import UnhandledHTTPRequestError
|
from .errors import UnhandledHTTPRequestError
|
||||||
from .matchers import requests_match, uri, method
|
from .matchers import requests_match, uri, method
|
||||||
from .patch import CassettePatcherBuilder
|
from .patch import CassettePatcherBuilder
|
||||||
@@ -43,7 +40,7 @@ class CassetteContextDecorator(object):
|
|||||||
self.__finish = None
|
self.__finish = None
|
||||||
|
|
||||||
def _patch_generator(self, cassette):
|
def _patch_generator(self, cassette):
|
||||||
with contextlib2.ExitStack() as exit_stack:
|
with contextlib.ExitStack() as exit_stack:
|
||||||
for patcher in CassettePatcherBuilder(cassette).build():
|
for patcher in CassettePatcherBuilder(cassette).build():
|
||||||
exit_stack.enter_context(patcher)
|
exit_stack.enter_context(patcher)
|
||||||
log.debug('Entered context for cassette at {0}.'.format(cassette._path))
|
log.debug('Entered context for cassette at {0}.'.format(cassette._path))
|
||||||
@@ -148,7 +145,7 @@ class Cassette(object):
|
|||||||
|
|
||||||
# self.data is the list of (req, resp) tuples
|
# self.data is the list of (req, resp) tuples
|
||||||
self.data = []
|
self.data = []
|
||||||
self.play_counts = Counter()
|
self.play_counts = collections.Counter()
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
self.rewound = False
|
self.rewound = False
|
||||||
|
|
||||||
|
|||||||
18
vcr/compat.py
Normal file
18
vcr/compat.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
try:
|
||||||
|
import contextlib
|
||||||
|
except ImportError:
|
||||||
|
import contextlib2 as contextlib
|
||||||
|
else:
|
||||||
|
if not hasattr(contextlib, 'ExitStack'):
|
||||||
|
import contextlib2 as contextlib
|
||||||
|
|
||||||
|
import collections
|
||||||
|
if not hasattr(collections, 'Counter'):
|
||||||
|
import backport_collections as collections
|
||||||
|
|
||||||
|
__all__ = ['mock', 'contextlib', 'collections']
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import collections
|
|
||||||
import copy
|
import copy
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
@@ -6,6 +5,7 @@ import os
|
|||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from .compat import collections
|
||||||
from .cassette import Cassette
|
from .cassette import Cassette
|
||||||
from .serializers import yamlserializer, jsonserializer
|
from .serializers import yamlserializer, jsonserializer
|
||||||
from .util import compose
|
from .util import compose
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
from six import BytesIO, text_type
|
from six import BytesIO, text_type
|
||||||
from six.moves.urllib.parse import urlparse, urlencode, urlunparse
|
from six.moves.urllib.parse import urlparse, urlencode, urlunparse
|
||||||
try:
|
|
||||||
from collections import OrderedDict
|
|
||||||
except ImportError:
|
|
||||||
from backport_collections import OrderedDict
|
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from .compat import collections
|
||||||
|
|
||||||
|
|
||||||
def remove_headers(request, headers_to_remove):
|
def remove_headers(request, headers_to_remove):
|
||||||
headers = copy.copy(request.headers)
|
headers = copy.copy(request.headers)
|
||||||
@@ -40,7 +38,7 @@ def remove_post_data_parameters(request, post_data_parameters_to_remove):
|
|||||||
del json_data[k]
|
del json_data[k]
|
||||||
request.body = json.dumps(json_data).encode('utf-8')
|
request.body = json.dumps(json_data).encode('utf-8')
|
||||||
else:
|
else:
|
||||||
post_data = OrderedDict()
|
post_data = collections.OrderedDict()
|
||||||
if isinstance(request.body, text_type):
|
if isinstance(request.body, text_type):
|
||||||
request.body = request.body.encode('utf-8')
|
request.body = request.body.encode('utf-8')
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
import functools
|
import functools
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import contextlib2
|
from .compat import contextlib, mock
|
||||||
import mock
|
|
||||||
|
|
||||||
from .stubs import VCRHTTPConnection, VCRHTTPSConnection
|
from .stubs import VCRHTTPConnection, VCRHTTPSConnection
|
||||||
from six.moves import http_client as httplib
|
from six.moves import http_client as httplib
|
||||||
|
|
||||||
@@ -323,9 +321,9 @@ def reset_patchers():
|
|||||||
_CertValidatingHTTPSConnection)
|
_CertValidatingHTTPSConnection)
|
||||||
|
|
||||||
|
|
||||||
@contextlib2.contextmanager
|
@contextlib.contextmanager
|
||||||
def force_reset():
|
def force_reset():
|
||||||
with contextlib2.ExitStack() as exit_stack:
|
with contextlib.ExitStack() as exit_stack:
|
||||||
for patcher in reset_patchers():
|
for patcher in reset_patchers():
|
||||||
exit_stack.enter_context(patcher)
|
exit_stack.enter_context(patcher)
|
||||||
yield
|
yield
|
||||||
|
|||||||
Reference in New Issue
Block a user