]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Fix pyflakes and pep8 errors
authorJohn Vandenberg <jayvdb@gmail.com>
Tue, 24 Nov 2015 21:44:33 +0000 (08:44 +1100)
committerJohn Vandenberg <jayvdb@gmail.com>
Wed, 25 Nov 2015 21:25:06 +0000 (08:25 +1100)
Use extra asserts to use previously unused variables in tests,
such as `cass` and `response`.

Fix only pyflakes errors in docs/conf.py

27 files changed:
.travis.yml
docs/conf.py
tests/integration/test_boto.py
tests/integration/test_filter.py
tests/integration/test_httplib2.py
tests/integration/test_ignore.py
tests/integration/test_matchers.py
tests/integration/test_record_mode.py
tests/integration/test_register_matcher.py
tests/integration/test_register_serializer.py
tests/integration/test_requests.py
tests/integration/test_stubs.py
tests/integration/test_tornado.py
tests/integration/test_urllib2.py
tests/integration/test_urllib3.py
tests/integration/test_wild.py
tests/unit/test_cassettes.py
tests/unit/test_request.py
tests/unit/test_stubs.py
tox.ini
vcr/matchers.py
vcr/migration.py
vcr/patch.py
vcr/stubs/__init__.py
vcr/stubs/requests_stubs.py
vcr/stubs/urllib3_stubs.py
vcr/util.py

index a3f5e7302982cf631c773ce12ce296806a28402c..9dc2e6b0605f9948c00d42062cf5e68fb2322915 100644 (file)
@@ -6,6 +6,7 @@ env:
     - secure: AifoKzwhjV94cmcQZrdQmqRu/9rkZZvWpwBv1daeAQpLOKFPGsOm3D+x2cSw9+iCfkgDZDfqQVv1kCaFVxTll8v8jTq5SJdqEY0NmGWbj/UkNtShh609oRDsuzLxAEwtVKYjf/h8K2BRea+bl1tGkwZ2vtmYS6dxNlAijjWOfds=
     - secure: LBSEg/gMj4u4Hrpo3zs6Y/1mTpd2RtcN49mZIFgTdbJ9IhpiNPqcEt647Lz94F9Eses2x2WbNuKqZKZZReY7QLbEzU1m0nN5jlaKrjcG5NR5clNABfFFyhgc0jBikyS4abAG8jc2efeaTrFuQwdoF4sE8YiVrkiVj2X5Xoi6sBk=
   matrix:
+    - TOX_SUFFIX="flakes"
     - TOX_SUFFIX="requests22"
     - TOX_SUFFIX="requests23"
     - TOX_SUFFIX="requests24"
@@ -37,7 +38,7 @@ python:
 - pypy
 install:
 - pip install tox
-- python setup.py install
+- if [[ $TOX_SUFFIX != flakes ]]; then python setup.py install ; fi
 script:
 - v=$TRAVIS_PYTHON_VERSION
 - if [[ ${v%py} != $v ]]; then TOXPY=$v; else TOXPY=py"${v/./}"; fi
index 803c722f2fa1f565202c42813940e459c185cb6d..afb28ccf4e24756ecc52e94a7b7ba1f736fff13b 100644 (file)
@@ -12,9 +12,7 @@
 # All configuration values have a default; values that are commented out
 # serve to show the default.
 
-import sys
 import os
-import shlex
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
index d00cf27b79e3997bc0a60e44f8be971948e800ac..84132d7a2dbdfe5cbeca6ea643b332dd5e7f0b19 100644 (file)
@@ -31,26 +31,26 @@ def test_boto_without_vcr():
 def test_boto_medium_difficulty(tmpdir):
     s3_conn = S3Connection()
     s3_bucket = s3_conn.get_bucket('boto-demo-1394171994')  # a bucket you can access
