From 148790aaf7bf3607e5d6e6d10bce2666535c4a07 Mon Sep 17 00:00:00 2001 From: Igor Saprykin Date: Mon, 21 May 2018 16:26:11 -0700 Subject: [PATCH] Support a better interface for the single option case in combinations.py. 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 | 5 ++++- tensorflow/contrib/distribute/python/combinations_test.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tensorflow/contrib/distribute/python/combinations.py b/tensorflow/contrib/distribute/python/combinations.py index 514fd27..1593581 100644 --- a/tensorflow/contrib/distribute/python/combinations.py +++ b/tensorflow/contrib/distribute/python/combinations.py @@ -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)) diff --git a/tensorflow/contrib/distribute/python/combinations_test.py b/tensorflow/contrib/distribute/python/combinations_test.py index 219b241..184bcf2 100644 --- a/tensorflow/contrib/distribute/python/combinations_test.py +++ b/tensorflow/contrib/distribute/python/combinations_test.py @@ -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( [{ -- 2.7.4