mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Added util.make_repr() function; added corresponding unit tests
This commit is contained in:
@@ -227,6 +227,7 @@ class Param(plugable.ReadOnly):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, name, **override):
|
def __init__(self, name, **override):
|
||||||
|
self.__override = override
|
||||||
if not ('required' in override or 'multivalue' in override):
|
if not ('required' in override or 'multivalue' in override):
|
||||||
(name, kw_from_spec) = parse_param_spec(name)
|
(name, kw_from_spec) = parse_param_spec(name)
|
||||||
override.update(kw_from_spec)
|
override.update(kw_from_spec)
|
||||||
|
|||||||
@@ -137,3 +137,12 @@ class LogFormatter(logging.Formatter):
|
|||||||
Log formatter that uses UTC for all timestamps.
|
Log formatter that uses UTC for all timestamps.
|
||||||
"""
|
"""
|
||||||
converter = time.gmtime
|
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():
|
def test_xmlrpc_marshal():
|
||||||
"""
|
"""
|
||||||
Test the `util.xmlrpc_marshal` function.
|
Test the `ipalib.util.xmlrpc_marshal` function.
|
||||||
"""
|
"""
|
||||||
f = util.xmlrpc_marshal
|
f = util.xmlrpc_marshal
|
||||||
assert f() == ({},)
|
assert f() == ({},)
|
||||||
@@ -39,7 +39,7 @@ def test_xmlrpc_marshal():
|
|||||||
|
|
||||||
def test_xmlrpc_unmarshal():
|
def test_xmlrpc_unmarshal():
|
||||||
"""
|
"""
|
||||||
Test the `util.xmlrpc_unmarshal` function.
|
Test the `ipalib.util.xmlrpc_unmarshal` function.
|
||||||
"""
|
"""
|
||||||
f = util.xmlrpc_unmarshal
|
f = util.xmlrpc_unmarshal
|
||||||
assert f() == (tuple(), {})
|
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(one=1, two=2)) == (tuple(), dict(one=1, two=2))
|
||||||
assert f(dict(three=3, four=4), 'one', 'two') == \
|
assert f(dict(three=3, four=4), 'one', 'two') == \
|
||||||
(('one', 'two'), dict(three=3, four=4))
|
(('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')"
|
||||||
|
|||||||
Reference in New Issue
Block a user