mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Automatic formatters supported in Python 2.7+
This commit is contained in:
@@ -26,9 +26,9 @@ def test_ignore_localhost(tmpdir, httpbin):
|
||||
with overridden_dns({'httpbin.org': '127.0.0.1'}):
|
||||
cass_file = str(tmpdir.join('filter_qs.yaml'))
|
||||
with vcr.use_cassette(cass_file, ignore_localhost=True) as cass:
|
||||
urlopen('http://localhost:{0}/'.format(httpbin.port))
|
||||
urlopen('http://localhost:{}/'.format(httpbin.port))
|
||||
assert len(cass) == 0
|
||||
urlopen('http://httpbin.org:{0}/'.format(httpbin.port))
|
||||
urlopen('http://httpbin.org:{}/'.format(httpbin.port))
|
||||
assert len(cass) == 1
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ def test_ignore_httpbin(tmpdir, httpbin):
|
||||
cass_file,
|
||||
ignore_hosts=['httpbin.org']
|
||||
) as cass:
|
||||
urlopen('http://httpbin.org:{0}/'.format(httpbin.port))
|
||||
urlopen('http://httpbin.org:{}/'.format(httpbin.port))
|
||||
assert len(cass) == 0
|
||||
urlopen('http://localhost:{0}/'.format(httpbin.port))
|
||||
urlopen('http://localhost:{}/'.format(httpbin.port))
|
||||
assert len(cass) == 1
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ def test_ignore_localhost_and_httpbin(tmpdir, httpbin):
|
||||
ignore_hosts=['httpbin.org'],
|
||||
ignore_localhost=True
|
||||
) as cass:
|
||||
urlopen('http://httpbin.org:{0}'.format(httpbin.port))
|
||||
urlopen('http://localhost:{0}'.format(httpbin.port))
|
||||
urlopen('http://httpbin.org:{}'.format(httpbin.port))
|
||||
urlopen('http://localhost:{}'.format(httpbin.port))
|
||||
assert len(cass) == 0
|
||||
|
||||
|
||||
@@ -62,12 +62,12 @@ def test_ignore_localhost_twice(tmpdir, httpbin):
|
||||
with overridden_dns({'httpbin.org': '127.0.0.1'}):
|
||||
cass_file = str(tmpdir.join('filter_qs.yaml'))
|
||||
with vcr.use_cassette(cass_file, ignore_localhost=True) as cass:
|
||||
urlopen('http://localhost:{0}'.format(httpbin.port))
|
||||
urlopen('http://localhost:{}'.format(httpbin.port))
|
||||
assert len(cass) == 0
|
||||
urlopen('http://httpbin.org:{0}'.format(httpbin.port))
|
||||
urlopen('http://httpbin.org:{}'.format(httpbin.port))
|
||||
assert len(cass) == 1
|
||||
with vcr.use_cassette(cass_file, ignore_localhost=True) as cass:
|
||||
assert len(cass) == 1
|
||||
urlopen('http://localhost:{0}'.format(httpbin.port))
|
||||
urlopen('http://httpbin.org:{0}'.format(httpbin.port))
|
||||
urlopen('http://localhost:{}'.format(httpbin.port))
|
||||
urlopen('http://httpbin.org:{}'.format(httpbin.port))
|
||||
assert len(cass) == 1
|
||||
|
||||
@@ -56,7 +56,7 @@ def test_body(tmpdir, httpbin_both, verify_pool_mgr):
|
||||
def test_auth(tmpdir, httpbin_both, verify_pool_mgr):
|
||||
'''Ensure that we can handle basic auth'''
|
||||
auth = ('user', 'passwd')
|
||||
headers = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(*auth))
|
||||
headers = urllib3.util.make_headers(basic_auth='{}:{}'.format(*auth))
|
||||
url = httpbin_both.url + '/basic-auth/user/passwd'
|
||||
with vcr.use_cassette(str(tmpdir.join('auth.yaml'))):
|
||||
one = verify_pool_mgr.request('GET', url, headers=headers)
|
||||
@@ -70,7 +70,7 @@ def test_auth(tmpdir, httpbin_both, verify_pool_mgr):
|
||||
def test_auth_failed(tmpdir, httpbin_both, verify_pool_mgr):
|
||||
'''Ensure that we can save failed auth statuses'''
|
||||
auth = ('user', 'wrongwrongwrong')
|
||||
headers = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(*auth))
|
||||
headers = urllib3.util.make_headers(basic_auth='{}:{}'.format(*auth))
|
||||
url = httpbin_both.url + '/basic-auth/user/passwd'
|
||||
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
|
||||
# Ensure that this is empty to begin with
|
||||
|
||||
@@ -304,7 +304,7 @@ class Cassette(object):
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
return "<Cassette containing {0} recorded response(s)>".format(
|
||||
return "<Cassette containing {} recorded response(s)>".format(
|
||||
len(self)
|
||||
)
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class VCR(object):
|
||||
serializer = self.serializers[serializer_name]
|
||||
except KeyError:
|
||||
raise KeyError(
|
||||
"Serializer {0} doesn't exist or isn't registered".format(
|
||||
"Serializer {} doesn't exist or isn't registered".format(
|
||||
serializer_name
|
||||
)
|
||||
)
|
||||
@@ -91,7 +91,7 @@ class VCR(object):
|
||||
matchers.append(self.matchers[m])
|
||||
except KeyError:
|
||||
raise KeyError(
|
||||
"Matcher {0} doesn't exist or isn't registered".format(m)
|
||||
"Matcher {} doesn't exist or isn't registered".format(m)
|
||||
)
|
||||
return matchers
|
||||
|
||||
|
||||
@@ -90,8 +90,8 @@ def _log_matches(r1, r2, matches):
|
||||
differences = [m for m in matches if not m[0]]
|
||||
if differences:
|
||||
log.debug(
|
||||
"Requests {0} and {1} differ according to "
|
||||
"the following matchers: {2}".format(r1, r2, differences)
|
||||
"Requests {} and {} differ according to "
|
||||
"the following matchers: {}".format(r1, r2, differences)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ def build_uri(**parts):
|
||||
port = parts['port']
|
||||
scheme = parts['protocol']
|
||||
default_port = {'https': 443, 'http': 80}[scheme]
|
||||
parts['port'] = ':{0}'.format(port) if port != default_port else ''
|
||||
parts['port'] = ':{}'.format(port) if port != default_port else ''
|
||||
return "{protocol}://{host}{port}{path}".format(**parts)
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ def main():
|
||||
for file_path in files:
|
||||
migrated = try_migrate(file_path)
|
||||
status = 'OK' if migrated else 'FAIL'
|
||||
sys.stderr.write("[{0}] {1}\n".format(status, file_path))
|
||||
sys.stderr.write("[{}] {}\n".format(status, file_path))
|
||||
sys.stderr.write("Done.\n")
|
||||
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ class CassettePatcherBuilder(object):
|
||||
bases = (base_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),
|
||||
return type('{}{}'.format(base_class.__name__, self._cassette._path),
|
||||
bases, dict(cassette=self._cassette))
|
||||
|
||||
@_build_patchers_from_mock_triples_decorator
|
||||
|
||||
@@ -81,7 +81,7 @@ class Request(object):
|
||||
return self.scheme
|
||||
|
||||
def __str__(self):
|
||||
return "<Request ({0}) {1}>".format(self.method, self.uri)
|
||||
return "<Request ({}) {}>".format(self.method, self.uri)
|
||||
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
|
||||
@@ -132,11 +132,11 @@ class VCRConnection(object):
|
||||
"""
|
||||
port = self.real_connection.port
|
||||
default_port = {'https': 443, 'http': 80}[self._protocol]
|
||||
return ':{0}'.format(port) if port != default_port else ''
|
||||
return ':{}'.format(port) if port != default_port else ''
|
||||
|
||||
def _uri(self, url):
|
||||
"""Returns request absolute URI"""
|
||||
uri = "{0}://{1}{2}{3}".format(
|
||||
uri = "{}://{}{}{}".format(
|
||||
self._protocol,
|
||||
self.real_connection.host,
|
||||
self._port_postfix(),
|
||||
@@ -146,7 +146,7 @@ class VCRConnection(object):
|
||||
|
||||
def _url(self, uri):
|
||||
"""Returns request selector url from absolute URI"""
|
||||
prefix = "{0}://{1}{2}".format(
|
||||
prefix = "{}://{}{}".format(
|
||||
self._protocol,
|
||||
self.real_connection.host,
|
||||
self._port_postfix(),
|
||||
@@ -161,7 +161,7 @@ class VCRConnection(object):
|
||||
body=body,
|
||||
headers=headers or {}
|
||||
)
|
||||
log.debug('Got {0}'.format(self._vcr_request))
|
||||
log.debug('Got {}'.format(self._vcr_request))
|
||||
|
||||
# Note: The request may not actually be finished at this point, so
|
||||
# I'm not sending the actual request until getresponse(). This
|
||||
@@ -180,7 +180,7 @@ class VCRConnection(object):
|
||||
body="",
|
||||
headers={}
|
||||
)
|
||||
log.debug('Got {0}'.format(self._vcr_request))
|
||||
log.debug('Got {}'.format(self._vcr_request))
|
||||
|
||||
def putheader(self, header, *values):
|
||||
self._vcr_request.headers[header] = values
|
||||
@@ -214,7 +214,7 @@ class VCRConnection(object):
|
||||
# then return it
|
||||
if self.cassette.can_play_response_for(self._vcr_request):
|
||||
log.info(
|
||||
"Playing response for {0} from cassette".format(
|
||||
"Playing response for {} from cassette".format(
|
||||
self._vcr_request
|
||||
)
|
||||
)
|
||||
@@ -236,7 +236,7 @@ class VCRConnection(object):
|
||||
# and return it.
|
||||
|
||||
log.info(
|
||||
"{0} not in cassette, sending to real server".format(
|
||||
"{} not in cassette, sending to real server".format(
|
||||
self._vcr_request
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user