-    with vcr.use_cassette(str(tmpdir.join('boto-medium.yml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('boto-medium.yml'))):
         k = Key(s3_bucket)
         k.key = 'test.txt'
         k.set_contents_from_string('hello world i am a string')
 
-    with vcr.use_cassette(str(tmpdir.join('boto-medium.yml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('boto-medium.yml'))):
         k = Key(s3_bucket)
         k.key = 'test.txt'
         k.set_contents_from_string('hello world i am a string')
 
 
 def test_boto_hardcore_mode(tmpdir):
-    with vcr.use_cassette(str(tmpdir.join('boto-hardcore.yml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('boto-hardcore.yml'))):
         s3_conn = S3Connection()
         s3_bucket = s3_conn.get_bucket('boto-demo-1394171994')  # a bucket you can access
         k = Key(s3_bucket)
         k.key = 'test.txt'
         k.set_contents_from_string('hello world i am a string')
 
-    with vcr.use_cassette(str(tmpdir.join('boto-hardcore.yml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('boto-hardcore.yml'))):
         s3_conn = S3Connection()
         s3_bucket = s3_conn.get_bucket('boto-demo-1394171994')  # a bucket you can access
         k = Key(s3_bucket)
@@ -68,10 +68,10 @@ def test_boto_iam(tmpdir):
     # Ensure that boto uses CertValidatingHTTPSConnection
     boto.config.set('Boto', 'https_validate_certificates', 'true')
 
-    with vcr.use_cassette(str(tmpdir.join('boto-iam.yml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('boto-iam.yml'))):
         iam_conn = boto.iam.connect_to_region('universal')
         iam_conn.get_all_users()
 
-    with vcr.use_cassette(str(tmpdir.join('boto-iam.yml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('boto-iam.yml'))):
         iam_conn = boto.iam.connect_to_region('universal')
         iam_conn.get_all_users()
index 45c3f78c3046e78d4df3bd0315757797c581786c..43f63ff50004a6f5a20b4840220bb37926281d3f 100644 (file)
@@ -78,9 +78,11 @@ def test_filter_json_post_data(tmpdir):
 def test_filter_callback(tmpdir):
     url = 'http://httpbin.org/get'
     cass_file = str(tmpdir.join('basic_auth_filter.yaml'))
+
     def before_record_cb(request):
         if request.path != '/get':
             return request
+
     # Test the legacy keyword.
     my_vcr = vcr.VCR(before_record=before_record_cb)
     with my_vcr.use_cassette(cass_file, filter_headers=['authorization']) as cass:
index f830a062551fe93785048e9d29923e7aae2d756c..eaa5d75f1de06074b048c650eba62552966dafa2 100644 (file)
@@ -24,11 +24,11 @@ def scheme(request):
 def test_response_code(scheme, tmpdir):
     '''Ensure we can read a response code from a fetch'''
     url = scheme + '://httpbin.org/'
-    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
         resp, _ = httplib2.Http().request(url)
         code = resp.status
 
-    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
         resp, _ = httplib2.Http().request(url)
         assert code == resp.status
 
@@ -36,11 +36,11 @@ def test_response_code(scheme, tmpdir):
 def test_random_body(scheme, tmpdir):
     '''Ensure we can read the content, and that it's served from cache'''
     url = scheme + '://httpbin.org/bytes/1024'
-    with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
         _, content = httplib2.Http().request(url)
         body = content
 
-    with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
         _, content = httplib2.Http().request(url)
         assert body == content
 
@@ -48,26 +48,28 @@ def test_random_body(scheme, tmpdir):
 def test_response_headers(scheme, tmpdir):
     '''Ensure we can get information from the response'''
     url = scheme + '://httpbin.org/'
-    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
         resp, _ = httplib2.Http().request(url)
         headers = resp.items()
 
-    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
         resp, _ = httplib2.Http().request(url)
         assert set(headers) == set(resp.items())
 
+
 def test_effective_url(scheme, tmpdir):
     '''Ensure that the effective_url is captured'''
     url = scheme + '://httpbin.org/redirect-to?url=/html'
-    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
         resp, _ = httplib2.Http().request(url)
         effective_url = resp['content-location']
         assert effective_url == scheme + '://httpbin.org/html'
 
-    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
         resp, _ = httplib2.Http().request(url)
         assert effective_url == resp['content-location']
 
+
 def test_multiple_requests(scheme, tmpdir):
     '''Ensure that we can cache multiple requests'''
     urls = [
@@ -85,10 +87,10 @@ def test_get_data(scheme, tmpdir):
     '''Ensure that it works with query data'''
     data = urlencode({'some': 1, 'data': 'here'})
     url = scheme + '://httpbin.org/get?' + data
-    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))):
         _, res1 = httplib2.Http().request(url)
 
-    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))):
         _, res2 = httplib2.Http().request(url)
 
     assert res1 == res2
@@ -98,7 +100,7 @@ def test_post_data(scheme, tmpdir):
     '''Ensure that it works when posting data'''
     data = urlencode({'some': 1, 'data': 'here'})
     url = scheme + '://httpbin.org/post'
-    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))):
         _, res1 = httplib2.Http().request(url, "POST", data)
 
     with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
@@ -112,7 +114,7 @@ def test_post_unicode_data(scheme, tmpdir):
     '''Ensure that it works when posting unicode data'''
     data = urlencode({'snowman': u'☃'.encode('utf-8')})
     url = scheme + '://httpbin.org/post'
-    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))):
         _, res1 = httplib2.Http().request(url, "POST", data)
 
     with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
index 9d0b0ae3308e1f9e573ee0a0de4f63e286fedc98..d32682fb4ce28d3393d96094b8cad2a067fe13e6 100644 (file)
@@ -1,7 +1,5 @@
-import base64
-import pytest
-from six.moves.urllib.request import urlopen, Request
-from six.moves.urllib.error import HTTPError
+from six.moves.urllib.request import urlopen
+
 import vcr
 
 
@@ -40,6 +38,7 @@ def test_ignore_localhost_and_httpbin(tmpdir, httpserver):
         urlopen(httpserver.url)
         assert len(cass) == 0
 
+
 def test_ignore_localhost_twice(tmpdir, httpserver):
     httpserver.serve_content('Hello!')
     cass_file = str(tmpdir.join('filter_qs.yaml'))
index 5ead41f099cee6997841b463dc24be986924533a..396bb40009bee5259d97d5f1fcee77838a668772 100644 (file)
@@ -37,7 +37,7 @@ def cassette(tmpdir):
     ('query',
      'https://google.com/get?p2=q2&p1=q1',
      'http://httpbin.org/get?p1=q1&a=b')
-    ])
+])
 def test_matchers(cassette, matcher, matching_uri, not_matching_uri):
     # play cassette with default uri
     with vcr.use_cassette(cassette, match_on=[matcher]) as cass:
index 3b0204e75274ba4343c5e77595cc8bc784c0d89a..5d9b603d656e375746c67c2b417c6e1eaae1c545 100644 (file)
@@ -1,4 +1,3 @@
-import os
 import pytest
 import vcr
 from six.moves.urllib.request import urlopen
@@ -8,39 +7,39 @@ def test_once_record_mode(tmpdir):
     testfile = str(tmpdir.join('recordmode.yml'))
     with vcr.use_cassette(testfile, record_mode="once"):
         # cassette file doesn't exist, so create.
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
-    with vcr.use_cassette(testfile, record_mode="once") as cass:
+    with vcr.use_cassette(testfile, record_mode="once"):
         # make the same request again
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
         # the first time, it's played from the cassette.
         # but, try to access something else from the same cassette, and an
         # exception is raised.
         with pytest.raises(Exception):
-            response = urlopen('http://httpbin.org/get').read()
+            urlopen('http://httpbin.org/get').read()
 
 
 def test_once_record_mode_two_times(tmpdir):
     testfile = str(tmpdir.join('recordmode.yml'))
     with vcr.use_cassette(testfile, record_mode="once"):
         # get two of the same file
-        response1 = urlopen('http://httpbin.org/').read()
-        response2 = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
-    with vcr.use_cassette(testfile, record_mode="once") as cass:
+    with vcr.use_cassette(testfile, record_mode="once"):
         # do it again
-        response = urlopen('http://httpbin.org/').read()
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
 
 def test_once_mode_three_times(tmpdir):
     testfile = str(tmpdir.join('recordmode.yml'))
     with vcr.use_cassette(testfile, record_mode="once"):
         # get three of the same file
-        response1 = urlopen('http://httpbin.org/').read()
-        response2 = urlopen('http://httpbin.org/').read()
-        response2 = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
 
 def test_new_episodes_record_mode(tmpdir):
@@ -48,18 +47,18 @@ def test_new_episodes_record_mode(tmpdir):
 
     with vcr.use_cassette(testfile, record_mode="new_episodes"):
         # cassette file doesn't exist, so create.
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
     with vcr.use_cassette(testfile, record_mode="new_episodes") as cass:
         # make the same request again
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
         # all responses have been played
         assert cass.all_played
 
         # in the "new_episodes" record mode, we can add more requests to
         # a cassette without repurcussions.
-        response = urlopen('http://httpbin.org/get').read()
+        urlopen('http://httpbin.org/get').read()
 
         # one of the responses has been played
         assert cass.play_count == 1
@@ -102,15 +101,15 @@ def test_all_record_mode(tmpdir):
 
     with vcr.use_cassette(testfile, record_mode="all"):
         # cassette file doesn't exist, so create.
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
     with vcr.use_cassette(testfile, record_mode="all") as cass:
         # make the same request again
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
         # in the "all" record mode, we can add more requests to
         # a cassette without repurcussions.
-        response = urlopen('http://httpbin.org/get').read()
+        urlopen('http://httpbin.org/get').read()
 
         # The cassette was never actually played, even though it existed.
         # that's because, in "all" mode, the requests all go directly to
@@ -124,7 +123,7 @@ def test_none_record_mode(tmpdir):
     testfile = str(tmpdir.join('recordmode.yml'))
     with vcr.use_cassette(testfile, record_mode="none"):
         with pytest.raises(Exception):
-            response = urlopen('http://httpbin.org/').read()
+            urlopen('http://httpbin.org/').read()
 
 
 def test_none_record_mode_with_existing_cassette(tmpdir):
@@ -132,12 +131,12 @@ def test_none_record_mode_with_existing_cassette(tmpdir):
     testfile = str(tmpdir.join('recordmode.yml'))
 
     with vcr.use_cassette(testfile, record_mode="all"):
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
 
     # play from cassette file
     with vcr.use_cassette(testfile, record_mode="none") as cass:
-        response = urlopen('http://httpbin.org/').read()
+        urlopen('http://httpbin.org/').read()
         assert cass.play_count == 1
         # but if I try to hit the net, raise an exception.
         with pytest.raises(Exception):
-            response = urlopen('http://httpbin.org/get').read()
+            urlopen('http://httpbin.org/get').read()
index ad1da1c10f80d4e8834f90c8223a2abfc5c8a656..ed83afd05ff3d2e972e09aa7b9b8ba8fc3866c3e 100644 (file)
@@ -14,12 +14,12 @@ def test_registered_true_matcher(tmpdir):
     my_vcr = vcr.VCR()
     my_vcr.register_matcher('true', true_matcher)
     testfile = str(tmpdir.join('test.yml'))
-    with my_vcr.use_cassette(testfile, match_on=['true']) as cass:
+    with my_vcr.use_cassette(testfile, match_on=['true']):
         # These 2 different urls are stored as the same request
         urlopen('http://httpbin.org/')
         urlopen('https://httpbin.org/get')
 
-    with my_vcr.use_cassette(testfile, match_on=['true']) as cass:
+    with my_vcr.use_cassette(testfile, match_on=['true']):
         # I can get the response twice even though I only asked for it once
         urlopen('http://httpbin.org/get')
         urlopen('https://httpbin.org/get')
index a7d15bc9e59f0093b6bf4aadb3fa7efaa9d3ef90..734f301ee2c56237ce7d3cad4d72316f1ca9b9a5 100644 (file)
@@ -10,7 +10,7 @@ class MockSerializer(object):
     def deserialize(self, cassette_string):
         self.serialize_count += 1
         self.cassette_string = cassette_string
-        return {'interactions':[]}
+        return {'interactions': []}
 
     def serialize(self, cassette_dict):
         self.deserialize_count += 1
index 674f6ed3786f4d456ceca989bec581e8021a394f..58ce5437dc65d5a7a8af7154409f2b2fb3a8a52b 100644 (file)
@@ -44,6 +44,7 @@ def test_body(tmpdir, scheme):
     with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
         assert content == requests.get(url).content
 
+
 def test_effective_url(scheme, tmpdir):
     '''Ensure that the effective_url is captured'''
     url = scheme + '://httpbin.org/redirect-to?url=/html'
@@ -54,6 +55,7 @@ def test_effective_url(scheme, tmpdir):
     with vcr.use_cassette(str(tmpdir.join('url.yaml'))):
         assert effective_url == requests.get(url).url
 
+
 def test_auth(tmpdir, scheme):
     '''Ensure that we can handle basic auth'''
     auth = ('user', 'passwd')
@@ -242,4 +244,3 @@ def test_filter_post_params(tmpdir, scheme):
         requests.post(url, data={'key': 'value'})
     with vcr.use_cassette(cass_loc, filter_post_data_parameters=['key']) as cass:
         assert b'key=value' not in cass.requests[0].body
-
index 15918d28882c40930d704546316daa26cd688ffb..2b069ea8ea47bcb959785c700d40ff889db68727 100644 (file)
@@ -1,6 +1,7 @@
 import vcr
 import six.moves.http_client as httplib
 
+
 def _headers_are_case_insensitive():
     conn = httplib.HTTPConnection('httpbin.org')
     conn.request('GET', "/cookies/set?k1=v1")
@@ -12,6 +13,7 @@ def _headers_are_case_insensitive():
     cookie_data2 = r2.getheader('Set-Cookie')
     return cookie_data1 == cookie_data2
 
+
 def test_case_insensitivity(tmpdir):
     testfile = str(tmpdir.join('case_insensitivity.yml'))
     # check if headers are case insensitive outside of vcrpy
@@ -25,12 +27,14 @@ def test_case_insensitivity(tmpdir):
     # behavior should be the same both inside and outside
     assert outside == inside == inside2
 
+
 def _multiple_header_value(httpserver):
     conn = httplib.HTTPConnection('%s:%s' % httpserver.server_address)
     conn.request('GET', "/")
     r = conn.getresponse()
     return r.getheader('foo')
 
+
 def test_multiple_headers(tmpdir, httpserver):
     testfile = str(tmpdir.join('multiple_headers.yaml'))
     httpserver.serve_content('Hello!', headers=[('foo', 'bar'), ('foo', 'baz')])
index b7d3c4edb0c76ca37f0835b00b801a95e2dfdade..ba23260c5ade636c05763a2fdb32bee32183e3e3 100644 (file)
@@ -81,6 +81,7 @@ def test_body(get_client, tmpdir, scheme):
         assert content == (yield get(get_client(), url)).body
         assert 1 == cass.play_count
 
+
 @pytest.mark.gen_test
 def test_effective_url(get_client, scheme, tmpdir):
     '''Ensure that the effective_url is captured'''
@@ -93,6 +94,7 @@ def test_effective_url(get_client, scheme, tmpdir):
         assert effective_url == (yield get(get_client(), url)).effective_url
         assert 1 == cass.play_count
 
+
 @pytest.mark.gen_test
 def test_auth(get_client, tmpdir, scheme):
     '''Ensure that we can handle basic auth'''
index 6754303d9f2a0d6eb4649a62f7444bcb7f291699..be1adc422d62569ced3f3f1b5ed332bea16cafa6 100644 (file)
@@ -22,43 +22,46 @@ def scheme(request):
 def test_response_code(scheme, tmpdir):
     '''Ensure we can read a response code from a fetch'''
     url = scheme + '://httpbin.org/'
-    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
         code = urlopen(url).getcode()
 
-    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
         assert code == urlopen(url).getcode()
 
 
 def test_random_body(scheme, tmpdir):
     '''Ensure we can read the content, and that it's served from cache'''
     url = scheme + '://httpbin.org/bytes/1024'
-    with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
         body = urlopen(url).read()
 
-    with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
         assert body == urlopen(url).read()
 
 
 def test_response_headers(scheme, tmpdir):
     '''Ensure we can get information from the response'''
     url = scheme + '://httpbin.org/'
-    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
         open1 = urlopen(url).info().items()
 
-    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
         open2 = urlopen(url).info().items()
+
         assert sorted(open1) == sorted(open2)
 
+
 def test_effective_url(scheme, tmpdir):
     '''Ensure that the effective_url is captured'''
     url = scheme + '://httpbin.org/redirect-to?url=/html'
-    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
         effective_url = urlopen(url).geturl()
         assert effective_url == scheme + '://httpbin.org/html'
 
-    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
         assert effective_url == urlopen(url).geturl()
 
+
 def test_multiple_requests(scheme, tmpdir):
     '''Ensure that we can cache multiple requests'''
     urls = [
@@ -76,10 +79,10 @@ def test_get_data(scheme, tmpdir):
     '''Ensure that it works with query data'''
     data = urlencode({'some': 1, 'data': 'here'})
     url = scheme + '://httpbin.org/get?' + data
-    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))):
         res1 = urlopen(url).read()
 
-    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))):
         res2 = urlopen(url).read()
 
     assert res1 == res2
