New Param: ported Param.__repr__() and corresponding unit test

This commit is contained in:
Jason Gerard DeRose committed 2008-12-18 11:21:12 -07:00
1 parent 4d1681176a
commit 46e37ab144
2 files changed
+23

No files matched your search

+11
View File
@@ -24,6 +24,7 @@ Parameter system for command plugins.
from types import NoneType
from plugable import ReadOnly, lock, check_name
from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR
from util import make_repr
class DefaultFrom(ReadOnly):
@@ -287,6 +288,16 @@ class Param(ReadOnly):
# And we're done.
lock(self)
def __repr__(self):
"""
Return an expresion that could construct this `Param` instance.
"""
return make_repr(
self.__class__.__name__,
self.param_spec,
**self.__kw
)
def normalize(self, value):
"""
Normalize ``value`` using normalizer callback.
+12
View File
@@ -188,6 +188,18 @@ class test_Param(ClassChecker):
assert str(e) == \
"Param('my_param'): takes no such kwargs: 'ape', 'great'"
def test_repr(self):
"""
Test the `ipalib.parameter.Param.__repr__` method.
"""
for name in ['name', 'name?', 'name*', 'name+']:
o = self.cls(name)
assert repr(o) == 'Param(%r)' % name
o = self.cls('name', required=False)
assert repr(o) == "Param('name', required=False)"
o = self.cls('name', multivalue=True)
assert repr(o) == "Param('name', multivalue=True)"
def test_convert(self):
"""
Test the `ipalib.parameter.Param.convert` method.