From f4188bd9d1067998530a297c4d8c4c0606f04e71 Mon Sep 17 00:00:00 2001 From: Mahmoud Hashemi Date: Tue, 5 Nov 2019 18:27:02 -0800 Subject: [PATCH] add tests and determinism to format_invocation --- boltons/funcutils.py | 2 +- tests/test_funcutils.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/boltons/funcutils.py b/boltons/funcutils.py index f715250..6c5fb84 100644 --- a/boltons/funcutils.py +++ b/boltons/funcutils.py @@ -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]) diff --git a/tests/test_funcutils.py b/tests/test_funcutils.py index a0047a3..a4b6793 100644 --- a/tests/test_funcutils.py +++ b/tests/test_funcutils.py @@ -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')"