@@ -89,11 +92,12 @@ def test_post_data(scheme, tmpdir):
     '''Ensure that it works when posting data'''
     data = urlencode({'some': 1, 'data': 'here'}).encode('utf-8')
     url = scheme + '://httpbin.org/post'
-    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))):
         res1 = urlopen(url, data).read()
 
     with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
         res2 = urlopen(url, data).read()
+        assert len(cass) == 1
 
     assert res1 == res2
     assert_cassette_has_one_response(cass)
@@ -103,10 +107,13 @@ def test_post_unicode_data(scheme, tmpdir):
     '''Ensure that it works when posting unicode data'''
     data = urlencode({'snowman': u'☃'.encode('utf-8')}).encode('utf-8')
     url = scheme + '://httpbin.org/post'
-    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
+    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))):
         res1 = urlopen(url, data).read()
+
     with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
         res2 = urlopen(url, data).read()
+        assert len(cass) == 1
+
     assert res1 == res2
     assert_cassette_has_one_response(cass)
 
@@ -122,6 +129,7 @@ def test_cross_scheme(tmpdir):
         assert len(cass) == 2
         assert cass.play_count == 0
 
+
 def test_decorator(scheme, tmpdir):
     '''Test the decorator version of VCR.py'''
     url = scheme + '://httpbin.org/'
