add tests and determinism to format_invocation

This commit is contained in:
Mahmoud Hashemi 2019-11-05 18:27:02 -08:00
parent 626df0f696
commit f4188bd9d1
2 changed files with 9 additions and 1 deletions

View File

@ -296,7 +296,7 @@ def format_invocation(name='', args=(), kwargs=None):
kwargs = kwargs or {}
a_text = ', '.join([repr(a) for a in args])
if isinstance(kwargs, dict):
kwarg_items = kwargs.items()
kwarg_items = [(k, kwargs[k]) for k in sorted(kwargs)]
else:
kwarg_items = kwargs
kw_text = ', '.join(['%s=%r' % (k, v) for k, v in kwarg_items])

View File

@ -2,6 +2,7 @@
from boltons.funcutils import (copy_function,
total_ordering,
format_invocation,
InstancePartial,
CachedInstancePartial)
@ -61,3 +62,10 @@ def test_total_ordering():
assert num < 5
assert num >= 2
assert num != 1
def test_format_invocation():
assert format_invocation('d') == "d()"
assert format_invocation('f', ('a', 'b')) == "f('a', 'b')"
assert format_invocation('g', (), {'x': 'y'}) == "g(x='y')"
assert format_invocation('h', ('a', 'b'), {'x': 'y', 'z': 'zz'}) == "h('a', 'b', x='y', z='zz')"