Browse Source

Use assert_true instead of assert_

assert_ is deprecated which causes annoying warnings
pull/739/head
Daniel Neuhäuser 12 years ago
parent
commit
239780be28
  1. 7
      flask/testsuite/__init__.py
  2. 2
      flask/testsuite/appctx.py
  3. 92
      flask/testsuite/basic.py
  4. 44
      flask/testsuite/blueprints.py
  5. 24
      flask/testsuite/config.py
  6. 8
      flask/testsuite/ext.py
  7. 38
      flask/testsuite/helpers.py
  8. 24
      flask/testsuite/reqctx.py
  9. 2
      flask/testsuite/signals.py
  10. 2
      flask/testsuite/subclassing.py
  11. 36
      flask/testsuite/templating.py
  12. 12
      flask/testsuite/testing.py

7
flask/testsuite/__init__.py

@ -101,9 +101,9 @@ def emits_module_deprecation_warning(f):
def new_f(self, *args, **kwargs):
with catch_warnings() as log:
f(self, *args, **kwargs)
self.assert_(log, 'expected deprecation warning')
self.assert_true(log, 'expected deprecation warning')
for entry in log:
self.assert_('Modules are deprecated' in str(entry['message']))
self.assert_true('Modules are deprecated' in str(entry['message']))
return update_wrapper(new_f, f)
@ -142,6 +142,9 @@ class FlaskTestCase(unittest.TestCase):
with catcher:
callable(*args, **kwargs)
def assert_true(self, x):
self.assertTrue(x)
class _ExceptionCatcher(object):

2
flask/testsuite/appctx.py

@ -87,7 +87,7 @@ class AppContextTestCase(FlaskTestCase):
with flask._app_ctx_stack.top:
with flask._request_ctx_stack.top:
pass
self.assert_(flask._request_ctx_stack.request.environ
self.assert_true(flask._request_ctx_stack.request.environ
['werkzeug.request'] is not None)
c = app.test_client()
c.get('/')

92
flask/testsuite/basic.py

@ -78,7 +78,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])
rv = c.head('/')
self.assert_equal(rv.status_code, 200)
self.assert_(not rv.data) # head truncates
self.assert_true(not rv.data) # head truncates
self.assert_equal(c.post('/more').data, b'POST')
self.assert_equal(c.get('/more').data, b'GET')
rv = c.delete('/more')
@ -102,7 +102,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])
rv = c.head('/')
self.assert_equal(rv.status_code, 200)
self.assert_(not rv.data) # head truncates
self.assert_true(not rv.data) # head truncates
self.assert_equal(c.post('/more').data, b'POST')
self.assert_equal(c.get('/more').data, b'GET')
rv = c.delete('/more')
@ -173,8 +173,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
flask.session['testing'] = 42
return 'Hello World'
rv = app.test_client().get('/', 'http://example.com/')
self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())
self.assert_('httponly' in rv.headers['set-cookie'].lower())
self.assert_true('domain=.example.com' in rv.headers['set-cookie'].lower())
self.assert_true('httponly' in rv.headers['set-cookie'].lower())
def test_session_using_server_name_and_port(self):
app = flask.Flask(__name__)
@ -187,8 +187,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
flask.session['testing'] = 42
return 'Hello World'
rv = app.test_client().get('/', 'http://example.com:8080/')
self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())
self.assert_('httponly' in rv.headers['set-cookie'].lower())
self.assert_true('domain=.example.com' in rv.headers['set-cookie'].lower())
self.assert_true('httponly' in rv.headers['set-cookie'].lower())
def test_session_using_server_name_port_and_path(self):
app = flask.Flask(__name__)
@ -202,9 +202,9 @@ class BasicFunctionalityTestCase(FlaskTestCase):
flask.session['testing'] = 42
return 'Hello World'
rv = app.test_client().get('/', 'http://example.com:8080/foo')
self.assert_('domain=example.com' in rv.headers['set-cookie'].lower())
self.assert_('path=/foo' in rv.headers['set-cookie'].lower())
self.assert_('httponly' in rv.headers['set-cookie'].lower())
self.assert_true('domain=example.com' in rv.headers['set-cookie'].lower())
self.assert_true('path=/foo' in rv.headers['set-cookie'].lower())
self.assert_true('httponly' in rv.headers['set-cookie'].lower())
def test_session_using_application_root(self):
class PrefixPathMiddleware(object):
@ -226,7 +226,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
flask.session['testing'] = 42
return 'Hello World'
rv = app.test_client().get('/', 'http://example.com:8080/')
self.assert_('path=/bar' in rv.headers['set-cookie'].lower())
self.assert_true('path=/bar' in rv.headers['set-cookie'].lower())
def test_session_using_session_settings(self):
app = flask.Flask(__name__)
@ -245,10 +245,10 @@ class BasicFunctionalityTestCase(FlaskTestCase):
return 'Hello World'
rv = app.test_client().get('/', 'http://www.example.com:8080/test/')
cookie = rv.headers['set-cookie'].lower()
self.assert_('domain=.example.com' in cookie)
self.assert_('path=/;' in cookie)
self.assert_('secure' in cookie)
self.assert_('httponly' not in cookie)
self.assert_true('domain=.example.com' in cookie)
self.assert_true('path=/;' in cookie)
self.assert_true('secure' in cookie)
self.assert_true('httponly' not in cookie)
def test_missing_session(self):
app = flask.Flask(__name__)
@ -256,11 +256,11 @@ class BasicFunctionalityTestCase(FlaskTestCase):
try:
f(*args, **kwargs)
except RuntimeError as e:
self.assert_(e.args and 'session is unavailable' in e.args[0])
self.assert_true(e.args and 'session is unavailable' in e.args[0])
else:
self.assert_(False, 'expected exception')
self.assert_true(False, 'expected exception')
with app.test_request_context():
self.assert_(flask.session.get('missing_key') is None)
self.assert_true(flask.session.get('missing_key') is None)
expect_exception(flask.session.__setitem__, 'foo', 42)
expect_exception(flask.session.pop, 'foo')
@ -280,7 +280,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
client = app.test_client()
rv = client.get('/')
self.assert_('set-cookie' in rv.headers)
self.assert_true('set-cookie' in rv.headers)
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
expires = parse_date(match.group())
expected = datetime.utcnow() + app.permanent_session_lifetime
@ -293,9 +293,9 @@ class BasicFunctionalityTestCase(FlaskTestCase):
permanent = False
rv = app.test_client().get('/')
self.assert_('set-cookie' in rv.headers)
self.assert_true('set-cookie' in rv.headers)
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
self.assert_(match is None)
self.assert_true(match is None)
def test_session_stored_last(self):
app = flask.Flask(__name__)
@ -347,11 +347,11 @@ class BasicFunctionalityTestCase(FlaskTestCase):
app.secret_key = 'testkey'
with app.test_request_context():
self.assert_(not flask.session.modified)
self.assert_true(not flask.session.modified)
flask.flash('Zap')
flask.session.modified = False
flask.flash('Zip')
self.assert_(flask.session.modified)
self.assert_true(flask.session.modified)
self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])
def test_extended_flashing(self):
@ -448,12 +448,12 @@ class BasicFunctionalityTestCase(FlaskTestCase):
return response
@app.route('/')
def index():
self.assert_('before' in evts)
self.assert_('after' not in evts)
self.assert_true('before' in evts)
self.assert_true('after' not in evts)
return 'request'
self.assert_('after' not in evts)
self.assert_true('after' not in evts)
rv = app.test_client().get('/').data
self.assert_(b'after' in evts)
self.assert_true(b'after' in evts)
self.assert_equal(rv, b'request|after')
def test_after_request_processing(self):
@ -483,7 +483,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
return "Response"
rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 200)
self.assert_(b'Response' in rv.data)
self.assert_true(b'Response' in rv.data)
self.assert_equal(len(called), 1)
def test_teardown_request_handler_debug_mode(self):
@ -499,7 +499,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
return "Response"
rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 200)
self.assert_(b'Response' in rv.data)
self.assert_true(b'Response' in rv.data)
self.assert_equal(len(called), 1)
def test_teardown_request_handler_error(self):
@ -532,7 +532,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
1/0
rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 500)
self.assert_(b'Internal Server Error' in rv.data)
self.assert_true(b'Internal Server Error' in rv.data)
self.assert_equal(len(called), 2)
def test_before_after_request_order(self):
@ -606,7 +606,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
app = flask.Flask(__name__)
@app.errorhandler(MyException)
def handle_my_exception(e):
self.assert_(isinstance(e, MyException))
self.assert_true(isinstance(e, MyException))
return '42'
@app.route('/')
def index():
@ -629,7 +629,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
try:
c.get('/fail')
except KeyError as e:
self.assert_(isinstance(e, BadRequest))
self.assert_true(isinstance(e, BadRequest))
else:
self.fail('Expected exception')
@ -664,8 +664,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
try:
c.post('/fail', data={'foo': 'index.txt'})
except DebugFilesKeyError as e:
self.assert_('no file contents were transmitted' in str(e))
self.assert_('This was submitted: "index.txt"' in str(e))
self.assert_true('no file contents were transmitted' in str(e))
self.assert_true('This was submitted: "index.txt"' in str(e))
else:
self.fail('Expected exception')
@ -804,7 +804,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(str(e), 'View function did not return a response')
pass
else:
self.assert_("Expected ValueError")
self.assert_true("Expected ValueError")
def test_request_locals(self):
self.assert_equal(repr(flask.g), '<LocalProxy unbound>')
@ -894,11 +894,11 @@ class BasicFunctionalityTestCase(FlaskTestCase):
@app.before_request
def always_first():
flask.request.form['myfile']
self.assert_(False)
self.assert_true(False)
@app.route('/accept', methods=['POST'])
def accept_file():
flask.request.form['myfile']
self.assert_(False)
self.assert_true(False)
@app.errorhandler(413)
def catcher(error):
return '42'
@ -967,14 +967,14 @@ class BasicFunctionalityTestCase(FlaskTestCase):
@app.route('/')
def index():
return 'Awesome'
self.assert_(not app.got_first_request)
self.assert_true(not app.got_first_request)
self.assert_equal(app.test_client().get('/').data, b'Awesome')
try:
@app.route('/foo')
def broken():
return 'Meh'
except AssertionError as e:
self.assert_('A setup function was called' in str(e))
self.assert_true('A setup function was called' in str(e))
else:
self.fail('Expected exception')
@ -983,7 +983,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
def working():
return 'Meh'
self.assert_equal(app.test_client().get('/foo').data, b'Meh')
self.assert_(app.got_first_request)
self.assert_true(app.got_first_request)
def test_before_first_request_functions(self):
got = []
@ -996,7 +996,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(got, [42])
c.get('/')
self.assert_equal(got, [42])
self.assert_(app.got_first_request)
self.assert_true(app.got_first_request)
def test_routing_redirect_debugging(self):
app = flask.Flask(__name__)
@ -1008,8 +1008,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
try:
c.post('/foo', data={})
except AssertionError as e:
self.assert_('http://localhost/foo/' in str(e))
self.assert_('Make sure to directly send your POST-request '
self.assert_true('http://localhost/foo/' in str(e))
self.assert_true('Make sure to directly send your POST-request '
'to this URL' in str(e))
else:
self.fail('Expected exception')
@ -1061,12 +1061,12 @@ class BasicFunctionalityTestCase(FlaskTestCase):
with self.assert_raises(ZeroDivisionError):
c.get('/fail')
self.assert_(flask._request_ctx_stack.top is not None)
self.assert_(flask._app_ctx_stack.top is not None)
self.assert_true(flask._request_ctx_stack.top is not None)
self.assert_true(flask._app_ctx_stack.top is not None)
# implicit appctx disappears too
flask._request_ctx_stack.top.pop()
self.assert_(flask._request_ctx_stack.top is None)
self.assert_(flask._app_ctx_stack.top is None)
self.assert_true(flask._request_ctx_stack.top is None)
self.assert_true(flask._app_ctx_stack.top is None)
class SubdomainTestCase(FlaskTestCase):

44
flask/testsuite/blueprints.py

@ -185,7 +185,7 @@ class ModuleTestCase(FlaskTestCase):
except TemplateNotFound as e:
self.assert_equal(e.name, 'missing.html')
else:
self.assert_(0, 'expected exception')
self.assert_true(0, 'expected exception')
with flask.Flask(__name__).test_request_context():
self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')
@ -201,13 +201,13 @@ class ModuleTestCase(FlaskTestCase):
except NotFound:
pass
else:
self.assert_(0, 'expected exception')
self.assert_true(0, 'expected exception')
try:
f('../__init__.py')
except NotFound:
pass
else:
self.assert_(0, 'expected exception')
self.assert_true(0, 'expected exception')
# testcase for a security issue that may exist on windows systems
import os
@ -220,7 +220,7 @@ class ModuleTestCase(FlaskTestCase):
except NotFound:
pass
else:
self.assert_(0, 'expected exception')
self.assert_true(0, 'expected exception')
finally:
os.path = old_path
@ -380,7 +380,7 @@ class BlueprintTestCase(FlaskTestCase):
except TemplateNotFound as e:
self.assert_equal(e.name, 'missing.html')
else:
self.assert_(0, 'expected exception')
self.assert_true(0, 'expected exception')
with flask.Flask(__name__).test_request_context():
self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')
@ -547,7 +547,7 @@ class BlueprintTestCase(FlaskTestCase):
return s[::-1]
app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/py')
self.assert_('my_reverse' in app.jinja_env.filters.keys())
self.assert_true('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']('abcd'), 'dcba')
@ -558,7 +558,7 @@ class BlueprintTestCase(FlaskTestCase):
bp.add_app_template_filter(my_reverse)
app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/py')
self.assert_('my_reverse' in app.jinja_env.filters.keys())
self.assert_true('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']('abcd'), 'dcba')
@ -569,7 +569,7 @@ class BlueprintTestCase(FlaskTestCase):
return s[::-1]
app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/py')
self.assert_('strrev' in app.jinja_env.filters.keys())
self.assert_true('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']('abcd'), 'dcba')
@ -580,7 +580,7 @@ class BlueprintTestCase(FlaskTestCase):
bp.add_app_template_filter(my_reverse, 'strrev')
app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/py')
self.assert_('strrev' in app.jinja_env.filters.keys())
self.assert_true('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']('abcd'), 'dcba')
@ -656,9 +656,9 @@ class BlueprintTestCase(FlaskTestCase):
return isinstance(value, bool)
app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/py')
self.assert_('is_boolean' in app.jinja_env.tests.keys())
self.assert_true('is_boolean' in app.jinja_env.tests.keys())
self.assert_equal(app.jinja_env.tests['is_boolean'], is_boolean)
self.assert_(app.jinja_env.tests['is_boolean'](False))
self.assert_true(app.jinja_env.tests['is_boolean'](False))
def test_add_template_test(self):
bp = flask.Blueprint('bp', __name__)
@ -667,9 +667,9 @@ class BlueprintTestCase(FlaskTestCase):
bp.add_app_template_test(is_boolean)
app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/py')
self.assert_('is_boolean' in app.jinja_env.tests.keys())
self.assert_true('is_boolean' in app.jinja_env.tests.keys())
self.assert_equal(app.jinja_env.tests['is_boolean'], is_boolean)
self.assert_(app.jinja_env.tests['is_boolean'](False))
self.assert_true(app.jinja_env.tests['is_boolean'](False))
def test_template_test_with_name(self):
bp = flask.Blueprint('bp', __name__)
@ -678,9 +678,9 @@ class BlueprintTestCase(FlaskTestCase):
return isinstance(value, bool)
app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/py')
self.assert_('boolean' in app.jinja_env.tests.keys())
self.assert_true('boolean' in app.jinja_env.tests.keys())
self.assert_equal(app.jinja_env.tests['boolean'], is_boolean)
self.assert_(app.jinja_env.tests['boolean'](False))
self.assert_true(app.jinja_env.tests['boolean'](False))
def test_add_template_test_with_name(self):
bp = flask.Blueprint('bp', __name__)
@ -689,9 +689,9 @@ class BlueprintTestCase(FlaskTestCase):
bp.add_app_template_test(is_boolean, 'boolean')
app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/py')
self.assert_('boolean' in app.jinja_env.tests.keys())
self.assert_true('boolean' in app.jinja_env.tests.keys())
self.assert_equal(app.jinja_env.tests['boolean'], is_boolean)
self.assert_(app.jinja_env.tests['boolean'](False))
self.assert_true(app.jinja_env.tests['boolean'](False))
def test_template_test_with_template(self):
bp = flask.Blueprint('bp', __name__)
@ -704,7 +704,7 @@ class BlueprintTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def test_template_test_after_route_with_template(self):
app = flask.Flask(__name__)
@ -717,7 +717,7 @@ class BlueprintTestCase(FlaskTestCase):
return isinstance(value, bool)
app.register_blueprint(bp, url_prefix='/py')
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def test_add_template_test_with_template(self):
bp = flask.Blueprint('bp', __name__)
@ -730,7 +730,7 @@ class BlueprintTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def test_template_test_with_name_and_template(self):
bp = flask.Blueprint('bp', __name__)
@ -743,7 +743,7 @@ class BlueprintTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def test_add_template_test_with_name_and_template(self):
bp = flask.Blueprint('bp', __name__)
@ -756,7 +756,7 @@ class BlueprintTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def suite():
suite = unittest.TestSuite()

24
flask/testsuite/config.py

@ -28,7 +28,7 @@ class ConfigTestCase(FlaskTestCase):
def common_object_test(self, app):
self.assert_equal(app.secret_key, 'devkey')
self.assert_equal(app.config['TEST_KEY'], 'foo')
self.assert_('ConfigTestCase' not in app.config)
self.assert_true('ConfigTestCase' not in app.config)
def test_config_from_file(self):
app = flask.Flask(__name__)
@ -57,13 +57,13 @@ class ConfigTestCase(FlaskTestCase):
try:
app.config.from_envvar('FOO_SETTINGS')
except RuntimeError as e:
self.assert_("'FOO_SETTINGS' is not set" in str(e))
self.assert_true("'FOO_SETTINGS' is not set" in str(e))
else:
self.assert_(0, 'expected exception')
self.assert_(not app.config.from_envvar('FOO_SETTINGS', silent=True))
self.assert_true(0, 'expected exception')
self.assert_true(not app.config.from_envvar('FOO_SETTINGS', silent=True))
os.environ = {'FOO_SETTINGS': __file__.rsplit('.', 1)[0] + '.py'}
self.assert_(app.config.from_envvar('FOO_SETTINGS'))
self.assert_true(app.config.from_envvar('FOO_SETTINGS'))
self.common_object_test(app)
finally:
os.environ = env
@ -77,9 +77,9 @@ class ConfigTestCase(FlaskTestCase):
app.config.from_envvar('FOO_SETTINGS')
except IOError as e:
msg = str(e)
self.assert_(msg.startswith('[Errno 2] Unable to load configuration '
self.assert_true(msg.startswith('[Errno 2] Unable to load configuration '
'file (No such file or directory):'))
self.assert_(msg.endswith("missing.cfg'"))
self.assert_true(msg.endswith("missing.cfg'"))
else:
self.fail('expected IOError')
self.assertFalse(app.config.from_envvar('FOO_SETTINGS', silent=True))
@ -92,12 +92,12 @@ class ConfigTestCase(FlaskTestCase):
app.config.from_pyfile('missing.cfg')
except IOError as e:
msg = str(e)
self.assert_(msg.startswith('[Errno 2] Unable to load configuration '
self.assert_true(msg.startswith('[Errno 2] Unable to load configuration '
'file (No such file or directory):'))
self.assert_(msg.endswith("missing.cfg'"))
self.assert_true(msg.endswith("missing.cfg'"))
else:
self.assert_(0, 'expected config')
self.assert_(not app.config.from_pyfile('missing.cfg', silent=True))
self.assert_true(0, 'expected config')
self.assert_true(not app.config.from_pyfile('missing.cfg', silent=True))
def test_session_lifetime(self):
app = flask.Flask(__name__)
@ -141,7 +141,7 @@ class InstanceTestCase(FlaskTestCase):
try:
flask.Flask(__name__, instance_path='instance')
except ValueError as e:
self.assert_('must be absolute' in str(e))
self.assert_true('must be absolute' in str(e))
else:
self.fail('Expected value error')

8
flask/testsuite/ext.py

@ -42,7 +42,7 @@ class ExtImportHookTestCase(FlaskTestCase):
def teardown(self):
from flask import ext
for key in ext.__dict__:
self.assert_('.' not in key)
self.assert_true('.' not in key)
def test_flaskext_new_simple_import_normal(self):
from flask.ext.newext_simple import ext_id
@ -108,12 +108,12 @@ class ExtImportHookTestCase(FlaskTestCase):
import flask.ext.broken
except ImportError:
exc_type, exc_value, tb = sys.exc_info()
self.assert_(exc_type is ImportError)
self.assert_true(exc_type is ImportError)
self.assert_equal(str(exc_value), 'No module named missing_module')
self.assert_(tb.tb_frame.f_globals is globals())
self.assert_true(tb.tb_frame.f_globals is globals())
next = tb.tb_next
self.assert_('flask_broken/__init__.py' in next.tb_frame.f_code.co_filename)
self.assert_true('flask_broken/__init__.py' in next.tb_frame.f_code.co_filename)
def suite():

38
flask/testsuite/helpers.py

@ -48,8 +48,8 @@ class JSONTestCase(FlaskTestCase):
rv = c.post('/json', data='malformed', content_type='application/json')
self.assert_equal(rv.status_code, 400)
self.assert_equal(rv.mimetype, 'application/json')
self.assert_('description' in flask.json.loads(rv.data))
self.assert_('<p>' not in flask.json.loads(rv.data)['description'])
self.assert_true('description' in flask.json.loads(rv.data))
self.assert_true('<p>' not in flask.json.loads(rv.data)['description'])
def test_json_body_encoding(self):
app = flask.Flask(__name__)
@ -167,7 +167,7 @@ class SendfileTestCase(FlaskTestCase):
app = flask.Flask(__name__)
with app.test_request_context():
rv = flask.send_file('static/index.html')
self.assert_(rv.direct_passthrough)
self.assert_true(rv.direct_passthrough)
self.assert_equal(rv.mimetype, 'text/html')
with app.open_resource('static/index.html') as f:
self.assert_equal(rv.data, f.read())
@ -177,8 +177,8 @@ class SendfileTestCase(FlaskTestCase):
app.use_x_sendfile = True
with app.test_request_context():
rv = flask.send_file('static/index.html')
self.assert_(rv.direct_passthrough)
self.assert_('x-sendfile' in rv.headers)
self.assert_true(rv.direct_passthrough)
self.assert_true('x-sendfile' in rv.headers)
self.assert_equal(rv.headers['x-sendfile'],
os.path.join(app.root_path, 'static/index.html'))
self.assert_equal(rv.mimetype, 'text/html')
@ -201,7 +201,7 @@ class SendfileTestCase(FlaskTestCase):
f = open(os.path.join(app.root_path, 'static/index.html'))
rv = flask.send_file(f)
self.assert_equal(rv.mimetype, 'text/html')
self.assert_('x-sendfile' in rv.headers)
self.assert_true('x-sendfile' in rv.headers)
self.assert_equal(rv.headers['x-sendfile'],
os.path.join(app.root_path, 'static/index.html'))
# mimetypes + etag
@ -229,7 +229,7 @@ class SendfileTestCase(FlaskTestCase):
with app.test_request_context():
f = StringIO('Test')
rv = flask.send_file(f)
self.assert_('x-sendfile' not in rv.headers)
self.assert_true('x-sendfile' not in rv.headers)
# etags
self.assert_equal(len(captured), 1)
@ -302,10 +302,10 @@ class LoggingTestCase(FlaskTestCase):
def test_logger_cache(self):
app = flask.Flask(__name__)
logger1 = app.logger
self.assert_(app.logger is logger1)
self.assert_true(app.logger is logger1)
self.assert_equal(logger1.name, __name__)
app.logger_name = __name__ + '/test_logger_cache'
self.assert_(app.logger is not logger1)
self.assert_true(app.logger is not logger1)
def test_debug_log(self):
app = flask.Flask(__name__)
@ -325,10 +325,10 @@ class LoggingTestCase(FlaskTestCase):
with catch_stderr() as err:
c.get('/')
out = err.getvalue()
self.assert_('WARNING in helpers [' in out)
self.assert_(os.path.basename(__file__.rsplit('.', 1)[0] + '.py') in out)
self.assert_('the standard library is dead' in out)
self.assert_('this is a debug statement' in out)
self.assert_true('WARNING in helpers [' in out)
self.assert_true(os.path.basename(__file__.rsplit('.', 1)[0] + '.py') in out)
self.assert_true('the standard library is dead' in out)
self.assert_true('this is a debug statement' in out)
with catch_stderr() as err:
try:
@ -336,7 +336,7 @@ class LoggingTestCase(FlaskTestCase):
except ZeroDivisionError:
pass
else:
self.assert_(False, 'debug log ate the exception')
self.assert_true(False, 'debug log ate the exception')
def test_debug_log_override(self):
app = flask.Flask(__name__)
@ -357,13 +357,13 @@ class LoggingTestCase(FlaskTestCase):
rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 500)
self.assert_(b'Internal Server Error' in rv.data)
self.assert_true(b'Internal Server Error' in rv.data)
err = out.getvalue()
self.assert_('Exception on / [GET]' in err)
self.assert_('Traceback (most recent call last):' in err)
self.assert_('1/0' in err)
self.assert_('ZeroDivisionError:' in err)
self.assert_true('Exception on / [GET]' in err)
self.assert_true('Traceback (most recent call last):' in err)
self.assert_true('1/0' in err)
self.assert_true('ZeroDivisionError:' in err)
def test_processor_exceptions(self):
app = flask.Flask(__name__)

24
flask/testsuite/reqctx.py

@ -57,7 +57,7 @@ class RequestContextTestCase(FlaskTestCase):
with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):
pass
except Exception as e:
self.assert_(isinstance(e, ValueError))
self.assert_true(isinstance(e, ValueError))
self.assert_equal(str(e), "the server name provided " +
"('localhost.localdomain:5000') does not match the " + \
"server name from the WSGI environment ('localhost')")
@ -93,17 +93,17 @@ class RequestContextTestCase(FlaskTestCase):
self.assert_equal(index(), 'Hello World!')
with app.test_request_context('/meh'):
self.assert_equal(meh(), 'http://localhost/meh')
self.assert_(flask._request_ctx_stack.top is None)
self.assert_true(flask._request_ctx_stack.top is None)
def test_context_test(self):
app = flask.Flask(__name__)
self.assert_(not flask.request)
self.assert_(not flask.has_request_context())
self.assert_true(not flask.request)
self.assert_true(not flask.has_request_context())
ctx = app.test_request_context()
ctx.push()
try:
self.assert_(flask.request)
self.assert_(flask.has_request_context())
self.assert_true(flask.request)
self.assert_true(flask.has_request_context())
finally:
ctx.pop()
@ -122,7 +122,7 @@ class RequestContextTestCase(FlaskTestCase):
except RuntimeError:
pass
else:
self.assert_(0, 'expected runtime error')
self.assert_true(0, 'expected runtime error')
def test_greenlet_context_copying(self):
app = flask.Flask(__name__)
@ -132,14 +132,14 @@ class RequestContextTestCase(FlaskTestCase):
def index():
reqctx = flask._request_ctx_stack.top.copy()
def g():
self.assert_(not flask.request)
self.assert_(not flask.current_app)
self.assert_true(not flask.request)
self.assert_true(not flask.current_app)
with reqctx:
self.assert_(flask.request)
self.assert_true(flask.request)
self.assert_equal(flask.current_app, app)
self.assert_equal(flask.request.path, '/')
self.assert_equal(flask.request.args['foo'], 'bar')
self.assert_(not flask.request)
self.assert_true(not flask.request)
return 42
greenlets.append(greenlet(g))
return 'Hello World!'
@ -159,7 +159,7 @@ class RequestContextTestCase(FlaskTestCase):
reqctx = flask._request_ctx_stack.top.copy()
@flask.copy_current_request_context
def g():
self.assert_(flask.request)
self.assert_true(flask.request)
self.assert_equal(flask.current_app, app)
self.assert_equal(flask.request.path, '/')
self.assert_equal(flask.request.args['foo'], 'bar')

2
flask/testsuite/signals.py

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

2
flask/testsuite/subclassing.py

@ -34,7 +34,7 @@ class FlaskSubclassingTestCase(FlaskTestCase):
rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 500)
self.assert_(b'Internal Server Error' in rv.data)
self.assert_true(b'Internal Server Error' in rv.data)
err = out.getvalue()
self.assert_equal(err, '')

36
flask/testsuite/templating.py

@ -99,7 +99,7 @@ class TemplatingTestCase(FlaskTestCase):
@app.template_filter()
def my_reverse(s):
return s[::-1]
self.assert_('my_reverse' in app.jinja_env.filters.keys())
self.assert_true('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']('abcd'), 'dcba')
@ -108,7 +108,7 @@ class TemplatingTestCase(FlaskTestCase):
def my_reverse(s):
return s[::-1]
app.add_template_filter(my_reverse)
self.assert_('my_reverse' in app.jinja_env.filters.keys())
self.assert_true('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']('abcd'), 'dcba')
@ -117,7 +117,7 @@ class TemplatingTestCase(FlaskTestCase):
@app.template_filter('strrev')
def my_reverse(s):
return s[::-1]
self.assert_('strrev' in app.jinja_env.filters.keys())
self.assert_true('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']('abcd'), 'dcba')
@ -126,7 +126,7 @@ class TemplatingTestCase(FlaskTestCase):
def my_reverse(s):
return s[::-1]
app.add_template_filter(my_reverse, 'strrev')
self.assert_('strrev' in app.jinja_env.filters.keys())
self.assert_true('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']('abcd'), 'dcba')
@ -179,36 +179,36 @@ class TemplatingTestCase(FlaskTestCase):
@app.template_test()
def boolean(value):
return isinstance(value, bool)
self.assert_('boolean' in app.jinja_env.tests.keys())
self.assert_true('boolean' in app.jinja_env.tests.keys())
self.assert_equal(app.jinja_env.tests['boolean'], boolean)
self.assert_(app.jinja_env.tests['boolean'](False))
self.assert_true(app.jinja_env.tests['boolean'](False))
def test_add_template_test(self):
app = flask.Flask(__name__)
def boolean(value):
return isinstance(value, bool)
app.add_template_test(boolean)
self.assert_('boolean' in app.jinja_env.tests.keys())
self.assert_true('boolean' in app.jinja_env.tests.keys())
self.assert_equal(app.jinja_env.tests['boolean'], boolean)
self.assert_(app.jinja_env.tests['boolean'](False))
self.assert_true(app.jinja_env.tests['boolean'](False))
def test_template_test_with_name(self):
app = flask.Flask(__name__)
@app.template_test('boolean')
def is_boolean(value):
return isinstance(value, bool)
self.assert_('boolean' in app.jinja_env.tests.keys())
self.assert_true('boolean' in app.jinja_env.tests.keys())
self.assert_equal(app.jinja_env.tests['boolean'], is_boolean)
self.assert_(app.jinja_env.tests['boolean'](False))
self.assert_true(app.jinja_env.tests['boolean'](False))
def test_add_template_test_with_name(self):
app = flask.Flask(__name__)
def is_boolean(value):
return isinstance(value, bool)
app.add_template_test(is_boolean, 'boolean')
self.assert_('boolean' in app.jinja_env.tests.keys())
self.assert_true('boolean' in app.jinja_env.tests.keys())
self.assert_equal(app.jinja_env.tests['boolean'], is_boolean)
self.assert_(app.jinja_env.tests['boolean'](False))
self.assert_true(app.jinja_env.tests['boolean'](False))
def test_template_test_with_template(self):
app = flask.Flask(__name__)
@ -219,7 +219,7 @@ class TemplatingTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def test_add_template_test_with_template(self):
app = flask.Flask(__name__)
@ -230,7 +230,7 @@ class TemplatingTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def test_template_test_with_name_and_template(self):
app = flask.Flask(__name__)
@ -241,7 +241,7 @@ class TemplatingTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def test_add_template_test_with_name_and_template(self):
app = flask.Flask(__name__)
@ -252,16 +252,16 @@ class TemplatingTestCase(FlaskTestCase):
def index():
return flask.render_template('template_test.html', value=False)
rv = app.test_client().get('/')
self.assert_(b'Success!' in rv.data)
self.assert_true(b'Success!' in rv.data)
def test_add_template_global(self):
app = flask.Flask(__name__)
@app.template_global()
def get_stuff():
return 42
self.assert_('get_stuff' in app.jinja_env.globals.keys())
self.assert_true('get_stuff' in app.jinja_env.globals.keys())
self.assert_equal(app.jinja_env.globals['get_stuff'], get_stuff)
self.assert_(app.jinja_env.globals['get_stuff'](), 42)
self.assert_true(app.jinja_env.globals['get_stuff'](), 42)
with app.app_context():
rv = flask.render_template_string('{{ get_stuff() }}')
self.assert_equal(rv, '42')

12
flask/testsuite/testing.py

@ -106,7 +106,7 @@ class TestToolsTestCase(FlaskTestCase):
with c.session_transaction() as sess:
pass
except RuntimeError as e:
self.assert_('Session backend did not open a session' in str(e))
self.assert_true('Session backend did not open a session' in str(e))
else:
self.fail('Expected runtime error')
@ -118,9 +118,9 @@ class TestToolsTestCase(FlaskTestCase):
with app.test_client() as c:
rv = c.get('/')
req = flask.request._get_current_object()
self.assert_(req is not None)
self.assert_true(req is not None)
with c.session_transaction():
self.assert_(req is flask.request._get_current_object())
self.assert_true(req is flask.request._get_current_object())
def test_session_transaction_needs_cookies(self):
app = flask.Flask(__name__)
@ -130,7 +130,7 @@ class TestToolsTestCase(FlaskTestCase):
with c.session_transaction() as s:
pass
except RuntimeError as e:
self.assert_('cookies' in str(e))
self.assert_true('cookies' in str(e))
else:
self.fail('Expected runtime error')
@ -152,8 +152,8 @@ class TestToolsTestCase(FlaskTestCase):
self.assert_equal(resp.status_code, 200)
resp = c.get('/other')
self.assert_(not hasattr(flask.g, 'value'))
self.assert_(b'Internal Server Error' in resp.data)
self.assert_true(not hasattr(flask.g, 'value'))
self.assert_true(b'Internal Server Error' in resp.data)
self.assert_equal(resp.status_code, 500)
flask.g.value = 23

Loading…
Cancel
Save