From 6610e857e3c56ac9c2916c5f3b79cd736c1f2299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Sun, 5 Jul 2009 13:29:24 +0000 Subject: [PATCH] [soc2009/model-validation] Minor simplification of validator tests git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11192 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/validators/tests.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py index e19353d03b..1541c5aab9 100644 --- a/tests/modeltests/validators/tests.py +++ b/tests/modeltests/validators/tests.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import types from unittest import TestCase from django.core.exceptions import ValidationError @@ -63,13 +64,17 @@ def get_simple_test_func(validator, expected, value, num): test_mask = 'test_%s_%d' def test_func(self): self.assertEqual(expected, validator(value)) - test_name = test_mask % (validator.__name__, num) + if isinstance(validator, types.FunctionType): + val_name = validator.__name__ + else: + val_name = validator.__class__.__name__ + test_name = test_mask % (val_name, num) return test_name, test_func -test_counter = {} +test_counter = 0 for validator, value, expected in SIMPLE_VALIDATORS_VALUES: - num = test_counter[validator] = test_counter.setdefault(validator, 0) + 1 - setattr(TestSimpleValidators, *get_simple_test_func(validator, expected, value, num)) + setattr(TestSimpleValidators, *get_simple_test_func(validator, expected, value, test_counter)) + test_counter += 1 class TestComplexValidators(TestCase): pass