Support combinations stored in a global variable in combinations.py-based tests.
authorIgor Saprykin <isaprykin@google.com>
Thu, 17 May 2018 22:29:03 +0000 (15:29 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Thu, 17 May 2018 22:35:34 +0000 (15:35 -0700)
The user's input is modified to give the test a better name.  If the user stores combinations in a variable and applies those combinations to more than one test, then the test case name will be a concatenation of of the names of the previous test cases.

PiperOrigin-RevId: 197061902

tensorflow/contrib/distribute/python/combinations.py

index d719234..6d70c9d 100644 (file)
@@ -90,6 +90,7 @@ def generate(combinations):
     """The decorator to be returned."""
 
     # Generate good test names that can be used with --test_filter.
+    named_combinations = []
     for combination in combinations:
       # We use OrderedDicts in `combine()` and `times()` to ensure stable
       # order of keys in each dictionary.
@@ -100,9 +101,12 @@ def generate(combinations):
               "".join(filter(str.isalnum, str(value))))
           for key, value in combination.items()
       ])
-      combination.update({"testcase_name": "_test{}".format(name)})
+      named_combinations.append(
+          OrderedDict(
+              list(combination.items()) + [("testcase_name",
+                                            "_test{}".format(name))]))
 
-    @parameterized.named_parameters(*combinations)
+    @parameterized.named_parameters(*named_combinations)
     def decorated(self, **kwargs):
       """A wrapped test method that sets up `test_function`."""
       assert "mode" in kwargs