From dd966f081a36cc3ee87f703bf81e821f3500fbb1 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sun, 5 Apr 2009 17:54:02 +0000 Subject: [PATCH] Fixed the test case from [10399] to be more robust against the order in which test cases are executed. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10402 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/signals/models.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/modeltests/signals/models.py b/tests/modeltests/signals/models.py index 06fd3a6fb3..ea8137f657 100644 --- a/tests/modeltests/signals/models.py +++ b/tests/modeltests/signals/models.py @@ -39,6 +39,14 @@ class PostDeleteHandler(object): post_delete_test = PostDeleteHandler() __test__ = {'API_TESTS':""" + +# Save up the number of connected signals so that we can check at the end +# that all the signals we register get properly unregistered (#9989) +>>> pre_signals = (len(models.signals.pre_save.receivers), +... len(models.signals.post_save.receivers), +... len(models.signals.pre_delete.receivers), +... len(models.signals.post_delete.receivers)) + >>> models.signals.pre_save.connect(pre_save_test) >>> models.signals.post_save.connect(post_save_test) >>> models.signals.pre_delete.connect(pre_delete_test) @@ -97,14 +105,13 @@ instance.id is None: False >>> models.signals.post_save.disconnect(post_save_test) >>> models.signals.pre_save.disconnect(pre_save_test) -# Make sure all the signals got removed properly (#9989) ->>> models.signals.post_delete.receivers -[] ->>> models.signals.pre_delete.receivers -[] ->>> models.signals.post_save.receivers -[] ->>> models.signals.pre_save.receivers -[] +# Check that all our signals got disconnected properly. +>>> post_signals = (len(models.signals.pre_save.receivers), +... len(models.signals.post_save.receivers), +... len(models.signals.pre_delete.receivers), +... len(models.signals.post_delete.receivers)) + +>>> pre_signals == post_signals +True """}