Skip to content

Commit

Permalink
Raise an error with a useful message if the app is not setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwg4 authored and Jack Grahl committed May 16, 2018
1 parent b07dfc8 commit 2bdff9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions flask_selfdoc/autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def html(self, groups='all', template=None, **context):
By specifying the group or groups arguments, only routes belonging to
those groups will be returned.
"""
if not self.app:
raise RuntimeError("Autodoc was not initialized with the Flask app.")
context['autodoc'] = context['autodoc'] if 'autodoc' in context \
else self.generate(groups=groups)
context['defaults'] = context['defaults'] if 'defaults' in context \
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def readme():
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
],
test_suite='tests.test_autodoc',
test_suite='tests',
)
13 changes: 13 additions & 0 deletions tests/test_error_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest

from flask import Flask
from flask_autodoc import Autodoc


class TestErrorHandling(unittest.TestCase):
def test_app_not_initialized(self):
app = Flask(__name__)
app.debug = True
autodoc = Autodoc()
with app.app_context():
self.assertRaises(RuntimeError, lambda: autodoc.html())

0 comments on commit 2bdff9c

Please sign in to comment.