Browse Source

Changed assert to self.assert_ where it was still in place

pull/309/head
Armin Ronacher 14 years ago
parent
commit
fc2caa4b9c
  1. 80
      flask/testsuite/basic.py
  2. 18
      flask/testsuite/blueprints.py
  3. 20
      flask/testsuite/config.py
  4. 2
      flask/testsuite/deprecations.py
  5. 34
      flask/testsuite/helpers.py
  6. 2
      flask/testsuite/signals.py
  7. 12
      flask/testsuite/templating.py
  8. 4
      flask/testsuite/testing.py

80
flask/testsuite/basic.py

@ -73,7 +73,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])
rv = c.head('/') rv = c.head('/')
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
assert not rv.data # head truncates self.assert_(not rv.data) # head truncates
self.assert_equal(c.post('/more').data, 'POST') self.assert_equal(c.post('/more').data, 'POST')
self.assert_equal(c.get('/more').data, 'GET') self.assert_equal(c.get('/more').data, 'GET')
rv = c.delete('/more') rv = c.delete('/more')
@ -97,7 +97,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])
rv = c.head('/') rv = c.head('/')
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
assert not rv.data # head truncates self.assert_(not rv.data) # head truncates
self.assert_equal(c.post('/more').data, 'POST') self.assert_equal(c.post('/more').data, 'POST')
self.assert_equal(c.get('/more').data, 'GET') self.assert_equal(c.get('/more').data, 'GET')
rv = c.delete('/more') rv = c.delete('/more')
@ -168,8 +168,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
flask.session['testing'] = 42 flask.session['testing'] = 42
return 'Hello World' return 'Hello World'
rv = app.test_client().get('/', 'http://example.com/') rv = app.test_client().get('/', 'http://example.com/')
assert 'domain=.example.com' in rv.headers['set-cookie'].lower() self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())
assert 'httponly' in rv.headers['set-cookie'].lower() self.assert_('httponly' in rv.headers['set-cookie'].lower())
def test_session_using_server_name_and_port(self): def test_session_using_server_name_and_port(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@ -182,8 +182,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
flask.session['testing'] = 42 flask.session['testing'] = 42
return 'Hello World' return 'Hello World'
rv = app.test_client().get('/', 'http://example.com:8080/') rv = app.test_client().get('/', 'http://example.com:8080/')
assert 'domain=.example.com' in rv.headers['set-cookie'].lower() self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())
assert 'httponly' in rv.headers['set-cookie'].lower() self.assert_('httponly' in rv.headers['set-cookie'].lower())
def test_session_using_application_root(self): def test_session_using_application_root(self):
class PrefixPathMiddleware(object): class PrefixPathMiddleware(object):
@ -205,7 +205,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
flask.session['testing'] = 42 flask.session['testing'] = 42
return 'Hello World' return 'Hello World'
rv = app.test_client().get('/', 'http://example.com:8080/') rv = app.test_client().get('/', 'http://example.com:8080/')
assert 'path=/bar' in rv.headers['set-cookie'].lower() self.assert_('path=/bar' in rv.headers['set-cookie'].lower())
def test_missing_session(self): def test_missing_session(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@ -213,11 +213,11 @@ class BasicFunctionalityTestCase(FlaskTestCase):
try: try:
f(*args, **kwargs) f(*args, **kwargs)
except RuntimeError, e: except RuntimeError, e:
assert e.args and 'session is unavailable' in e.args[0] self.assert_(e.args and 'session is unavailable' in e.args[0])
else: else:
assert False, 'expected exception' self.assert_(False, 'expected exception')
with app.test_request_context(): with app.test_request_context():
assert flask.session.get('missing_key') is None self.assert_(flask.session.get('missing_key') is None)
expect_exception(flask.session.__setitem__, 'foo', 42) expect_exception(flask.session.__setitem__, 'foo', 42)
expect_exception(flask.session.pop, 'foo') expect_exception(flask.session.pop, 'foo')
@ -237,7 +237,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
client = app.test_client() client = app.test_client()
rv = client.get('/') rv = client.get('/')
assert 'set-cookie' in rv.headers self.assert_('set-cookie' in rv.headers)
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie']) match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
expires = parse_date(match.group()) expires = parse_date(match.group())
expected = datetime.utcnow() + app.permanent_session_lifetime expected = datetime.utcnow() + app.permanent_session_lifetime
@ -250,20 +250,20 @@ class BasicFunctionalityTestCase(FlaskTestCase):
permanent = False permanent = False
rv = app.test_client().get('/') rv = app.test_client().get('/')
assert 'set-cookie' in rv.headers self.assert_('set-cookie' in rv.headers)
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie']) match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
assert match is None self.assert_(match is None)
def test_flashes(self): def test_flashes(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.secret_key = 'testkey' app.secret_key = 'testkey'
with app.test_request_context(): with app.test_request_context():
assert not flask.session.modified self.assert_(not flask.session.modified)
flask.flash('Zap') flask.flash('Zap')
flask.session.modified = False flask.session.modified = False
flask.flash('Zip') flask.flash('Zip')
assert flask.session.modified self.assert_(flask.session.modified)
self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
def test_extended_flashing(self): def test_extended_flashing(self):
@ -308,12 +308,12 @@ class BasicFunctionalityTestCase(FlaskTestCase):
return response return response
@app.route('/') @app.route('/')
def index(): def index():
assert 'before' in evts self.assert_('before' in evts)
assert 'after' not in evts self.assert_('after' not in evts)
return 'request' return 'request'
assert 'after' not in evts self.assert_('after' not in evts)
rv = app.test_client().get('/').data rv = app.test_client().get('/').data
assert 'after' in evts self.assert_('after' in evts)
self.assert_equal(rv, 'request|after') self.assert_equal(rv, 'request|after')
def test_teardown_request_handler(self): def test_teardown_request_handler(self):
@ -328,7 +328,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
return "Response" return "Response"
rv = app.test_client().get('/') rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
assert 'Response' in rv.data self.assert_('Response' in rv.data)
self.assert_equal(len(called), 1) self.assert_equal(len(called), 1)
def test_teardown_request_handler_debug_mode(self): def test_teardown_request_handler_debug_mode(self):
@ -344,7 +344,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
return "Response" return "Response"
rv = app.test_client().get('/') rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
assert 'Response' in rv.data self.assert_('Response' in rv.data)
self.assert_equal(len(called), 1) self.assert_equal(len(called), 1)
def test_teardown_request_handler_error(self): def test_teardown_request_handler_error(self):
@ -377,7 +377,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
1/0 1/0
rv = app.test_client().get('/') rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 500) self.assert_equal(rv.status_code, 500)
assert 'Internal Server Error' in rv.data self.assert_('Internal Server Error' in rv.data)
self.assert_equal(len(called), 2) self.assert_equal(len(called), 2)
def test_before_after_request_order(self): def test_before_after_request_order(self):
@ -451,7 +451,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@app.errorhandler(MyException) @app.errorhandler(MyException)
def handle_my_exception(e): def handle_my_exception(e):
assert isinstance(e, MyException) self.assert_(isinstance(e, MyException))
return '42' return '42'
@app.route('/') @app.route('/')
def index(): def index():
@ -474,7 +474,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
try: try:
c.get('/fail') c.get('/fail')
except KeyError, e: except KeyError, e:
assert isinstance(e, BadRequest) self.assert_(isinstance(e, BadRequest))
else: else:
self.fail('Expected exception') self.fail('Expected exception')
@ -509,8 +509,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
try: try:
c.post('/fail', data={'foo': 'index.txt'}) c.post('/fail', data={'foo': 'index.txt'})
except DebugFilesKeyError, e: except DebugFilesKeyError, e:
assert 'no file contents were transmitted' in str(e) self.assert_('no file contents were transmitted' in str(e))
assert 'This was submitted: "index.txt"' in str(e) self.assert_('This was submitted: "index.txt"' in str(e))
else: else:
self.fail('Expected exception') self.fail('Expected exception')
@ -572,8 +572,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
pass pass
with app.test_request_context(): with app.test_request_context():
self.assert_equal(flask.url_for('hello', name='test x'), '/hello/test%20x') self.assert_equal(flask.url_for('hello', name='test x'), '/hello/test%20x')
assert flask.url_for('hello', name='test x', _external=True) \ self.assert_equal(flask.url_for('hello', name='test x', _external=True),
== 'http://localhost/hello/test%20x' 'http://localhost/hello/test%20x')
def test_custom_converters(self): def test_custom_converters(self):
from werkzeug.routing import BaseConverter from werkzeug.routing import BaseConverter
@ -597,8 +597,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
self.assert_equal(rv.data.strip(), '<h1>Hello World!</h1>') self.assert_equal(rv.data.strip(), '<h1>Hello World!</h1>')
with app.test_request_context(): with app.test_request_context():
assert flask.url_for('static', filename='index.html') \ self.assert_equal(flask.url_for('static', filename='index.html'),
== '/static/index.html' '/static/index.html')
def test_none_response(self): def test_none_response(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@ -611,7 +611,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(str(e), 'View function did not return a response') self.assert_equal(str(e), 'View function did not return a response')
pass pass
else: else:
assert "Expected ValueError" self.assert_("Expected ValueError")
def test_request_locals(self): def test_request_locals(self):
self.assert_equal(repr(flask.g), '<LocalProxy unbound>') self.assert_equal(repr(flask.g), '<LocalProxy unbound>')
@ -641,7 +641,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}): with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):
pass pass
except Exception, e: except Exception, e:
assert isinstance(e, ValueError) self.assert_(isinstance(e, ValueError))
self.assert_equal(str(e), "the server name provided " + self.assert_equal(str(e), "the server name provided " +
"('localhost.localdomain:5000') does not match the " + \ "('localhost.localdomain:5000') does not match the " + \
"server name from the WSGI environment ('localhost')") "server name from the WSGI environment ('localhost')")
@ -768,11 +768,11 @@ class BasicFunctionalityTestCase(FlaskTestCase):
@app.before_request @app.before_request
def always_first(): def always_first():
flask.request.form['myfile'] flask.request.form['myfile']
assert False self.assert_(False)
@app.route('/accept', methods=['POST']) @app.route('/accept', methods=['POST'])
def accept_file(): def accept_file():
flask.request.form['myfile'] flask.request.form['myfile']
assert False self.assert_(False)
@app.errorhandler(413) @app.errorhandler(413)
def catcher(error): def catcher(error):
return '42' return '42'
@ -889,17 +889,17 @@ class ContextTestCase(FlaskTestCase):
self.assert_equal(index(), 'Hello World!') self.assert_equal(index(), 'Hello World!')
with app.test_request_context('/meh'): with app.test_request_context('/meh'):
self.assert_equal(meh(), 'http://localhost/meh') self.assert_equal(meh(), 'http://localhost/meh')
assert flask._request_ctx_stack.top is None self.assert_(flask._request_ctx_stack.top is None)
def test_context_test(self): def test_context_test(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
assert not flask.request self.assert_(not flask.request)
assert not flask.has_request_context() self.assert_(not flask.has_request_context())
ctx = app.test_request_context() ctx = app.test_request_context()
ctx.push() ctx.push()
try: try:
assert flask.request self.assert_(flask.request)
assert flask.has_request_context() self.assert_(flask.has_request_context())
finally: finally:
ctx.pop() ctx.pop()
@ -918,7 +918,7 @@ class ContextTestCase(FlaskTestCase):
except RuntimeError: except RuntimeError:
pass pass
else: else:
assert 0, 'expected runtime error' self.assert_(0, 'expected runtime error')
class SubdomainTestCase(FlaskTestCase): class SubdomainTestCase(FlaskTestCase):

18
flask/testsuite/blueprints.py

@ -173,8 +173,8 @@ class ModuleTestCase(FlaskTestCase):
self.assert_equal(rv.data.strip(), '/* nested file */') self.assert_equal(rv.data.strip(), '/* nested file */')
with app.test_request_context(): with app.test_request_context():
assert flask.url_for('admin.static', filename='test.txt') \ self.assert_equal(flask.url_for('admin.static', filename='test.txt'),
== '/admin/static/test.txt' '/admin/static/test.txt')
with app.test_request_context(): with app.test_request_context():
try: try:
@ -182,7 +182,7 @@ class ModuleTestCase(FlaskTestCase):
except TemplateNotFound, e: except TemplateNotFound, e:
self.assert_equal(e.name, 'missing.html') self.assert_equal(e.name, 'missing.html')
else: else:
assert 0, 'expected exception' self.assert_(0, 'expected exception')
with flask.Flask(__name__).test_request_context(): with flask.Flask(__name__).test_request_context():
self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested') self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')
@ -198,13 +198,13 @@ class ModuleTestCase(FlaskTestCase):
except NotFound: except NotFound:
pass pass
else: else:
assert 0, 'expected exception' self.assert_(0, 'expected exception')
try: try:
f('../__init__.py') f('../__init__.py')
except NotFound: except NotFound:
pass pass
else: else:
assert 0, 'expected exception' self.assert_(0, 'expected exception')
# testcase for a security issue that may exist on windows systems # testcase for a security issue that may exist on windows systems
import os import os
@ -217,7 +217,7 @@ class ModuleTestCase(FlaskTestCase):
except NotFound: except NotFound:
pass pass
else: else:
assert 0, 'expected exception' self.assert_(0, 'expected exception')
finally: finally:
os.path = old_path os.path = old_path
@ -355,8 +355,8 @@ class BlueprintTestCase(FlaskTestCase):
self.assert_equal(rv.data.strip(), '/* nested file */') self.assert_equal(rv.data.strip(), '/* nested file */')
with app.test_request_context(): with app.test_request_context():
assert flask.url_for('admin.static', filename='test.txt') \ self.assert_equal(flask.url_for('admin.static', filename='test.txt'),
== '/admin/static/test.txt' '/admin/static/test.txt')
with app.test_request_context(): with app.test_request_context():
try: try:
@ -364,7 +364,7 @@ class BlueprintTestCase(FlaskTestCase):
except TemplateNotFound, e: except TemplateNotFound, e:
self.assert_equal(e.name, 'missing.html') self.assert_equal(e.name, 'missing.html')
else: else:
assert 0, 'expected exception' self.assert_(0, 'expected exception')
with flask.Flask(__name__).test_request_context(): with flask.Flask(__name__).test_request_context():
self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested') self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')

