From e93060c81bef0130d0626b348ab753db50e3f8fb Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Sat, 21 Jul 2018 17:03:19 +0800 Subject: [PATCH 1/3] Fix compatibility with Python 3.7 --- setup.py | 1 + tests/integration/test_urllib2.py | 5 ++++- vcr/cassette.py | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 3935af6..65c0773 100644 --- a/setup.py +++ b/setup.py @@ -62,6 +62,7 @@ setup( 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Testing', diff --git a/tests/integration/test_urllib2.py b/tests/integration/test_urllib2.py index 8a633ba..3c0b021 100644 --- a/tests/integration/test_urllib2.py +++ b/tests/integration/test_urllib2.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- '''Integration tests with urllib2''' +import ssl from six.moves.urllib.request import urlopen from six.moves.urllib_parse import urlencode import pytest_httpbin.certs @@ -12,7 +13,9 @@ from assertions import assert_cassette_has_one_response def urlopen_with_cafile(*args, **kwargs): - kwargs['cafile'] = pytest_httpbin.certs.where() + context = ssl.create_default_context(cafile=pytest_httpbin.certs.where()) + context.check_hostname = False + kwargs['context'] = context try: return urlopen(*args, **kwargs) except TypeError: diff --git a/vcr/cassette.py b/vcr/cassette.py index d64dec6..3b6f54e 100644 --- a/vcr/cassette.py +++ b/vcr/cassette.py @@ -136,7 +136,10 @@ class CassetteContextDecorator(object): except Exception: to_yield = coroutine.throw(*sys.exc_info()) else: - to_yield = coroutine.send(to_send) + try: + to_yield = coroutine.send(to_send) + except StopIteration: + break def _handle_function(self, fn): with self as cassette: From b38915a89aef77f7169fdf3aa949072050029648 Mon Sep 17 00:00:00 2001 From: Luiz Menezes Date: Tue, 18 Sep 2018 18:42:22 -0300 Subject: [PATCH 2/3] Fix httplib2 compatibility with py37 --- tests/integration/test_httplib2.py | 11 ++++++++--- vcr/stubs/httplib2_stubs.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_httplib2.py b/tests/integration/test_httplib2.py index 05a25d3..4eda032 100644 --- a/tests/integration/test_httplib2.py +++ b/tests/integration/test_httplib2.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- '''Integration tests with httplib2''' -# External imports +import sys + from six.moves.urllib_parse import urlencode import pytest import pytest_httpbin.certs -# Internal imports import vcr from assertions import assert_cassette_has_one_response @@ -19,7 +19,12 @@ def http(): Returns an httplib2 HTTP instance with the certificate replaced by the httpbin one. """ - return httplib2.Http(ca_certs=pytest_httpbin.certs.where()) + kwargs = { + 'ca_certs': pytest_httpbin.certs.where() + } + if sys.version_info[:2] == (3, 7): + kwargs['disable_ssl_certificate_validation'] = True + return httplib2.Http(**kwargs) def test_response_code(tmpdir, httpbin_both): diff --git a/vcr/stubs/httplib2_stubs.py b/vcr/stubs/httplib2_stubs.py index 4f31537..3d83406 100644 --- a/vcr/stubs/httplib2_stubs.py +++ b/vcr/stubs/httplib2_stubs.py @@ -40,6 +40,7 @@ class VCRHTTPSConnectionWithTimeout(VCRHTTPSConnection, 'timeout', 'source_address', 'ca_certs', + 'disable_ssl_certificate_validation', } unknown_keys = set(kwargs.keys()) - safe_keys safe_kwargs = kwargs.copy() From 9a9cdb3a950cb6a5197eab1d6c10d9072b4cfccf Mon Sep 17 00:00:00 2001 From: Luiz Menezes Date: Tue, 18 Sep 2018 18:47:32 -0300 Subject: [PATCH 3/3] add py37 on CI build --- .travis.yml | 25 +++++++++++++++++++++++++ tox.ini | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 169ee5a..6759546 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,31 @@ env: - TOX_SUFFIX="tornado4" - TOX_SUFFIX="aiohttp" matrix: + include: + - env: TOX_SUFFIX="flakes" + python: 3.7 + dist: xenial + sudo: true + - env: TOX_SUFFIX="requests27" + python: 3.7 + dist: xenial + sudo: true + - env: TOX_SUFFIX="httplib2" + python: 3.7 + dist: xenial + sudo: true + - env: TOX_SUFFIX="urllib3121" + python: 3.7 + dist: xenial + sudo: true + - env: TOX_SUFFIX="tornado4" + python: 3.7 + dist: xenial + sudo: true + - env: TOX_SUFFIX="aiohttp" + python: 3.7 + dist: xenial + sudo: true allow_failures: - env: TOX_SUFFIX="boto3" - env: TOX_SUFFIX="aiohttp" diff --git a/tox.ini b/tox.ini index 3eeb686..865cd62 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py27,py35,py36,pypy}-{flakes,requests27,httplib2,urllib3121,tornado4,boto3,aiohttp} +envlist = {py27,py35,py36,py37,pypy}-{flakes,requests27,httplib2,urllib3121,tornado4,boto3,aiohttp} [testenv:flakes] skipsdist = True