# HG changeset patch
# User Martijn Pieters <mj@zopatista.com>
# Date 1533149854 -7200
#      Wed Aug 01 20:57:34 2018 +0200
# Node ID 357ed3a95baa035831444a457bdaaae510460fb9
# Parent  fdff9b6ce64161df2647ed6dfc2cbfcb73074426
utils: add a decorator to move positional param args to keyword args

Usage:

```
class TestSuite(BaseTestSuite):
    params = BaseTestSuite.params + [foo_values, bar_values]
    param_names = BaseTestSuite.param_names + ['foo', 'bar']

    @params_as_kwargs
    def test_name(self, foo, bar, **kwargs):
        # ...

and you no longer have to worry about other parameters in BaseTestSuite.params.

diff --git a/benchmarks/utils.py b/benchmarks/utils.py
--- a/benchmarks/utils.py
+++ b/benchmarks/utils.py
@@ -1,5 +1,6 @@
 from __future__ import print_function
 import json
+import functools
 import os
 import os.path
 import re
@@ -115,6 +116,22 @@
     return sum(sorted(lst)[quotient - 1:quotient + 1]) / 2.
 
 
+def params_as_kwargs(f):
+    """Pass in test parameters as keyword arguments.
+
+    Use as a decorator on BaseTestSuite methods
+
+    """
+    @functools.wraps(f)
+    def wrapper(self, *args, **kwargs):
+        names = self.param_names
+        args, values = args[len(names):], args[:len(names)]
+        kwargs.update(zip(names, values))
+        return f(self, *args, **kwargs)
+
+    return wrapper
+
+
 class BaseTestSuite(object):
 
     params = [REPOS]