mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 23:50:03 -06:00
Added util.make_repr() function; added corresponding unit tests
This commit is contained in:
parent
01a7f1f437
commit
8ad5502354
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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')"
|
||||
|
Loading…
Reference in New Issue
Block a user