Permalink
Browse files

Split up testsuite and moved it to flask.testsuite. This fixes #246

  • Loading branch information...
mitsuhiko committed Aug 26, 2011
1 parent 85ed1bf commit 4cb6eea8f1e1edc707874f72cbca43a0f698ec7d
Showing with 2,575 additions and 2,336 deletions.
  1. +121 −0 flask/testsuite/__init__.py
  2. +992 −0 flask/testsuite/basic.py
  3. +423 −0 flask/testsuite/blueprints.py
  4. +177 −0 flask/testsuite/config.py
  5. +38 −0 flask/testsuite/deprecations.py
  6. +38 −0 flask/testsuite/examples.py
  7. +295 −0 flask/testsuite/helpers.py
  8. +103 −0 flask/testsuite/signals.py
  9. 0 {tests → flask/testsuite}/static/index.html
  10. 0 {tests → flask/testsuite}/templates/_macro.html
  11. 0 {tests → flask/testsuite}/templates/context_template.html
  12. 0 {tests → flask/testsuite}/templates/escaping_template.html
  13. 0 {tests → flask/testsuite}/templates/mail.txt
  14. 0 {tests → flask/testsuite}/templates/nested/nested.txt
  15. 0 {tests → flask/testsuite}/templates/simple_template.html
  16. 0 {tests → flask/testsuite}/templates/template_filter.html
  17. +141 −0 flask/testsuite/templating.py
  18. 0 {tests → flask/testsuite/test_apps}/blueprintapp/__init__.py
  19. 0 {tests → flask/testsuite/test_apps}/blueprintapp/apps/__init__.py
  20. 0 {tests → flask/testsuite/test_apps}/blueprintapp/apps/admin/__init__.py
  21. 0 {tests → flask/testsuite/test_apps}/blueprintapp/apps/admin/static/css/test.css
  22. 0 {tests → flask/testsuite/test_apps}/blueprintapp/apps/admin/static/test.txt
  23. 0 {tests → flask/testsuite/test_apps}/blueprintapp/apps/admin/templates/admin/index.html
  24. 0 {tests → flask/testsuite/test_apps}/blueprintapp/apps/frontend/__init__.py
  25. 0 {tests → flask/testsuite/test_apps}/blueprintapp/apps/frontend/templates/frontend/index.html
  26. +4 −0 flask/testsuite/test_apps/config_module_app.py
  27. +4 −0 flask/testsuite/test_apps/config_package_app/__init__.py
  28. 0 {tests → flask/testsuite/test_apps}/moduleapp/__init__.py
  29. 0 {tests → flask/testsuite/test_apps}/moduleapp/apps/__init__.py
  30. 0 {tests → flask/testsuite/test_apps}/moduleapp/apps/admin/__init__.py
  31. 0 {tests → flask/testsuite/test_apps}/moduleapp/apps/admin/static/css/test.css
  32. 0 {tests → flask/testsuite/test_apps}/moduleapp/apps/admin/static/test.txt
  33. 0 {tests → flask/testsuite/test_apps}/moduleapp/apps/admin/templates/index.html
  34. 0 {tests → flask/testsuite/test_apps}/moduleapp/apps/frontend/__init__.py
  35. 0 {tests → flask/testsuite/test_apps}/moduleapp/apps/frontend/templates/index.html
  36. 0 {tests → flask/testsuite/test_apps}/subdomaintestmodule/__init__.py
  37. 0 {tests → flask/testsuite/test_apps}/subdomaintestmodule/static/hello.txt
  38. +121 −0 flask/testsuite/testing.py
  39. +117 −0 flask/testsuite/views.py
  40. 0 {tests → scripts}/flaskext_test.py
  41. +1 −7 setup.py
  42. +0 −2,329 tests/flask_tests.py
View
@@ -0,0 +1,121 @@
+# -*- coding: utf-8 -*-
+"""
+ flask.testsuite
+ ~~~~~~~~~~~~~~~
+
+ Tests Flask itself. The majority of Flask is already tested
+ as part of Werkzeug.
+
+ :copyright: (c) 2011 by Armin Ronacher.
+ :license: BSD, see LICENSE for more details.
+"""
+import os
+import sys
+import flask
+import warnings
+import unittest
+from StringIO import StringIO
+from functools import update_wrapper
+from contextlib import contextmanager
+from werkzeug.utils import import_string, find_modules
+
+
+def add_to_path(path):
+ def _samefile(x, y):
+ try:
+ return os.path.samefile(x, y)
+ except (IOError, OSError):
+ return False
+ for entry in sys.path:
+ try:
+ if os.path.samefile(path, entry):
+ return
+ except (OSError, IOError):
+ pass
+ sys.path.append(path)
+
+
+def setup_paths():
+ add_to_path(os.path.abspath(os.path.join(
+ os.path.dirname(__file__), 'test_apps')))
+
+
+def iter_suites():
+ for module in find_modules(__name__):
+ mod = import_string(module)
+ if hasattr(mod, 'suite'):
+ yield mod.suite()
+
+
+@contextmanager
+def catch_warnings():
+ """Catch warnings in a with block in a list"""
+ # make sure deprecation warnings are active in tests
+ warnings.simplefilter('default', category=DeprecationWarning)
+
+ filters = warnings.filters
+ warnings.filters = filters[:]
+ old_showwarning = warnings.showwarning
+ log = []
+ def showwarning(message, category, filename, lineno, file=None, line=None):
+ log.append(locals())
+ try:
+ warnings.showwarning = showwarning
+ yield log
+ finally:
+ warnings.filters = filters
+ warnings.showwarning = old_showwarning
+
+
+@contextmanager
+def catch_stderr():
+ """Catch stderr in a StringIO"""
+ old_stderr = sys.stderr
+ sys.stderr = rv = StringIO()
+ try:
+ yield rv
+ finally:
+ sys.stderr = old_stderr
+
+
+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')
+ for entry in log:
+ self.assert_('Modules are deprecated' in str(entry['message']))
+ return update_wrapper(new_f, f)
+
+
+class FlaskTestCase(unittest.TestCase):
+
+ def ensure_clean_request_context(self):
+ # make sure we're not leaking a request context since we are
+ # testing flask internally in debug mode in a few cases
+ self.assert_equal(flask._request_ctx_stack.top, None)
+
+ def setup(self):
+ pass
+
+ def teardown(self):
+ pass
+
+ def setUp(self):
+ self.setup()
+
+ def tearDown(self):
+ unittest.TestCase.tearDown(self)
+ self.ensure_clean_request_context()
+ self.teardown()
+
+ def assert_equal(self, x, y):
+ return self.assertEqual(x, y)
+
+
+def suite():
+ setup_paths()
+ suite = unittest.TestSuite()
+ for other_suite in iter_suites():
+ suite.addTest(other_suite)
+ return suite
Oops, something went wrong.

0 comments on commit 4cb6eea

Please sign in to comment.