diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 56c4ea01f..87126a440 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -227,6 +227,7 @@ class Param(plugable.ReadOnly): ) def __init__(self, name, **override): + self.__override = override if not ('required' in override or 'multivalue' in override): (name, kw_from_spec) = parse_param_spec(name) override.update(kw_from_spec) diff --git a/ipalib/util.py b/ipalib/util.py index 9bc432545..89e2c5a74 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -137,3 +137,12 @@ class LogFormatter(logging.Formatter): Log formatter that uses UTC for all timestamps. """ converter = time.gmtime + + +def make_repr(name, *args, **kw): + """ + Construct a standard representation of a class instance. + """ + args = [repr(a) for a in args] + kw = ['%s=%r' % (k, kw[k]) for k in sorted(kw)] + return '%s(%s)' % (name, ', '.join(args + kw)) diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index 04ff23f09..6729fcda5 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -27,7 +27,7 @@ from ipalib import util def test_xmlrpc_marshal(): """ - Test the `util.xmlrpc_marshal` function. + Test the `ipalib.util.xmlrpc_marshal` function. """ f = util.xmlrpc_marshal assert f() == ({},) @@ -39,7 +39,7 @@ def test_xmlrpc_marshal(): def test_xmlrpc_unmarshal(): """ - Test the `util.xmlrpc_unmarshal` function. + Test the `ipalib.util.xmlrpc_unmarshal` function. """ f = util.xmlrpc_unmarshal assert f() == (tuple(), {}) @@ -47,3 +47,15 @@ def test_xmlrpc_unmarshal(): assert f(dict(one=1, two=2)) == (tuple(), dict(one=1, two=2)) assert f(dict(three=3, four=4), 'one', 'two') == \ (('one', 'two'), dict(three=3, four=4)) + + +def test_make_repr(): + """ + Test the `ipalib.util.make_repr` function. + """ + f = util.make_repr + assert f('my') == 'my()' + assert f('my', True, u'hello') == "my(True, u'hello')" + assert f('my', one=1, two='two') == "my(one=1, two='two')" + assert f('my', None, 3, dog='animal', apple='fruit') == \ + "my(None, 3, apple='fruit', dog='animal')"