From 74198f4542375af65772deb3b078657edb6ad4b4 Mon Sep 17 00:00:00 2001 From: Grey Li Date: Wed, 15 Nov 2023 22:18:25 +0800 Subject: [PATCH] Fix unit test and lint issues --- example/app.py | 8 +++----- src/flask_debugtoolbar/panels/profiler.py | 4 ++-- src/flask_debugtoolbar/utils.py | 1 + test/basic_app.py | 12 ++++++------ test/test_toolbar.py | 1 - tox.ini | 2 +- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/example/app.py b/example/app.py index 77c688e..5e5d9ad 100644 --- a/example/app.py +++ b/example/app.py @@ -22,17 +22,15 @@ db = SQLAlchemy(app) toolbar = DebugToolbarExtension(app) +with app.app_context(): + db.create_all() + class ExampleModel(db.Model): __tablename__ = 'examples' value = db.Column(db.String(100), primary_key=True) -@app.before_first_request -def setup(): - db.create_all() - - @app.route('/') def index(): app.logger.info("Hello there") diff --git a/src/flask_debugtoolbar/panels/profiler.py b/src/flask_debugtoolbar/panels/profiler.py index 3294e4a..66f22aa 100644 --- a/src/flask_debugtoolbar/panels/profiler.py +++ b/src/flask_debugtoolbar/panels/profiler.py @@ -94,7 +94,7 @@ def process_response(self, request, response): def title(self): if not self.is_active: return "Profiler not active" - return 'View: %.2fms' % (float(self.stats.total_tt)*1000,) + return 'View: %.2fms' % (float(self.stats.total_tt) * 1000,) def nav_title(self): return 'Profiler' @@ -102,7 +102,7 @@ def nav_title(self): def nav_subtitle(self): if not self.is_active: return "in-active" - return 'View: %.2fms' % (float(self.stats.total_tt)*1000,) + return 'View: %.2fms' % (float(self.stats.total_tt) * 1000,) def url(self): return '' diff --git a/src/flask_debugtoolbar/utils.py b/src/flask_debugtoolbar/utils.py index 267a2e3..76957e1 100644 --- a/src/flask_debugtoolbar/utils.py +++ b/src/flask_debugtoolbar/utils.py @@ -88,6 +88,7 @@ def format_sql(query, args): SqlLexer(), HtmlFormatter(noclasses=True, style=PYGMENT_STYLE))) + def gzip_compress(data, compresslevel=6): buff = io.BytesIO() with gzip.GzipFile(fileobj=buff, mode='wb', compresslevel=compresslevel) as f: diff --git a/test/basic_app.py b/test/basic_app.py index 6ec1ddd..98dac60 100644 --- a/test/basic_app.py +++ b/test/basic_app.py @@ -4,10 +4,12 @@ from flask_debugtoolbar import DebugToolbarExtension app = Flask('basic_app') +app.config['DEBUG'] = True app.config['SECRET_KEY'] = 'abc123' app.config['SQLALCHEMY_RECORD_QUERIES'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' -# This is no longer needed for Flask-SQLAlchemy 3.0+, if you're using 2.X you'll want to define this: +# This is no longer needed for Flask-SQLAlchemy 3.0+, +# if you're using 2.X you'll want to define this: # app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # make sure these are printable in the config panel @@ -17,17 +19,15 @@ toolbar = DebugToolbarExtension(app) db = SQLAlchemy(app) +with app.app_context(): + db.create_all() + class Foo(db.Model): __tablename__ = 'foo' id = db.Column(db.Integer, primary_key=True) -@app.before_first_request -def setup(): - db.create_all() - - @app.route('/') def index(): Foo.query.filter_by(id=1).all() diff --git a/test/test_toolbar.py b/test/test_toolbar.py index fd04ddc..8624ee3 100644 --- a/test/test_toolbar.py +++ b/test/test_toolbar.py @@ -7,7 +7,6 @@ def load_app(name): app = __import__(name).app - app.config['TESTING'] = True return app.test_client() diff --git a/tox.ini b/tox.ini index 6483179..324525d 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ commands = deps = pycodestyle commands = - pycodestyle flask_debugtoolbar test + pycodestyle src/flask_debugtoolbar test --ignore=E731,W503,W504 [pycodestyle] max-line-length = 100