Browse Source

Refactor test codes to PEP8 recommendation

- '== cond' to 'is cond'
ex) app.templates_auto_reload == False to app.templates_auto_reload is False
- Change about blank lines
- Change field variable names intuitively
- Change about blank lines
- Change about continuation line's visual indent
- Change about importation
pull/2641/head
JoMingyu 7 years ago
parent
commit
137b75d319
  1. 4
      tests/test_apps/blueprintapp/__init__.py
  2. 1
      tests/test_apps/helloworld/hello.py
  3. 1
      tests/test_basic.py
  4. 25
      tests/test_helpers.py
  5. 9
      tests/test_templating.py

4
tests/test_apps/blueprintapp/__init__.py

@ -1,8 +1,8 @@
from flask import Flask
from blueprintapp.apps.admin import admin
from blueprintapp.apps.frontend import frontend
app = Flask(__name__)
app.config['DEBUG'] = True
from blueprintapp.apps.admin import admin
from blueprintapp.apps.frontend import frontend
app.register_blueprint(admin)
app.register_blueprint(frontend)

1
tests/test_apps/helloworld/hello.py

@ -1,6 +1,7 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"

1
tests/test_basic.py

@ -1550,7 +1550,6 @@ def test_max_content_length(app, client):
def test_url_processors(app, client):
@app.url_defaults
def add_language_code(endpoint, values):
if flask.g.lang_code is not None and \

25
tests/test_helpers.py

@ -144,27 +144,27 @@ class TestJSON(object):
def test_jsonify_dicts(self, app, client):
"""Test jsonify with dicts and kwargs unpacking."""
d = {'a': 0, 'b': 23, 'c': 3.14, 'd': 't',
data = {'a': 0, 'b': 23, 'c': 3.14, 'd': 't',
'e': 'Hi', 'f': True, 'g': False,
'h': ['test list', 10, False],
'i': {'test': 'dict'}}
@app.route('/kw')
def return_kwargs():
return flask.jsonify(**d)
return flask.jsonify(**data)
@app.route('/dict')
def return_dict():
return flask.jsonify(d)
return flask.jsonify(data)
for url in '/kw', '/dict':
rv = client.get(url)
assert rv.mimetype == 'application/json'
assert flask.json.loads(rv.data) == d
assert flask.json.loads(rv.data) == data
def test_jsonify_arrays(self, app, client):
"""Test jsonify of lists and args unpacking."""
l = [
arr = [
0, 42, 3.14, 't', 'hello', True, False,
['test list', 2, False],
{'test': 'dict'}
@ -172,16 +172,16 @@ class TestJSON(object):
@app.route('/args_unpack')
def return_args_unpack():
return flask.jsonify(*l)
return flask.jsonify(*arr)
@app.route('/array')
def return_array():
return flask.jsonify(l)
return flask.jsonify(arr)
for url in '/args_unpack', '/array':
rv = client.get(url)
assert rv.mimetype == 'application/json'
assert flask.json.loads(rv.data) == l
assert flask.json.loads(rv.data) == arr
def test_jsonify_date_types(self, app, client):
"""Test jsonify with datetime.date and datetime.datetime types."""
@ -342,7 +342,7 @@ class TestJSON(object):
def test_json_key_sorting(self, app, client):
app.debug = True
assert app.config['JSON_SORT_KEYS'] == True
assert app.config['JSON_SORT_KEYS'] is True
d = dict.fromkeys(range(20), 'foo')
@app.route('/')
@ -686,7 +686,6 @@ class TestSendfile(object):
class TestUrlFor(object):
def test_url_for_with_anchor(self, app, req_ctx):
@app.route('/')
def index():
return '42'
@ -694,7 +693,6 @@ class TestUrlFor(object):
assert flask.url_for('index', _anchor='x y') == '/#x%20y'
def test_url_for_with_scheme(self, app, req_ctx):
@app.route('/')
def index():
return '42'
@ -702,7 +700,6 @@ class TestUrlFor(object):
assert flask.url_for('index', _external=True, _scheme='https') == 'https://localhost/'
def test_url_for_with_scheme_not_external(self, app, req_ctx):
@app.route('/')
def index():
return '42'
@ -713,7 +710,6 @@ class TestUrlFor(object):
_scheme='https')
def test_url_for_with_alternating_schemes(self, app, req_ctx):
@app.route('/')
def index():
return '42'
@ -768,7 +764,6 @@ class TestNoImports(object):
class TestStreaming(object):
def test_streaming_with_context(self, app, client):
@app.route('/')
def index():
def generate():
@ -782,7 +777,6 @@ class TestStreaming(object):
assert rv.data == b'Hello World!'
def test_streaming_with_context_as_decorator(self, app, client):
@app.route('/')
def index():
@flask.stream_with_context
@ -883,6 +877,7 @@ class TestSafeJoin(object):
with pytest.raises(NotFound):
print(flask.safe_join(*args))
class TestHelpers(object):
@pytest.mark.parametrize('debug, expected_flag, expected_default_flag', [

9
tests/test_templating.py

@ -384,6 +384,7 @@ def test_templates_auto_reload(app):
app.config['TEMPLATES_AUTO_RELOAD'] = True
assert app.jinja_env.auto_reload is True
def test_templates_auto_reload_debug_run(app, monkeypatch):
def run_simple_mock(*args, **kwargs):
pass
@ -391,12 +392,12 @@ def test_templates_auto_reload_debug_run(app, monkeypatch):
monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)
app.run()
assert app.templates_auto_reload == False
assert app.jinja_env.auto_reload == False
assert app.templates_auto_reload is False
assert app.jinja_env.auto_reload is False
app.run(debug=True)
assert app.templates_auto_reload == True
assert app.jinja_env.auto_reload == True
assert app.templates_auto_reload is True
assert app.jinja_env.auto_reload is True
def test_template_loader_debugging(test_apps, monkeypatch):

Loading…
Cancel
Save