From dd6b2574c9d40c4777da71d576f6e5eea1712404 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Tue, 2 Sep 2014 05:10:16 +0200 Subject: [PATCH] Rework test_signals --- tests/test_signals.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/test_signals.py b/tests/test_signals.py index db3287e5..fbbfda61 100644 --- a/tests/test_signals.py +++ b/tests/test_signals.py @@ -9,11 +9,22 @@ :license: BSD, see LICENSE for more details. """ +import pytest + +try: + import blinker +except ImportError: + blinker = None + import flask -import unittest from tests import TestFlask +pytestmark = pytest.mark.skipif( + blinker is None, + reason='Signals require the blinker library.' +) + class TestSignals(TestFlask): def test_template_rendered(self): @@ -24,6 +35,7 @@ class TestSignals(TestFlask): return flask.render_template('simple_template.html', whiskey=42) recorded = [] + def record(sender, template, context): recorded.append((template, context)) @@ -71,8 +83,8 @@ class TestSignals(TestFlask): self.assert_equal(rv.data, b'stuff') self.assert_equal(calls, ['before-signal', 'before-handler', - 'handler', 'after-handler', - 'after-signal']) + 'handler', 'after-handler', + 'after-signal']) finally: flask.request_started.disconnect(before_request_signal, app) flask.request_finished.disconnect(after_request_signal, app) @@ -99,8 +111,10 @@ class TestSignals(TestFlask): def test_appcontext_signals(self): app = flask.Flask(__name__) recorded = [] + def record_push(sender, **kwargs): recorded.append('push') + def record_pop(sender, **kwargs): recorded.append('pop') @@ -130,6 +144,7 @@ class TestSignals(TestFlask): return flask.redirect('/other') recorded = [] + def record(sender, message, category): recorded.append((message, category)) @@ -144,10 +159,3 @@ class TestSignals(TestFlask): self.assert_equal(category, 'notice') finally: flask.message_flashed.disconnect(record, app) - - -def suite(): - suite = unittest.TestSuite() - if flask.signals_available: - suite.addTest(unittest.makeSuite(TestSignals)) - return suite