Support a better interface for the single option case in combinations.py.
authorIgor Saprykin <isaprykin@google.com>
Mon, 21 May 2018 23:26:11 +0000 (16:26 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Mon, 21 May 2018 23:29:14 +0000 (16:29 -0700)
If there's only one combination for combination-based tests, it doesn't have to
be a list.

PiperOrigin-RevId: 197479773

tensorflow/contrib/distribute/python/combinations.py
tensorflow/contrib/distribute/python/combinations_test.py

index 514fd27..1593581 100644 (file)
@@ -181,7 +181,8 @@ def combine(**kwargs):
   can be computed using `times()`.
 
   Args:
-    **kwargs: keyword arguments of form `option=[possibilities, ...]`.
+    **kwargs: keyword arguments of form `option=[possibilities, ...]`
+         or `option=the_only_possibility`.
 
   Returns:
     a list of dictionaries for each combination. Keys in the dictionaries are
@@ -200,6 +201,8 @@ def combine(**kwargs):
 
   key = first[0]
   values = first[1]
+  if not isinstance(values, list):
+    values = [values]
 
   return [
       OrderedDict(sorted(list(combined.items()) + [(key, v)], key=sort_by_key))
index 219b241..184bcf2 100644 (file)
@@ -41,6 +41,15 @@ class TestingCombinationsTest(test.TestCase):
         "b": 3
     }], combinations.combine(a=[1, 2], b=[2, 3]))
 
+  def test_combine_single_parameter(self):
+    self.assertEqual([{
+        "a": 1,
+        "b": 2
+    }, {
+        "a": 2,
+        "b": 2
+    }], combinations.combine(a=[1, 2], b=2))
+
   def test_add(self):
     self.assertEqual(
         [{