index 694416f7f0da6eab249029a6f695b0ddd52ece47..2a3665c68b2ac2b248ac180e560b69509ffc390a 100644 (file)
@@ -20,7 +20,7 @@ def scheme(request):
 @pytest.fixture(scope='module')
 def verify_pool_mgr():
     return urllib3.PoolManager(
-        cert_reqs='CERT_REQUIRED', # Force certificate check.
+        cert_reqs='CERT_REQUIRED',  # Force certificate check.
         ca_certs=certifi.where()
     )
 
index 2d446fb1ae884ee7bda97942b5052f97849de0bb..47edc08f7b54e6e1b68d6fd788b64559e546538a 100644 (file)
@@ -42,6 +42,8 @@ def test_flickr_multipart_upload():
         data = r.read()
         h.close()
 
+        return data
+
     with vcr.use_cassette('fixtures/vcr_cassettes/flickr.yaml') as cass:
         _pretend_to_be_flickr_library()
         assert len(cass) == 1
@@ -63,7 +65,8 @@ def test_cookies(tmpdir):
     testfile = str(tmpdir.join('cookies.yml'))
     with vcr.use_cassette(testfile):
         s = requests.Session()
-        r1 = s.get("http://httpbin.org/cookies/set?k1=v1&k2=v2")
+        s.get("http://httpbin.org/cookies/set?k1=v1&k2=v2")
+
         r2 = s.get("http://httpbin.org/cookies")
         assert len(r2.json()['cookies']) == 2
 
