mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Merge pull request #442 from addgene/master
fixes #440 VCR responses don't work with Biopython on Python3
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
# coding: UTF-8
|
||||
import io
|
||||
import unittest
|
||||
|
||||
import six
|
||||
|
||||
from vcr.stubs import VCRHTTPResponse
|
||||
|
||||
|
||||
@@ -66,3 +71,52 @@ def test_response_headers_should_have_correct_values():
|
||||
|
||||
assert response.headers.get('content-length') == "10806"
|
||||
assert response.headers.get('date') == "Fri, 24 Oct 2014 18:35:37 GMT"
|
||||
|
||||
|
||||
@unittest.skipIf(six.PY2, "Regression test for Python3 only")
|
||||
def test_response_parses_correctly_and_fp_attribute_error_is_not_thrown():
|
||||
"""
|
||||
Regression test for https://github.com/kevin1024/vcrpy/issues/440
|
||||
:return:
|
||||
"""
|
||||
recorded_response = {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 200
|
||||
},
|
||||
"headers": {
|
||||
"content-length": ["0"],
|
||||
"server": ["gunicorn/18.0"],
|
||||
"connection": ["Close"],
|
||||
"access-control-allow-credentials": ["true"],
|
||||
"date": ["Fri, 24 Oct 2014 18:35:37 GMT"],
|
||||
"access-control-allow-origin": ["*"],
|
||||
"content-type": ["text/html; charset=utf-8"],
|
||||
},
|
||||
"body": {
|
||||
"string": b"\nPMID- 19416910\nOWN - NLM\nSTAT- MEDLINE\nDA - 20090513\nDCOM- "
|
||||
b"20090622\nLR - "
|
||||
b"20141209\nIS - 1091-6490 (Electronic)\nIS - 0027-8424 (Linking)\nVI - "
|
||||
b"106\nIP - "
|
||||
b"19\nDP - 2009 May 12\nTI - Genetic dissection of histone deacetylase "
|
||||
b"requirement in "
|
||||
b"tumor cells.\nPG - 7751-5\nLID - 10.1073/pnas.0903139106 [doi]\nAB - "
|
||||
b"Histone "
|
||||
b"deacetylase inhibitors (HDACi) represent a new group of drugs currently\n "
|
||||
b" being "
|
||||
b"tested in a wide variety of clinical applications. They are especially\n "
|
||||
b" effective "
|
||||
b"in preclinical models of cancer where they show antiproliferative\n "
|
||||
b"action in many "
|
||||
b"different types of cancer cells. Recently, the first HDACi was\n "
|
||||
b"approved for the "
|
||||
b"treatment of cutaneous T cell lymphomas. Most HDACi currently in\n "
|
||||
b"clinical "
|
||||
|
||||
}
|
||||
}
|
||||
vcr_response = VCRHTTPResponse(recorded_response)
|
||||
handle = io.TextIOWrapper(io.BufferedReader(vcr_response), encoding='utf-8')
|
||||
handle = iter(handle)
|
||||
articles = [line for line in handle]
|
||||
assert len(articles) > 1
|
||||
|
||||
@@ -60,9 +60,10 @@ def serialize_headers(response):
|
||||
|
||||
class VCRHTTPResponse(HTTPResponse):
|
||||
"""
|
||||
Stub reponse class that gets returned instead of a HTTPResponse
|
||||
Stub response class that gets returned instead of a HTTPResponse
|
||||
"""
|
||||
def __init__(self, recorded_response):
|
||||
self.fp = None
|
||||
self.recorded_response = recorded_response
|
||||
self.reason = recorded_response['status']['message']
|
||||
self.status = self.code = recorded_response['status']['code']
|
||||
@@ -93,9 +94,30 @@ class VCRHTTPResponse(HTTPResponse):
|
||||
def read(self, *args, **kwargs):
|
||||
return self._content.read(*args, **kwargs)
|
||||
|
||||
def readall(self):
|
||||
return self._content.readall()
|
||||
|
||||
def readinto(self, *args, **kwargs):
|
||||
return self._content.readinto(*args, **kwargs)
|
||||
|
||||
def readline(self, *args, **kwargs):
|
||||
return self._content.readline(*args, **kwargs)
|
||||
|
||||
def readlines(self, *args, **kwargs):
|
||||
return self._content.readlines(*args, **kwargs)
|
||||
|
||||
def seekable(self):
|
||||
return self._content.seekable()
|
||||
|
||||
def tell(self):
|
||||
return self._content.tell()
|
||||
|
||||
def isatty(self):
|
||||
return self._content.isatty()
|
||||
|
||||
def seek(self, *args, **kwargs):
|
||||
return self._content.seek(*args, **kwargs)
|
||||
|
||||
def close(self):
|
||||
self._closed = True
|
||||
return True
|
||||
@@ -121,6 +143,9 @@ class VCRHTTPResponse(HTTPResponse):
|
||||
else:
|
||||
return default
|
||||
|
||||
def readable(self):
|
||||
return self._content.readable()
|
||||
|
||||
|
||||
class VCRConnection(object):
|
||||
# A reference to the cassette that's currently being patched in
|
||||
|
||||
Reference in New Issue
Block a user