From 4d1681176afc45c57fb4316892f939bda1bacf1d Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 18 Dec 2008 02:08:41 -0700 Subject: New Param: added unit tests for TypeError cases in DefaultFrom.__init__() --- ipalib/constants.py | 2 +- ipalib/parameter.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'ipalib') diff --git a/ipalib/constants.py b/ipalib/constants.py index ad1e3f7c..ef2aef72 100644 --- a/ipalib/constants.py +++ b/ipalib/constants.py @@ -29,7 +29,7 @@ NULLS = (None, '', u'', tuple(), []) TYPE_ERROR = '%s: need a %r; got %r (which is a %r)' -CALLABLE_ERROR = '%s: need a callable; got %r (a %r)' +CALLABLE_ERROR = '%s: need a callable; got %r (which is a %r)' # Used for a tab (or indentation level) when formatting for CLI: diff --git a/ipalib/parameter.py b/ipalib/parameter.py index ca578cd9..fca95b0e 100644 --- a/ipalib/parameter.py +++ b/ipalib/parameter.py @@ -103,7 +103,9 @@ class DefaultFrom(ReadOnly): :param keys: Optional keys used for source values. """ if not callable(callback): - raise TypeError('callback must be callable; got %r' % callback) + raise TypeError( + CALLABLE_ERROR % ('callback', callback, type(callback)) + ) self.callback = callback if len(keys) == 0: fc = callback.func_code @@ -112,7 +114,9 @@ class DefaultFrom(ReadOnly): self.keys = keys for key in self.keys: if type(key) is not str: - raise_TypeError(key, str, 'keys') + raise TypeError( + TYPE_ERROR % ('keys', str, key, type(key)) + ) lock(self) def __call__(self, **kw): -- cgit