@@ -81,9 +84,8 @@ def test_xmlrpclib(tmpdir):
         roundup_server = xmlrpc_client.ServerProxy('http://bugs.python.org/xmlrpc', allow_none=True)
         original_schema = roundup_server.schema()
 
-    with vcr.use_cassette(str(tmpdir.join('xmlrpcvideo.yaml'))) as cassette:
+    with vcr.use_cassette(str(tmpdir.join('xmlrpcvideo.yaml'))):
         roundup_server = xmlrpc_client.ServerProxy('http://bugs.python.org/xmlrpc', allow_none=True)
         second_schema = roundup_server.schema()
 
     assert original_schema == second_schema
-
index 413b154d5f2b6206a2c7080b2f2deec3e5058b3c..fc7fac0251ed52bfeddc83f05f413f696e59a783 100644 (file)
@@ -89,7 +89,7 @@ def make_get_request():
 def test_function_decorated_with_use_cassette_can_be_invoked_multiple_times(*args):
     decorated_function = Cassette.use(path='test')(make_get_request)
     for i in range(4):
-         decorated_function()
+        decorated_function()
 
 
 def test_arg_getter_functionality():
@@ -160,7 +160,7 @@ def test_nesting_cassette_context_managers(*args):
     with contextlib.ExitStack() as exit_stack:
         first_cassette = exit_stack.enter_context(Cassette.use(path='test'))
         exit_stack.enter_context(mock.patch.object(first_cassette, 'play_response',
-                                                    return_value=first_response))
+                                                   return_value=first_response))
         assert_get_response_body_is('first_response')
 
         # Make sure a second cassette can supercede the first
