Skip to content

Commit

Permalink
- use gzip compression for vcr tapes (old tapes are still readable)
Browse files Browse the repository at this point in the history
barsch committed Apr 2, 2017
1 parent aab7d7c commit d33c35e
Showing 27 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ def vcr_test_suite():

setup(
name='vcr',
version='0.0.8',
version='0.0.9',
description='VCR - decorator for capturing and simulating network ' +
'communication',
long_description=readme,
2 changes: 2 additions & 0 deletions tests/test_doctest.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ def runTest(self): # NOQA
if '+VCR' in self._dt_test.docstring:
return vcr(self._runTest)()
return self._runTest()


doctest.DocTestCase._runTest = doctest.DocTestCase.runTest
doctest.DocTestCase.runTest = runTest
doctest.register_optionflag('VCR')
Binary file modified tests/vcrtapes/test_core.read_test.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_doctest.some_function_with_doctest.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_http_get.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_http_get_invalid.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_http_post.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_https_get.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_https_head.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_http_client.test_redirect_to_https.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_allow_redirects_false.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_cookie_jar.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_cookies.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_get_fdsn.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_http_get.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_http_post.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_http_post_file.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_https_get.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_redirect.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_redirect_twice.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_sessions.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_requests.test_sessions2.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_socket.test_arclink.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_socket.test_seedlink.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_telnetlib.test_arclink.vcr
Binary file not shown.
Binary file modified tests/vcrtapes/test_telnetlib.test_read_until_only_linesep.vcr
Binary file not shown.
13 changes: 10 additions & 3 deletions vcr/core.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
from future.utils import PY2

import copy
import gzip
import io
import os
import pickle
@@ -39,6 +40,7 @@
import time
import warnings


from .utils import classproperty


@@ -505,7 +507,7 @@ def _vcr_inner(*args, **kwargs):
else:
warnings.warn(msg)
else:
with open(tape, 'wb') as fh:
with gzip.open(tape, 'wb') as fh:
pickle.dump(VCRSystem.playlist, fh, protocol=2)
else:
# playback mode
@@ -521,8 +523,13 @@ def _vcr_inner(*args, **kwargs):
VCRSystem.stop()
raise IOError(msg)
# load playlist
with open(tape, 'rb') as fh:
VCRSystem.playlist = pickle.load(fh)
try:
with gzip.open(tape, 'rb') as fh:
VCRSystem.playlist = pickle.load(fh)
except OSError:
# support for older uncompressed tapes
with open(tape, 'rb') as fh:
VCRSystem.playlist = pickle.load(fh)
# execute decorated function
try:
value = func(*args, **kwargs)

0 comments on commit d33c35e

Please sign in to comment.