1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 09:35:34 +00:00

Automatic formatters supported in Python 2.7+

This commit is contained in:
Hugo
2017-12-07 13:32:08 +02:00
parent 87666ba2e4
commit 6156271c48
9 changed files with 28 additions and 28 deletions

View File

@@ -26,9 +26,9 @@ def test_ignore_localhost(tmpdir, httpbin):
with overridden_dns({'httpbin.org': '127.0.0.1'}): with overridden_dns({'httpbin.org': '127.0.0.1'}):
cass_file = str(tmpdir.join('filter_qs.yaml')) cass_file = str(tmpdir.join('filter_qs.yaml'))
with vcr.use_cassette(cass_file, ignore_localhost=True) as cass: 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 assert len(cass) == 0
urlopen('http://httpbin.org:{0}/'.format(httpbin.port)) urlopen('http://httpbin.org:{}/'.format(httpbin.port))
assert len(cass) == 1 assert len(cass) == 1
@@ -39,9 +39,9 @@ def test_ignore_httpbin(tmpdir, httpbin):
cass_file, cass_file,
ignore_hosts=['httpbin.org'] ignore_hosts=['httpbin.org']
) as cass: ) as cass:
urlopen('http://httpbin.org:{0}/'.format(httpbin.port)) urlopen('http://httpbin.org:{}/'.format(httpbin.port))
assert len(cass) == 0 assert len(cass) == 0
urlopen('http://localhost:{0}/'.format(httpbin.port)) urlopen('http://localhost:{}/'.format(httpbin.port))
assert len(cass) == 1 assert len(cass) == 1
@@ -53,8 +53,8 @@ def test_ignore_localhost_and_httpbin(tmpdir, httpbin):
ignore_hosts=['httpbin.org'], ignore_hosts=['httpbin.org'],
ignore_localhost=True ignore_localhost=True
) as cass: ) as cass:
urlopen('http://httpbin.org:{0}'.format(httpbin.port)) urlopen('http://httpbin.org:{}'.format(httpbin.port))
urlopen('http://localhost:{0}'.format(httpbin.port)) urlopen('http://localhost:{}'.format(httpbin.port))
assert len(cass) == 0 assert len(cass) == 0
@@ -62,12 +62,12 @@ def test_ignore_localhost_twice(tmpdir, httpbin):
with overridden_dns({'httpbin.org': '127.0.0.1'}): with overridden_dns({'httpbin.org': '127.0.0.1'}):
cass_file = str(tmpdir.join('filter_qs.yaml')) cass_file = str(tmpdir.join('filter_qs.yaml'))
with vcr.use_cassette(cass_file, ignore_localhost=True) as cass: 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 assert len(cass) == 0
urlopen('http://httpbin.org:{0}'.format(httpbin.port)) urlopen('http://httpbin.org:{}'.format(httpbin.port))
assert len(cass) == 1 assert len(cass) == 1
with vcr.use_cassette(cass_file, ignore_localhost=True) as cass: with vcr.use_cassette(cass_file, ignore_localhost=True) as cass:
assert len(cass) == 1 assert len(cass) == 1
urlopen('http://localhost:{0}'.format(httpbin.port)) urlopen('http://localhost:{}'.format(httpbin.port))
urlopen('http://httpbin.org:{0}'.format(httpbin.port)) urlopen('http://httpbin.org:{}'.format(httpbin.port))
assert len(cass) == 1 assert len(cass) == 1

View File

@@ -56,7 +56,7 @@ def test_body(tmpdir, httpbin_both, verify_pool_mgr):
def test_auth(tmpdir, httpbin_both, verify_pool_mgr): def test_auth(tmpdir, httpbin_both, verify_pool_mgr):
'''Ensure that we can handle basic auth''' '''Ensure that we can handle basic auth'''
auth = ('user', 'passwd') 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' url = httpbin_both.url + '/basic-auth/user/passwd'
with vcr.use_cassette(str(tmpdir.join('auth.yaml'))): with vcr.use_cassette(str(tmpdir.join('auth.yaml'))):
one = verify_pool_mgr.request('GET', url, headers=headers) 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): def test_auth_failed(tmpdir, httpbin_both, verify_pool_mgr):
'''Ensure that we can save failed auth statuses''' '''Ensure that we can save failed auth statuses'''
auth = ('user', 'wrongwrongwrong') 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' url = httpbin_both.url + '/basic-auth/user/passwd'
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass: with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
# Ensure that this is empty to begin with # Ensure that this is empty to begin with

View File