@@ -200,16 +200,17 @@ def test_custom_patchers():
                           custom_patches=((Test, 'attribute', VCRHTTPSConnection),)):
             assert issubclass(Test.attribute, VCRHTTPSConnection)
             assert VCRHTTPSConnection is not Test.attribute
-            assert  Test.attribute is not old_attribute
+            assert Test.attribute is not old_attribute
 
         assert issubclass(Test.attribute, VCRHTTPSConnection)
         assert VCRHTTPSConnection is not Test.attribute
-        assert  Test.attribute is old_attribute
+        assert Test.attribute is old_attribute
 
 
 def test_decorated_functions_are_reentrant():
     info = {"second": False}
     original_conn = httplib.HTTPConnection
+
     @Cassette.use(path='whatever', inject=True)
     def test_function(cassette):
         if info['second']:
@@ -219,6 +220,7 @@ def test_decorated_functions_are_reentrant():
             info['second'] = True
             test_function()
             assert httplib.HTTPConnection is info['first_conn']
+
     test_function()
     assert httplib.HTTPConnection is original_conn
 
@@ -232,9 +234,11 @@ def test_cassette_use_called_without_path_uses_function_to_generate_path():
 
 def test_path_transformer_with_function_path():
     path_transformer = lambda path: os.path.join('a', path)
+
     @Cassette.use(inject=True, path_transformer=path_transformer)
     def function_name(cassette):
         assert cassette._path == os.path.join('a', 'function_name')
+
     function_name()
 
 
@@ -255,15 +259,18 @@ def test_path_transformer_None():
 def test_func_path_generator():
     def generator(function):
         return os.path.join(os.path.dirname(inspect.getfile(function)),
-                                            function.__name__)
+                            function.__name__)
+
     @Cassette.use(inject=True, func_path_generator=generator)
     def function_name(cassette):
         assert cassette._path == os.path.join(os.path.dirname(__file__), 'function_name')
+
     function_name()
 
 
 def test_use_as_decorator_on_coroutine():
     original_http_connetion = httplib.HTTPConnection
+
     @Cassette.use(inject=True)
     def test_function(cassette):
         assert httplib.HTTPConnection.cassette is cassette
@@ -274,6 +281,7 @@ def test_use_as_decorator_on_coroutine():
         assert httplib.HTTPConnection is not original_http_connetion
         value = yield 2
         assert value == 2
+
     coroutine = test_function()
     value = next(coroutine)
     while True:
@@ -285,6 +293,7 @@ def test_use_as_decorator_on_coroutine():
 
 def test_use_as_decorator_on_generator():
     original_http_connetion = httplib.HTTPConnection
+
     @Cassette.use(inject=True)
     def test_function(cassette):
         assert httplib.HTTPConnection.cassette is cassette
@@ -293,4 +302,5 @@ def test_use_as_decorator_on_generator():
         assert httplib.HTTPConnection.cassette is cassette
         assert httplib.HTTPConnection is not original_http_connetion
         yield 2
+
     assert list(test_function()) == [1, 2]
index a89e15afa9ff422f3c55b6dd10a824f8e55790cb..dfd68d7e48dcd57c45a0ebbe8ceb14e0bbe6c78d 100644 (file)
@@ -29,9 +29,9 @@ def test_add_header_deprecated():
     ('https://go.com/', 443),
     ('https://go.com:443/', 443),
     ('https://go.com:3000/', 3000),
-    ])
+])
 def test_port(uri, expected_port):
-    req = Request('GET', uri,  '', {})
+    req = Request('GET', uri, '', {})
     assert req.port == expected_port
 
 
index 7e51450589bb8d0af91d507180fdc1e6648cdedb..a3b7cca13a227dede95677ec26a88898de8a324f 100644 (file)
@@ -1,6 +1,8 @@
 from vcr.stubs import VCRHTTPSConnection
 
