automated change using python-modernize: use 'as' in except
This commit is contained in:
parent
521398d5e7
commit
6caaa8a527
12 changed files with 32 additions and 32 deletions
|
|
@ -220,5 +220,5 @@ def main():
|
|||
"""Runs the testsuite as command line application."""
|
||||
try:
|
||||
unittest.main(testLoader=BetterLoader(), defaultTest='suite')
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print 'Error: %s' % e
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
def expect_exception(f, *args, **kwargs):
|
||||
try:
|
||||
f(*args, **kwargs)
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
self.assert_(e.args and 'session is unavailable' in e.args[0])
|
||||
else:
|
||||
self.assert_(False, 'expected exception')
|
||||
|
|
@ -629,7 +629,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
c = app.test_client()
|
||||
try:
|
||||
c.get('/fail')
|
||||
except KeyError, e:
|
||||
except KeyError as e:
|
||||
self.assert_(isinstance(e, BadRequest))
|
||||
else:
|
||||
self.fail('Expected exception')
|
||||
|
|
@ -645,7 +645,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
c = app.test_client()
|
||||
try:
|
||||
c.get('/fail')
|
||||
except NotFound, e:
|
||||
except NotFound as e:
|
||||
pass
|
||||
else:
|
||||
self.fail('Expected exception')
|
||||
|
|
@ -664,7 +664,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
with app.test_client() as c:
|
||||
try:
|
||||
c.post('/fail', data={'foo': 'index.txt'})
|
||||
except DebugFilesKeyError, e:
|
||||
except DebugFilesKeyError as e:
|
||||
self.assert_('no file contents were transmitted' in str(e))
|
||||
self.assert_('This was submitted: "index.txt"' in str(e))
|
||||
else:
|
||||
|
|
@ -755,7 +755,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
try:
|
||||
with app.test_request_context():
|
||||
flask.url_for('spam')
|
||||
except BuildError, error:
|
||||
except BuildError as error:
|
||||
pass
|
||||
try:
|
||||
raise RuntimeError('Test case where BuildError is not current.')
|
||||
|
|
@ -802,7 +802,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
return None
|
||||
try:
|
||||
app.test_client().get('/')
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
self.assert_equal(str(e), 'View function did not return a response')
|
||||
pass
|
||||
else:
|
||||
|
|
@ -843,7 +843,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
rv = app.test_client().get('/', 'https://localhost.localdomain')
|
||||
# Werkzeug 0.8
|
||||
self.assert_equal(rv.status_code, 404)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
# Werkzeug 0.7
|
||||
self.assert_equal(str(e), "the server name provided " +
|
||||
"('localhost.localdomain:443') does not match the " + \
|
||||
|
|
@ -854,7 +854,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
rv = app.test_client().get('/', 'http://foo.localhost')
|
||||
# Werkzeug 0.8
|
||||
self.assert_equal(rv.status_code, 404)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
# Werkzeug 0.7
|
||||
self.assert_equal(str(e), "the server name provided " + \
|
||||
"('localhost.localdomain') does not match the " + \
|
||||
|
|
@ -975,7 +975,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
@app.route('/foo')
|
||||
def broken():
|
||||
return 'Meh'
|
||||
except AssertionError, e:
|
||||
except AssertionError as e:
|
||||
self.assert_('A setup function was called' in str(e))
|
||||
else:
|
||||
self.fail('Expected exception')
|
||||
|
|
@ -1009,7 +1009,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
with app.test_client() as c:
|
||||
try:
|
||||
c.post('/foo', data={})
|
||||
except AssertionError, e:
|
||||
except AssertionError as e:
|
||||
self.assert_('http://localhost/foo/' in str(e))
|
||||
self.assert_('Make sure to directly send your POST-request '
|
||||
'to this URL' in str(e))
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ class ModuleTestCase(FlaskTestCase):
|
|||
with app.test_request_context():
|
||||
try:
|
||||
flask.render_template('missing.html')
|
||||
except TemplateNotFound, e:
|
||||
except TemplateNotFound as e:
|
||||
self.assert_equal(e.name, 'missing.html')
|
||||
else:
|
||||
self.assert_(0, 'expected exception')
|
||||
|
|
@ -378,7 +378,7 @@ class BlueprintTestCase(FlaskTestCase):
|
|||
with app.test_request_context():
|
||||
try:
|
||||
flask.render_template('missing.html')
|
||||
except TemplateNotFound, e:
|
||||
except TemplateNotFound as e:
|
||||
self.assert_equal(e.name, 'missing.html')
|
||||
else:
|
||||
self.assert_(0, 'expected exception')
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class ConfigTestCase(FlaskTestCase):
|
|||
app = flask.Flask(__name__)
|
||||
try:
|
||||
app.config.from_envvar('FOO_SETTINGS')
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
self.assert_("'FOO_SETTINGS' is not set" in str(e))
|
||||
else:
|
||||
self.assert_(0, 'expected exception')
|
||||
|
|
@ -76,7 +76,7 @@ class ConfigTestCase(FlaskTestCase):
|
|||
try:
|
||||
app = flask.Flask(__name__)
|
||||
app.config.from_envvar('FOO_SETTINGS')
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
msg = str(e)
|
||||
self.assert_(msg.startswith('[Errno 2] Unable to load configuration '
|
||||
'file (No such file or directory):'))
|
||||
|
|
@ -91,7 +91,7 @@ class ConfigTestCase(FlaskTestCase):
|
|||
app = flask.Flask(__name__)
|
||||
try:
|
||||
app.config.from_pyfile('missing.cfg')
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
msg = str(e)
|
||||
self.assert_(msg.startswith('[Errno 2] Unable to load configuration '
|
||||
'file (No such file or directory):'))
|
||||
|
|
@ -141,7 +141,7 @@ class InstanceTestCase(FlaskTestCase):
|
|||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
try:
|
||||
flask.Flask(__name__, instance_path='instance')
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
self.assert_('must be absolute' in str(e))
|
||||
else:
|
||||
self.fail('Expected value error')
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class RequestContextTestCase(FlaskTestCase):
|
|||
try:
|
||||
with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.assert_(isinstance(e, ValueError))
|
||||
self.assert_equal(str(e), "the server name provided " +
|
||||
"('localhost.localdomain:5000') does not match the " + \
|
||||
|
|
@ -68,7 +68,7 @@ class RequestContextTestCase(FlaskTestCase):
|
|||
app.config.update(SERVER_NAME='localhost')
|
||||
with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost'}):
|
||||
pass
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise ValueError(
|
||||
"No ValueError exception should have been raised \"%s\"" % e
|
||||
)
|
||||
|
|
@ -77,7 +77,7 @@ class RequestContextTestCase(FlaskTestCase):
|
|||
app.config.update(SERVER_NAME='localhost:80')
|
||||
with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost:80'}):
|
||||
pass
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise ValueError(
|
||||
"No ValueError exception should have been raised \"%s\"" % e
|
||||
)
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class TestToolsTestCase(FlaskTestCase):
|
|||
try:
|
||||
with c.session_transaction() as sess:
|
||||
pass
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
self.assert_('Session backend did not open a session' in str(e))
|
||||
else:
|
||||
self.fail('Expected runtime error')
|
||||
|
|
@ -130,7 +130,7 @@ class TestToolsTestCase(FlaskTestCase):
|
|||
try:
|
||||
with c.session_transaction() as s:
|
||||
pass
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
self.assert_('cookies' in str(e))
|
||||
else:
|
||||
self.fail('Expected runtime error')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue