Changed assert to self.assert_ where it was still in place
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 3069e2d · Browse files · 8 files·+86 added−86 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+86 added−86 removed
- other:+86 added−86 removed
Provenance
- Commit
fc2caa4- Tree
afb64f6- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
3069e2d
8 files changed+86 added−86 removed
modified:flask/testsuite/basic.py+40 added-40 removed
71 unmodified lines72 self.assert_equal(rv.status_code, 405)73 self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])74 rv = c.head('/')75 self.assert_equal(rv.status_code, 200)76- assert not rv.data # head truncates76+ self.assert_(not rv.data) # head truncates77 self.assert_equal(c.post('/more').data, 'POST')78 self.assert_equal(c.get('/more').data, 'GET')79 rv = c.delete('/more')80 self.assert_equal(rv.status_code, 405)15 unmodified lines96 self.assert_equal(rv.status_code, 405)97 self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])98 rv = c.head('/')99 self.assert_equal(rv.status_code, 200)100- assert not rv.data # head truncates100+ self.assert_(not rv.data) # head truncates101 self.assert_equal(c.post('/more').data, 'POST')102 self.assert_equal(c.get('/more').data, 'GET')103 rv = c.delete('/more')104 self.assert_equal(rv.status_code, 405)62 unmodified lines167 def index():168 flask.session['testing'] = 42169 return 'Hello World'170 rv = app.test_client().get('/', 'http://example.com/')171- assert 'domain=.example.com' in rv.headers['set-cookie'].lower()172- assert 'httponly' in rv.headers['set-cookie'].lower()171+ self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())172+ self.assert_('httponly' in rv.headers['set-cookie'].lower())173 174 def test_session_using_server_name_and_port(self):175 app = flask.Flask(__name__)176 app.config.update(4 unmodified lines181 def index():182 flask.session['testing'] = 42183 return 'Hello World'184 rv = app.test_client().get('/', 'http://example.com:8080/')185- assert 'domain=.example.com' in rv.headers['set-cookie'].lower()186- assert 'httponly' in rv.headers['set-cookie'].lower()185+ self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())186+ self.assert_('httponly' in rv.headers['set-cookie'].lower())187 188 def test_session_using_application_root(self):189 class PrefixPathMiddleware(object):190 def __init__(self, app, prefix):13 unmodified lines204 def index():205 flask.session['testing'] = 42206 return 'Hello World'207 rv = app.test_client().get('/', 'http://example.com:8080/')208- assert 'path=/bar' in rv.headers['set-cookie'].lower()208+ self.assert_('path=/bar' in rv.headers['set-cookie'].lower())209 210 def test_missing_session(self):211 app = flask.Flask(__name__)212 def expect_exception(f, *args, **kwargs):213 try:214 f(*args, **kwargs)215 except RuntimeError, e:216- assert e.args and 'session is unavailable' in e.args[0]216+ self.assert_(e.args and 'session is unavailable' in e.args[0])217 else:218- assert False, 'expected exception'218+ self.assert_(False, 'expected exception')219 with app.test_request_context():220- assert flask.session.get('missing_key') is None220+ self.assert_(flask.session.get('missing_key') is None)221 expect_exception(flask.session.__setitem__, 'foo', 42)222 expect_exception(flask.session.pop, 'foo')223 224 def test_session_expiration(self):11 unmodified lines236 return unicode(flask.session.permanent)237 238 client = app.test_client()239 rv = client.get('/')240- assert 'set-cookie' in rv.headers240+ self.assert_('set-cookie' in rv.headers)241 match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])242 expires = parse_date(match.group())243 expected = datetime.utcnow() + app.permanent_session_lifetime244 self.assert_equal(expires.year, expected.year)4 unmodified lines249 self.assert_equal(rv.data, 'True')250 251 permanent = False252 rv = app.test_client().get('/')253- assert 'set-cookie' in rv.headers253+ self.assert_('set-cookie' in rv.headers)254 match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])255- assert match is None255+ self.assert_(match is None)256 257 def test_flashes(self):258 app = flask.Flask(__name__)259 app.secret_key = 'testkey'260 261 with app.test_request_context():262- assert not flask.session.modified262+ self.assert_(not flask.session.modified)263 flask.flash('Zap')264 flask.session.modified = False265 flask.flash('Zip')266- assert flask.session.modified266+ self.assert_(flask.session.modified)267 self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])268 269 def test_extended_flashing(self):270 app = flask.Flask(__name__)36 unmodified lines307 evts.append('after')308 return response309 @app.route('/')310 def index():311- assert 'before' in evts312- assert 'after' not in evts311+ self.assert_('before' in evts)312+ self.assert_('after' not in evts)313 return 'request'314- assert 'after' not in evts314+ self.assert_('after' not in evts)315 rv = app.test_client().get('/').data316- assert 'after' in evts316+ self.assert_('after' in evts)317 self.assert_equal(rv, 'request|after')318 319 def test_teardown_request_handler(self):320 called = []6 unmodified lines327 def root():328 return "Response"329 rv = app.test_client().get('/')330 self.assert_equal(rv.status_code, 200)331- assert 'Response' in rv.data331+ self.assert_('Response' in rv.data)332 self.assert_equal(len(called), 1)333 334 def test_teardown_request_handler_debug_mode(self):335 called = []7 unmodified lines343 def root():344 return "Response"345 rv = app.test_client().get('/')346 self.assert_equal(rv.status_code, 200)347- assert 'Response' in rv.data347+ self.assert_('Response' in rv.data)348 self.assert_equal(len(called), 1)349 350 def test_teardown_request_handler_error(self):351 called = []24 unmodified lines376 def fails():377 1/0378 rv = app.test_client().get('/')379 self.assert_equal(rv.status_code, 500)380- assert 'Internal Server Error' in rv.data380+ self.assert_('Internal Server Error' in rv.data)381 self.assert_equal(len(called), 2)382 383 def test_before_after_request_order(self):384 called = []65 unmodified lines450 451 app = flask.Flask(__name__)452 @app.errorhandler(MyException)453 def handle_my_exception(e):454- assert isinstance(e, MyException)454+ self.assert_(isinstance(e, MyException))455 return '42'456 @app.route('/')457 def index():458 raise MyException()14 unmodified lines473 c = app.test_client()474 try:475 c.get('/fail')476 except KeyError, e:477- assert isinstance(e, BadRequest)477+ self.assert_(isinstance(e, BadRequest))478 else:479 self.fail('Expected exception')480 481 def test_trapping_of_all_http_exceptions(self):26 unmodified lines508 with app.test_client() as c:509 try:510 c.post('/fail', data={'foo': 'index.txt'})511 except DebugFilesKeyError, e:512- assert 'no file contents were transmitted' in str(e)513- assert 'This was submitted: "index.txt"' in str(e)512+ self.assert_('no file contents were transmitted' in str(e))513+ self.assert_('This was submitted: "index.txt"' in str(e))514 else:515 self.fail('Expected exception')516 517 def test_teardown_on_pop(self):53 unmodified lines571 def hello():572 pass573 with app.test_request_context():574 self.assert_equal(flask.url_for('hello', name='test x'), '/hello/test%20x')575- assert flask.url_for('hello', name='test x', _external=True) \576- == 'http://localhost/hello/test%20x'575+ self.assert_equal(flask.url_for('hello', name='test x', _external=True),576+ 'http://localhost/hello/test%20x')577 578 def test_custom_converters(self):579 from werkzeug.routing import BaseConverter580 class ListConverter(BaseConverter):15 unmodified lines596 rv = app.test_client().get('/static/index.html')597 self.assert_equal(rv.status_code, 200)598 self.assert_equal(rv.data.strip(), '<h1>Hello World!</h1>')599 with app.test_request_context():600- assert flask.url_for('static', filename='index.html') \601- == '/static/index.html'600+ self.assert_equal(flask.url_for('static', filename='index.html'),601+ '/static/index.html')602 603 def test_none_response(self):604 app = flask.Flask(__name__)605 @app.route('/')4 unmodified lines610 except ValueError, e:611 self.assert_equal(str(e), 'View function did not return a response')612 pass613 else:614- assert "Expected ValueError"614+ self.assert_("Expected ValueError")615 616 def test_request_locals(self):617 self.assert_equal(repr(flask.g), '<LocalProxy unbound>')618 self.assertFalse(flask.g)21 unmodified lines640 try:641 with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):642 pass643 except Exception, e:644- assert isinstance(e, ValueError)644+ self.assert_(isinstance(e, ValueError))645 self.assert_equal(str(e), "the server name provided " +646 "('localhost.localdomain:5000') does not match the " + \647 "server name from the WSGI environment ('localhost')")648 118 unmodified lines767 app.config['MAX_CONTENT_LENGTH'] = 64768 @app.before_request769 def always_first():770 flask.request.form['myfile']771- assert False771+ self.assert_(False)772 @app.route('/accept', methods=['POST'])773 def accept_file():774 flask.request.form['myfile']775- assert False775+ self.assert_(False)776 @app.errorhandler(413)777 def catcher(error):778 return '42'779 108 unmodified lines888 with app.test_request_context('/?name=World'):889 self.assert_equal(index(), 'Hello World!')890 with app.test_request_context('/meh'):891 self.assert_equal(meh(), 'http://localhost/meh')892- assert flask._request_ctx_stack.top is None892+ self.assert_(flask._request_ctx_stack.top is None)893 894 def test_context_test(self):895 app = flask.Flask(__name__)896- assert not flask.request897- assert not flask.has_request_context()896+ self.assert_(not flask.request)897+ self.assert_(not flask.has_request_context())898 ctx = app.test_request_context()899 ctx.push()900 try:901- assert flask.request902- assert flask.has_request_context()901+ self.assert_(flask.request)902+ self.assert_(flask.has_request_context())903 finally:904 ctx.pop()905 906 def test_manual_context_binding(self):10 unmodified lines917 index()918 except RuntimeError:919 pass920 else:921- assert 0, 'expected runtime error'921+ self.assert_(0, 'expected runtime error')922 923 924 class SubdomainTestCase(FlaskTestCase):925 67 unmodified linesmodified:flask/testsuite/blueprints.py+9 added-9 removed
171 unmodified lines172 rv = c.get('/admin/static/css/test.css')173 self.assert_equal(rv.data.strip(), '/* nested file */')174 175 with app.test_request_context():176- assert flask.url_for('admin.static', filename='test.txt') \177- == '/admin/static/test.txt'176+ self.assert_equal(flask.url_for('admin.static', filename='test.txt'),177+ '/admin/static/test.txt')178 179 with app.test_request_context():180 try:181 flask.render_template('missing.html')182 except TemplateNotFound, e:183 self.assert_equal(e.name, 'missing.html')184 else:185- assert 0, 'expected exception'185+ self.assert_(0, 'expected exception')186 187 with flask.Flask(__name__).test_request_context():188 self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')189 7 unmodified lines197 f('/etc/passwd')198 except NotFound:199 pass200 else:201- assert 0, 'expected exception'201+ self.assert_(0, 'expected exception')202 try:203 f('../__init__.py')204 except NotFound:205 pass206 else:207- assert 0, 'expected exception'207+ self.assert_(0, 'expected exception')208 209 # testcase for a security issue that may exist on windows systems210 import os211 import ntpath4 unmodified lines216 f('..\\__init__.py')217 except NotFound:218 pass219 else:220- assert 0, 'expected exception'220+ self.assert_(0, 'expected exception')221 finally:222 os.path = old_path223 224 @emits_module_deprecation_warning129 unmodified lines354 rv = c.get('/admin/static/css/test.css')355 self.assert_equal(rv.data.strip(), '/* nested file */')356 357 with app.test_request_context():358- assert flask.url_for('admin.static', filename='test.txt') \359- == '/admin/static/test.txt'358+ self.assert_equal(flask.url_for('admin.static', filename='test.txt'),359+ '/admin/static/test.txt')360 361 with app.test_request_context():362 try:363 flask.render_template('missing.html')364 except TemplateNotFound, e:365 self.assert_equal(e.name, 'missing.html')366 else:367- assert 0, 'expected exception'367+ self.assert_(0, 'expected exception')368 369 with flask.Flask(__name__).test_request_context():370 self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')371 52 unmodified linesmodified:flask/testsuite/config.py+10 added-10 removed
23 unmodified lines24 25 def common_object_test(self, app):26 self.assert_equal(app.secret_key, 'devkey')27 self.assert_equal(app.config['TEST_KEY'], 'foo')28- assert 'ConfigTestCase' not in app.config28+ self.assert_('ConfigTestCase' not in app.config)29 30 def test_config_from_file(self):31 app = flask.Flask(__name__)32 app.config.from_pyfile(__file__.rsplit('.')[0] + '.py')20 unmodified lines53 app = flask.Flask(__name__)54 try:55 app.config.from_envvar('FOO_SETTINGS')56 except RuntimeError, e:57- assert "'FOO_SETTINGS' is not set" in str(e)57+ self.assert_("'FOO_SETTINGS' is not set" in str(e))58 else:59- assert 0, 'expected exception'60- assert not app.config.from_envvar('FOO_SETTINGS', silent=True)59+ self.assert_(0, 'expected exception')60+ self.assert_(not app.config.from_envvar('FOO_SETTINGS', silent=True))61 62 os.environ = {'FOO_SETTINGS': __file__.rsplit('.')[0] + '.py'}63- assert app.config.from_envvar('FOO_SETTINGS')63+ self.assert_(app.config.from_envvar('FOO_SETTINGS'))64 self.common_object_test(app)65 finally:66 os.environ = env67 2 unmodified lines70 try:71 app.config.from_pyfile('missing.cfg')72 except IOError, e:73 msg = str(e)74- assert msg.startswith('[Errno 2] Unable to load configuration '75- 'file (No such file or directory):')76- assert msg.endswith("missing.cfg'")74+ self.assert_(msg.startswith('[Errno 2] Unable to load configuration '75+ 'file (No such file or directory):'))76+ self.assert_(msg.endswith("missing.cfg'"))77 else:78- assert 0, 'expected config'79- assert not app.config.from_pyfile('missing.cfg', silent=True)78+ self.assert_(0, 'expected config')79+ self.assert_(not app.config.from_pyfile('missing.cfg', silent=True))80 81 82 class InstanceTestCase(FlaskTestCase):83 94 unmodified linesmodified:flask/testsuite/deprecations.py+1 added-1 removed
27 unmodified lines28 29 c = app.test_client()30 self.assert_equal(c.get('/').data, '42')31 self.assert_equal(len(log), 1)32- assert 'init_jinja_globals' in str(log[0]['message'])32+ self.assert_('init_jinja_globals' in str(log[0]['message']))33 34 35 def suite():36 suite = unittest.TestSuite()2 unmodified linesmodified:flask/testsuite/helpers.py+17 added-17 removed
106 unmodified lines107 def test_send_file_regular(self):108 app = flask.Flask(__name__)109 with app.test_request_context():110 rv = flask.send_file('static/index.html')111- assert rv.direct_passthrough111+ self.assert_(rv.direct_passthrough)112 self.assert_equal(rv.mimetype, 'text/html')113 with app.open_resource('static/index.html') as f:114 self.assert_equal(rv.data, f.read())115 1 unmodified line117 app = flask.Flask(__name__)118 app.use_x_sendfile = True119 with app.test_request_context():120 rv = flask.send_file('static/index.html')121- assert rv.direct_passthrough122- assert 'x-sendfile' in rv.headers121+ self.assert_(rv.direct_passthrough)122+ self.assert_('x-sendfile' in rv.headers)123 self.assert_equal(rv.headers['x-sendfile'],124 os.path.join(app.root_path, 'static/index.html'))125 self.assert_equal(rv.mimetype, 'text/html')126 14 unmodified lines141 with app.test_request_context():142 f = open(os.path.join(app.root_path, 'static/index.html'))143 rv = flask.send_file(f)144 self.assert_equal(rv.mimetype, 'text/html')145- assert 'x-sendfile' in rv.headers145+ self.assert_('x-sendfile' in rv.headers)146 self.assert_equal(rv.headers['x-sendfile'],147 os.path.join(app.root_path, 'static/index.html'))148 # mimetypes + etag149 self.assert_equal(len(captured), 2)19 unmodified lines169 with catch_warnings() as captured:170 with app.test_request_context():171 f = StringIO('Test')172 rv = flask.send_file(f)173- assert 'x-sendfile' not in rv.headers173+ self.assert_('x-sendfile' not in rv.headers)174 # etags175 self.assert_equal(len(captured), 1)176 177 def test_attachment(self):28 unmodified lines206 207 def test_logger_cache(self):208 app = flask.Flask(__name__)209 logger1 = app.logger210- assert app.logger is logger1210+ self.assert_(app.logger is logger1)211 self.assert_equal(logger1.name, __name__)212 app.logger_name = __name__ + '/test_logger_cache'213- assert app.logger is not logger1213+ self.assert_(app.logger is not logger1)214 215 def test_debug_log(self):216 app = flask.Flask(__name__)217 app.debug = True11 unmodified lines229 with app.test_client() as c:230 with catch_stderr() as err:231 c.get('/')232 out = err.getvalue()233- assert 'WARNING in helpers [' in out234- assert os.path.basename(__file__.rsplit('.')[0] + '.py') in out235- assert 'the standard library is dead' in out236- assert 'this is a debug statement' in out233+ self.assert_('WARNING in helpers [' in out)234+ self.assert_(os.path.basename(__file__.rsplit('.')[0] + '.py') in out)235+ self.assert_('the standard library is dead' in out)236+ self.assert_('this is a debug statement' in out)237 238 with catch_stderr() as err:239 try:240 c.get('/exc')241 except ZeroDivisionError:242 pass243 else:244- assert False, 'debug log ate the exception'244+ self.assert_(False, 'debug log ate the exception')245 246 def test_exception_logging(self):247 out = StringIO()248 app = flask.Flask(__name__)5 unmodified lines254 1/0255 256 rv = app.test_client().get('/')257 self.assert_equal(rv.status_code, 500)258- assert 'Internal Server Error' in rv.data258+ self.assert_('Internal Server Error' in rv.data)259 260 err = out.getvalue()261- assert 'Exception on / [GET]' in err262- assert 'Traceback (most recent call last):' in err263- assert '1/0' in err264- assert 'ZeroDivisionError:' in err261+ self.assert_('Exception on / [GET]' in err)262+ self.assert_('Traceback (most recent call last):' in err)263+ self.assert_('1/0' in err)264+ self.assert_('ZeroDivisionError:' in err)265 266 def test_processor_exceptions(self):267 app = flask.Flask(__name__)268 @app.before_request27 unmodified linesmodified:flask/testsuite/signals.py+1 added-1 removed
89 unmodified lines90 flask.got_request_exception.connect(record, app)91 try:92 self.assert_equal(app.test_client().get('/').status_code, 500)93 self.assert_equal(len(recorded), 1)94- assert isinstance(recorded[0], ZeroDivisionError)94+ self.assert_(isinstance(recorded[0], ZeroDivisionError))95 finally:96 flask.got_request_exception.disconnect(record, app)97 98 5 unmodified linesmodified:flask/testsuite/templating.py+6 added-6 removed
68 unmodified lines69 70 def test_no_escaping(self):71 app = flask.Flask(__name__)72 with app.test_request_context():73- assert flask.render_template_string('{{ foo }}',74- foo='<test>') == '<test>'75- assert flask.render_template('mail.txt', foo='<test>') \76- == '<test> Mail'73+ self.assert_equal(flask.render_template_string('{{ foo }}',74+ foo='<test>'), '<test>')75+ self.assert_equal(flask.render_template('mail.txt', foo='<test>'),76+ '<test> Mail')77 78 def test_macros(self):79 app = flask.Flask(__name__)80 with app.test_request_context():4 unmodified lines85 app = flask.Flask(__name__)86 @app.template_filter()87 def my_reverse(s):88 return s[::-1]89- assert 'my_reverse' in app.jinja_env.filters.keys()89+ self.assert_('my_reverse' in app.jinja_env.filters.keys())90 self.assert_equal(app.jinja_env.filters['my_reverse'], my_reverse)91 self.assert_equal(app.jinja_env.filters['my_reverse']('abcd'), 'dcba')92 93 def test_template_filter_with_name(self):94 app = flask.Flask(__name__)95 @app.template_filter('strrev')96 def my_reverse(s):97 return s[::-1]98- assert 'strrev' in app.jinja_env.filters.keys()98+ self.assert_('strrev' in app.jinja_env.filters.keys())99 self.assert_equal(app.jinja_env.filters['strrev'], my_reverse)100 self.assert_equal(app.jinja_env.filters['strrev']('abcd'), 'dcba')101 102 def test_template_filter_with_template(self):39 unmodified linesmodified:flask/testsuite/testing.py+2 added-2 removed
100 unmodified lines101 self.assert_equal(resp.data, 'Hello World!')102 self.assert_equal(resp.status_code, 200)103 104 resp = c.get('/other')105- assert not hasattr(flask.g, 'value')106- assert 'Internal Server Error' in resp.data105+ self.assert_(not hasattr(flask.g, 'value'))106+ self.assert_('Internal Server Error' in resp.data)107 self.assert_equal(resp.status_code, 500)108 flask.g.value = 23109 110 try:11 unmodified lines