+
 class TestVCRConnection(object):
+
     def test_setting_of_attributes_get_propogated_to_real_connection(self):
         vcr_connection = VCRHTTPSConnection('www.examplehost.com')
         vcr_connection.ssl_version = 'example_ssl_version'
diff --git a/tox.ini b/tox.ini
index 5e1a0dd656410c88ff1cb902647dcae2aea770e1..88bea53b4ce09994c4b5077c38b709987af20faa 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,15 +1,22 @@
 [tox]
-envlist = {py26,py27,py33,py34,pypy}-{requests27,requests26,requests25,requests24,requests23,requests22,requests1,httplib2,urllib317,urllib319,urllib3110,tornado,boto}
+envlist = py34-flakes,{py26,py27,py33,py34,pypy}-{requests27,requests26,requests25,requests24,requests23,requests22,requests1,httplib2,urllib317,urllib319,urllib3110,tornado,boto}
 
-[testenv]
+[testenv:py34-flakes]
+skipsdist = True
 commands =
-    py.test {posargs}
+    flake8 --exclude="./docs/conf.py"
+    pyflakes ./docs/conf.py
+deps = flake8
+
+[testenv]
 basepython =
     py26: python2.6
     py27: python2.7
     py33: python3.3
     py34: python3.4
     pypy: pypy
+commands =
+    py.test {posargs}
 deps =
     mock
     pytest
@@ -30,3 +37,6 @@ deps =
     {py26,py27,py33,py34,pypy}-tornado: pytest-tornado
     {py26,py27,py33,py34}-tornado: pycurl
     boto: boto
+
+[flake8]
+max_line_length = 110
index 57e7a02d45720694504984a747799f057066a2be..b54ed2fbea198dbea59c4f3f74334abec440df24 100644 (file)
@@ -67,7 +67,8 @@ def _identity(x):
 
 def _get_transformer(request):
     for checker, transformer in _checker_transformer_pairs:
-        if checker(request.headers): return transformer
+        if checker(request.headers):
+            return transformer
     else:
         return _identity
 
index 9e423f8d1f765f086506881d26e7b42da8c7d59e..6e30027757cb58ec18e682b26dfa1de6077feeb4 100644 (file)
@@ -19,7 +19,7 @@ import sys
 import tempfile
 import yaml
 
-from .serializers import compat, yamlserializer, jsonserializer
+from .serializers import yamlserializer, jsonserializer
 from .serialize import serialize
 from . import request
 from .stubs.compat import get_httpmessage
index 8400c68ddd2b3536062b6acb81496b4da3c709db..b4b5e0e3b14a9573587344be76b78c6664379a19 100644 (file)
@@ -59,7 +59,7 @@ except ImportError:  # pragma: no cover
     pass
 else:
     _SimpleAsyncHTTPClient_fetch_impl = \
-            tornado.simple_httpclient.SimpleAsyncHTTPClient.fetch_impl
+        tornado.simple_httpclient.SimpleAsyncHTTPClient.fetch_impl
 
 
 try:
@@ -68,7 +68,7 @@ except ImportError:  # pragma: no cover
     pass
 else:
     _CurlAsyncHTTPClient_fetch_impl = \
-            tornado.curl_httpclient.CurlAsyncHTTPClient.fetch_impl
+        tornado.curl_httpclient.CurlAsyncHTTPClient.fetch_impl
 
 
 class CassettePatcherBuilder(object):
