mirror of
https://github.com/django/django.git
synced 2025-07-07 19:29:12 +00:00
[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
This commit is contained in:
parent
c1093ca87f
commit
6610e857e3
@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import types
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@ -63,13 +64,17 @@ def get_simple_test_func(validator, expected, value, num):
|
|||||||
test_mask = 'test_%s_%d'
|
test_mask = 'test_%s_%d'
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
self.assertEqual(expected, validator(value))
|
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
|
return test_name, test_func
|
||||||
|
|
||||||
test_counter = {}
|
test_counter = 0
|
||||||
for validator, value, expected in SIMPLE_VALIDATORS_VALUES:
|
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, test_counter))
|
||||||
setattr(TestSimpleValidators, *get_simple_test_func(validator, expected, value, num))
|
test_counter += 1
|
||||||
|
|
||||||
class TestComplexValidators(TestCase):
|
class TestComplexValidators(TestCase):
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user