@@ -304,7 +304,7 @@ class Cassette(object):
pass pass
def __str__(self): def __str__(self):
return "<Cassette containing {0} recorded response(s)>".format( return "<Cassette containing {} recorded response(s)>".format(
len(self) len(self)
) )

View File

@@ -78,7 +78,7 @@ class VCR(object):
serializer = self.serializers[serializer_name] serializer = self.serializers[serializer_name]
except KeyError: except KeyError:
raise KeyError( raise KeyError(
"Serializer {0} doesn't exist or isn't registered".format( "Serializer {} doesn't exist or isn't registered".format(
serializer_name serializer_name
) )
) )
@@ -91,7 +91,7 @@ class VCR(object):
matchers.append(self.matchers[m]) matchers.append(self.matchers[m])
except KeyError: except KeyError:
raise 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 return matchers

View File

@@ -90,8 +90,8 @@ def _log_matches(r1, r2, matches):
differences = [m for m in matches if not m[0]] differences = [m for m in matches if not m[0]]
if differences: if differences:
log.debug( log.debug(
"Requests {0} and {1} differ according to " "Requests {} and {} differ according to "
"the following matchers: {2}".format(r1, r2, differences) "the following matchers: {}".format(r1, r2, differences)
) )

View File

@@ -59,7 +59,7 @@ def build_uri(**parts):
port = parts['port'] port = parts['port']
scheme = parts['protocol'] scheme = parts['protocol']
default_port = {'https': 443, 'http': 80}[scheme] 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) return "{protocol}://{host}{port}{path}".format(**parts)
@@ -161,7 +161,7 @@ def main():
for file_path in files: for file_path in files:
migrated = try_migrate(file_path) migrated = try_migrate(file_path)
status = 'OK' if migrated else 'FAIL' 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") sys.stderr.write("Done.\n")

View File

@@ -169,7 +169,7 @@ class CassettePatcherBuilder(object):
bases = (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,) 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)) bases, dict(cassette=self._cassette))
@_build_patchers_from_mock_triples_decorator @_build_patchers_from_mock_triples_decorator

View File

@@ -81,7 +81,7 @@ class Request(object):
return self.scheme return self.scheme
def __str__(self): def __str__(self):
return "<Request ({0}) {1}>".format(self.method, self.uri) return "<Request ({}) {}>".format(self.method, self.uri)
def __repr__(self): def __repr__(self):
return self.__str__() return self.__str__()

View File

@@ -132,11 +132,11 @@ class VCRConnection(object):
""" """
port = self.real_connection.port port = self.real_connection.port
default_port = {'https': 443, 'http': 80}[self._protocol] 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): def _uri(self, url):
"""Returns request absolute URI""" """Returns request absolute URI"""
uri = "{0}://{1}{2}{3}".format( uri = "{}://{}{}{}".format(
self._protocol, self._protocol,
self.real_connection.host, self.real_connection.host,
self._port_postfix(), self._port_postfix(),
@@ -146,7 +146,7 @@ class VCRConnection(object):
def _url(self, uri): def _url(self, uri):
"""Returns request selector url from absolute URI""" """Returns request selector url from absolute URI"""
prefix = "{0}://{1}{2}".format( prefix = "{}://{}{}".format(
self._protocol, self._protocol,
self.real_connection.host, self.real_connection.host,
self._port_postfix(), self._port_postfix(),
@@ -161,7 +161,7 @@ class VCRConnection(object):
body=body, body=body,
headers=headers or {} 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 # Note: The request may not actually be finished at this point, so
# I'm not sending the actual request until getresponse(). This # I'm not sending the actual request until getresponse(). This
@@ -180,7 +180,7 @@ class VCRConnection(object):
body="", body="",
headers={} headers={}
) )
log.debug('Got {0}'.format(self._vcr_request)) log.debug('Got {}'.format(self._vcr_request))
def putheader(self, header, *values): def putheader(self, header, *values):
self._vcr_request.headers[header] = values self._vcr_request.headers[header] = values
@@ -214,7 +214,7 @@ class VCRConnection(object):
# then return it # then return it
if self.cassette.can_play_response_for(self._vcr_request): if self.cassette.can_play_response_for(self._vcr_request):
log.info( log.info(
"Playing response for {0} from cassette".format( "Playing response for {} from cassette".format(
self._vcr_request self._vcr_request
) )
) )
@@ -236,7 +236,7 @@ class VCRConnection(object):
# and return it. # and return it.
log.info( log.info(
"{0} not in cassette, sending to real server".format( "{} not in cassette, sending to real server".format(
self._vcr_request self._vcr_request
) )
) )