@@ -127,13 +127,13 @@ class CassettePatcherBuilder(object):
         described in the previous paragraph.
         """
         if isinstance(replacement_dict_or_obj, dict):
-            for key, replacement_obj  in replacement_dict_or_obj.items():
+            for key, replacement_obj in replacement_dict_or_obj.items():
                 replacement_obj = self._recursively_apply_get_cassette_subclass(
                     replacement_obj)
                 replacement_dict_or_obj[key] = replacement_obj
             return replacement_dict_or_obj
         if hasattr(replacement_dict_or_obj, 'cassette'):
-            replacement_dict_or_obj =  self._get_cassette_subclass(
+            replacement_dict_or_obj = self._get_cassette_subclass(
                 replacement_dict_or_obj)
         return replacement_dict_or_obj
 
@@ -147,7 +147,7 @@ class CassettePatcherBuilder(object):
 
     def _build_cassette_subclass(self, base_class):
         bases = (base_class,)
-        if not issubclass(base_class, object): # Check for old style class
+        if not issubclass(base_class, object):  # Check for old style class
             bases += (object,)
         return type('{0}{1}'.format(base_class.__name__, self._cassette._path),
                     bases, dict(cassette=self._cassette))
@@ -167,11 +167,13 @@ class CassettePatcherBuilder(object):
 
     def _patched_get_conn(self, connection_pool_class, connection_class_getter):
         get_conn = connection_pool_class._get_conn
+
         @functools.wraps(get_conn)
         def patched_get_conn(pool, timeout=None):
             connection = get_conn(pool, timeout)
-            connection_class = pool.ConnectionCls if hasattr(pool, 'ConnectionCls') \
-                               else connection_class_getter()
+            connection_class = (
+                pool.ConnectionCls if hasattr(pool, 'ConnectionCls')
+                else connection_class_getter())
             # We need to make sure that we are actually providing a
             # patched version of the connection class. This might not
             # always be the case because the pool keeps previously
@@ -181,15 +183,18 @@ class CassettePatcherBuilder(object):
             while not isinstance(connection, connection_class):
                 connection = get_conn(pool, timeout)
             return connection
+
         return patched_get_conn
 
     def _patched_new_conn(self, connection_pool_class, connection_remover):
         new_conn = connection_pool_class._new_conn
+
         @functools.wraps(new_conn)
         def patched_new_conn(pool):
             new_connection = new_conn(pool)
             connection_remover.add_connection_to_pool_entry(pool, new_connection)
             return new_connection
+
         return patched_new_conn
 
     def _urllib3(self):
@@ -270,10 +275,10 @@ class CassettePatcherBuilder(object):
         # connections of the appropriate type.
         mock_triples += ((cpool.HTTPConnectionPool, '_get_conn',
                           self._patched_get_conn(cpool.HTTPConnectionPool,
-                                                 lambda : cpool.HTTPConnection)),
+                                                 lambda: cpool.HTTPConnection)),
                          (cpool.HTTPSConnectionPool, '_get_conn',
                           self._patched_get_conn(cpool.HTTPSConnectionPool,
-                                                 lambda : cpool.HTTPSConnection)),
+                                                 lambda: cpool.HTTPSConnection)),
                          (cpool.HTTPConnectionPool, '_new_conn',
                           self._patched_new_conn(cpool.HTTPConnectionPool,
                                                  http_connection_remover)),
@@ -382,7 +387,7 @@ def reset_patchers():
     else:
         yield mock.patch.object(
             curl.CurlAsyncHTTPClient,
-            'fetch_impl', 
+            'fetch_impl',
             _CurlAsyncHTTPClient_fetch_impl,
         )
 
index e140945f723d6b9858f55c76e95ba8389722d3ce..b3726587fa3454d4188632b12b58cd29545acb8d 100644 (file)
@@ -1,9 +1,5 @@
 '''Stubs for patching HTTP and HTTPS requests'''
 
-try:
-    import http.client
-except ImportError:
-    pass
 import logging
 import six
 from six.moves.http_client import (
@@ -329,8 +325,8 @@ class VCRConnection(object):
         try:
             setattr(self.real_connection, name, value)
         except AttributeError:
-             # raised if real_connection has not been set yet, such as when
-             # we're setting the real_connection itself for the first time
+            # raised if real_connection has not been set yet, such as when
+            # we're setting the real_connection itself for the first time
             pass
 
         super(VCRConnection, self).__setattr__(name, value)
index 30e960f7a2d43ab8f0ab1e9dcb5173714bd4dd0d..8cae533bd16b80b570b4af0fa63436bbbf95640e 100644 (file)
@@ -10,8 +10,10 @@ from ..stubs import VCRHTTPConnection, VCRHTTPSConnection
 # urllib3 defines its own HTTPConnection classes, which requests goes ahead and assumes
 # you're using.  It includes some polyfills for newer features missing in older pythons.
 
+
 class VCRRequestsHTTPConnection(VCRHTTPConnection, HTTPConnection):
     _baseclass = HTTPConnection
 
+
 class VCRRequestsHTTPSConnection(VCRHTTPSConnection, VerifiedHTTPSConnection):
     _baseclass = VerifiedHTTPSConnection
index 214884d72c1df9db6cda0fb63952a6ce958d3044..dff38d139663e2c71f3355f40ad49a19737bd605 100644 (file)
@@ -6,8 +6,10 @@ from ..stubs import VCRHTTPConnection, VCRHTTPSConnection
 # urllib3 defines its own HTTPConnection classes. It includes some polyfills
 # for newer features missing in older pythons.
 
+
 class VCRRequestsHTTPConnection(VCRHTTPConnection, HTTPConnection):
     _baseclass = HTTPConnection
 
+
 class VCRRequestsHTTPSConnection(VCRHTTPSConnection, VerifiedHTTPSConnection):
     _baseclass = VerifiedHTTPSConnection
index e1261970226a48f474740b1ee08239c02f7b701f..2e6effbc8211c5fe7794ff9f7bddd1e46bc1a581 100644 (file)
@@ -71,6 +71,7 @@ class CaseInsensitiveDict(collections.MutableMapping):
     def __repr__(self):
         return str(dict(self.items()))
 
+
 def partition_dict(predicate, dictionary):
     true_dict = {}
     false_dict = {}
@@ -89,6 +90,7 @@ def compose(*functions):
         return res
     return composed
 
+
 def read_body(request):
     if hasattr(request.body, 'read'):
         return request.body.read()