20
flask/testsuite/config.py

@ -25,7 +25,7 @@ class ConfigTestCase(FlaskTestCase):
def common_object_test(self, app): def common_object_test(self, app):
self.assert_equal(app.secret_key, 'devkey') self.assert_equal(app.secret_key, 'devkey')
self.assert_equal(app.config['TEST_KEY'], 'foo') self.assert_equal(app.config['TEST_KEY'], 'foo')
assert 'ConfigTestCase' not in app.config self.assert_('ConfigTestCase' not in app.config)
def test_config_from_file(self): def test_config_from_file(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@ -54,13 +54,13 @@ class ConfigTestCase(FlaskTestCase):
try: try:
app.config.from_envvar('FOO_SETTINGS') app.config.from_envvar('FOO_SETTINGS')
except RuntimeError, e: except RuntimeError, e:
assert "'FOO_SETTINGS' is not set" in str(e) self.assert_("'FOO_SETTINGS' is not set" in str(e))
else: else:
assert 0, 'expected exception' self.assert_(0, 'expected exception')
assert not app.config.from_envvar('FOO_SETTINGS', silent=True) self.assert_(not app.config.from_envvar('FOO_SETTINGS', silent=True))
os.environ = {'FOO_SETTINGS': __file__.rsplit('.')[0] + '.py'} os.environ = {'FOO_SETTINGS': __file__.rsplit('.')[0] + '.py'}
assert app.config.from_envvar('FOO_SETTINGS') self.assert_(app.config.from_envvar('FOO_SETTINGS'))
self.common_object_test(app) self.common_object_test(app)
finally: finally:
os.environ = env os.environ = env
@ -71,12 +71,12 @@ class ConfigTestCase(FlaskTestCase):
app.config.from_pyfile('missing.cfg') app.config.from_pyfile('missing.cfg')
except IOError, e: except IOError, e:
msg = str(e) msg = str(e)
assert msg.startswith('[Errno 2] Unable to load configuration ' self.assert_(msg.startswith('[Errno 2] Unable to load configuration '
'file (No such file or directory):') 'file (No such file or directory):'))
assert msg.endswith("missing.cfg'") self.assert_(msg.endswith("missing.cfg'"))
else: else:
assert 0, 'expected config' self.assert_(0, 'expected config')
assert not app.config.from_pyfile('missing.cfg', silent=True) self.assert_(not app.config.from_pyfile('missing.cfg', silent=True))
class InstanceTestCase(FlaskTestCase): class InstanceTestCase(FlaskTestCase):

2
flask/testsuite/deprecations.py

@ -29,7 +29,7 @@ class DeprecationsTestCase(FlaskTestCase):
c = app.test_client() c = app.test_client()
self.assert_equal(c.get('/').data, '42') self.assert_equal(c.get('/').data, '42')
self.assert_equal(len(log), 1) self.assert_equal(len(log), 1)
assert 'init_jinja_globals' in str(log[0]['message']) self.assert_('init_jinja_globals' in str(log[0]['message']))
def suite(): def suite():

34
flask/testsuite/helpers.py

@ -108,7 +108,7 @@ class SendfileTestCase(FlaskTestCase):
app = flask.Flask(__name__) app = flask.Flask(__name__)
with app.test_request_context(): with app.test_request_context():
rv = flask.send_file('static/index.html') rv = flask.send_file('static/index.html')
assert rv.direct_passthrough self.assert_(rv.direct_passthrough)
self.assert_equal(rv.mimetype, 'text/html') self.assert_equal(rv.mimetype, 'text/html')
with app.open_resource('static/index.html') as f: with app.open_resource('static/index.html') as f:
self.assert_equal(rv.data, f.read()) self.assert_equal(rv.data, f.read())
@ -118,8 +118,8 @@ class SendfileTestCase(FlaskTestCase):
app.use_x_sendfile = True app.use_x_sendfile = True
with app.test_request_context(): with app.test_request_context():
rv = flask.send_file('static/index.html') rv = flask.send_file('static/index.html')
assert rv.direct_passthrough self.assert_(rv.direct_passthrough)
assert 'x-sendfile' in rv.headers self.assert_('x-sendfile' in rv.headers)
self.assert_equal(rv.headers['x-sendfile'], self.assert_equal(rv.headers['x-sendfile'],
os.path.join(app.root_path, 'static/index.html')) os.path.join(app.root_path, 'static/index.html'))
self.assert_equal(rv.mimetype, 'text/html') self.assert_equal(rv.mimetype, 'text/html')
@ -142,7 +142,7 @@ class SendfileTestCase(FlaskTestCase):
f = open(os.path.join(app.root_path, 'static/index.html')) f = open(os.path.join(app.root_path, 'static/index.html'))
rv = flask.send_file(f) rv = flask.send_file(f)
self.assert_equal(rv.mimetype, 'text/html') self.assert_equal(rv.mimetype, 'text/html')
assert 'x-sendfile' in rv.headers self.assert_('x-sendfile' in rv.headers)
self.assert_equal(rv.headers['x-sendfile'], self.assert_equal(rv.headers['x-sendfile'],
os.path.join(app.root_path, 'static/index.html')) os.path.join(app.root_path, 'static/index.html'))
# mimetypes + etag # mimetypes + etag
@ -170,7 +170,7 @@ class SendfileTestCase(FlaskTestCase):
with app.test_request_context(): with app.test_request_context():
f = StringIO('Test') f = StringIO('Test')
rv = flask.send_file(f) rv = flask.send_file(f)
assert 'x-sendfile' not in rv.headers self.assert_('x-sendfile' not in rv.headers)
# etags # etags
self.assert_equal(len(captured), 1) self.assert_equal(len(captured), 1)
@ -207,10 +207,10 @@ class LoggingTestCase(FlaskTestCase):
def test_logger_cache(self): def test_logger_cache(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
logger1 = app.logger logger1 = app.logger
assert app.logger is logger1 self.assert_(app.logger is logger1)
self.assert_equal(logger1.name, __name__) self.assert_equal(logger1.name, __name__)
app.logger_name = __name__ + '/test_logger_cache' app.logger_name = __name__ + '/test_logger_cache'
assert app.logger is not logger1 self.assert_(app.logger is not logger1)
def test_debug_log(self): def test_debug_log(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@ -230,10 +230,10 @@ class LoggingTestCase(FlaskTestCase):
with catch_stderr() as err: with catch_stderr() as err:
c.get('/') c.get('/')
out = err.getvalue() out = err.getvalue()
assert 'WARNING in helpers [' in out self.assert_('WARNING in helpers [' in out)
assert os.path.basename(__file__.rsplit('.')[0] + '.py') in out self.assert_(os.path.basename(__file__.rsplit('.')[0] + '.py') in out)
assert 'the standard library is dead' in out self.assert_('the standard library is dead' in out)
assert 'this is a debug statement' in out self.assert_('this is a debug statement' in out)
with catch_stderr() as err: with catch_stderr() as err:
try: try:
@ -241,7 +241,7 @@ class LoggingTestCase(FlaskTestCase):
except ZeroDivisionError: except ZeroDivisionError:
pass pass
else: else:
assert False, 'debug log ate the exception' self.assert_(False, 'debug log ate the exception')
def test_exception_logging(self): def test_exception_logging(self):
out = StringIO() out = StringIO()
@ -255,13 +255,13 @@ class LoggingTestCase(FlaskTestCase):
rv = app.test_client().get('/') rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 500) self.assert_equal(rv.status_code, 500)
assert 'Internal Server Error' in rv.data self.assert_('Internal Server Error' in rv.data)
err = out.getvalue() err = out.getvalue()
assert 'Exception on / [GET]' in err self.assert_('Exception on / [GET]' in err)
assert 'Traceback (most recent call last):' in err self.assert_('Traceback (most recent call last):' in err)
assert '1/0' in err self.assert_('1/0' in err)
assert 'ZeroDivisionError:' in err self.assert_('ZeroDivisionError:' in err)
def test_processor_exceptions(self): def test_processor_exceptions(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)

2
flask/testsuite/signals.py

@ -91,7 +91,7 @@ class SignalsTestCase(FlaskTestCase):
try: try:
self.assert_equal(app.test_client().get('/').status_code, 500) self.assert_equal(app.test_client().get('/').status_code, 500)
self.assert_equal(len(recorded), 1) self.assert_equal(len(recorded), 1)
assert isinstance(recorded[0], ZeroDivisionError) self.assert_(isinstance(recorded[0], ZeroDivisionError))
finally: finally:
flask.got_request_exception.disconnect(record, app) flask.got_request_exception.disconnect(record, app)

12
flask/testsuite/templating.py

@ -70,10 +70,10 @@ class TemplatingTestCase(FlaskTestCase):
def test_no_escaping(self): def test_no_escaping(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
with app.test_request_context(): with app.test_request_context():
assert flask.render_template_string('{{ foo }}', self.assert_equal(flask.render_template_string('{{ foo }}',
foo='<test>') == '<test>' foo='<test>'), '<test>')
assert flask.render_template('mail.txt', foo='<test>') \ self.assert_equal(flask.render_template('mail.txt', foo='<test>'),
== '<test> Mail' '<test> Mail')
def test_macros(self): def test_macros(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@ -86,7 +86,7 @@ class TemplatingTestCase(FlaskTestCase):
@app.template_filter() @app.template_filter()
def my_reverse(s): def my_reverse(s):
return s[::-1] return s[::-1]
assert 'my_reverse' in app.jinja_env.filters.keys() self.assert_('my_reverse' in app.jinja_env.filters.keys())
self.assert_equal(app.jinja_env.filters['my_reverse'], my_reverse) self.assert_equal(app.jinja_env.filters['my_reverse'], my_reverse)
self.assert_equal(app.jinja_env.filters['my_reverse']('abcd'), 'dcba') self.assert_equal(app.jinja_env.filters['my_reverse']('abcd'), 'dcba')
@ -95,7 +95,7 @@ class TemplatingTestCase(FlaskTestCase):
@app.template_filter('strrev') @app.template_filter('strrev')
def my_reverse(s): def my_reverse(s):
return s[::-1] return s[::-1]
assert 'strrev' in app.jinja_env.filters.keys() self.assert_('strrev' in app.jinja_env.filters.keys())
self.assert_equal(app.jinja_env.filters['strrev'], my_reverse) self.assert_equal(app.jinja_env.filters['strrev'], my_reverse)
self.assert_equal(app.jinja_env.filters['strrev']('abcd'), 'dcba') self.assert_equal(app.jinja_env.filters['strrev']('abcd'), 'dcba')

4
flask/testsuite/testing.py

@ -102,8 +102,8 @@ class TestToolsTestCase(FlaskTestCase):
self.assert_equal(resp.status_code, 200) self.assert_equal(resp.status_code, 200)
resp = c.get('/other') resp = c.get('/other')
assert not hasattr(flask.g, 'value') self.assert_(not hasattr(flask.g, 'value'))
assert 'Internal Server Error' in resp.data self.assert_('Internal Server Error' in resp.data)
self.assert_equal(resp.status_code, 500) self.assert_equal(resp.status_code, 500)
flask.g.value = 23 flask.g.value = 23

Loading…
Cancel
Save