From: Igor Saprykin Date: Mon, 21 May 2018 23:26:11 +0000 (-0700) Subject: Support a better interface for the single option case in combinations.py. X-Git-Tag: upstream/v1.9.0_rc1~56^2~2^2~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=148790aaf7bf3607e5d6e6d10bce2666535c4a07;p=platform%2Fupstream%2Ftensorflow.git 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 --- 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( [{