Example #1
0
  def Interpolate(self):
    """Interpolates the pattern.

    Yields:
      All possible interpolation results.
    """
    for var_config in collection.DictProduct(self._var_bindings):
      for scope_config in collection.DictProduct(self._scope_bindings):
        subst = Substitution(var_config=var_config, scope_config=scope_config)
        yield subst.Substitute(self._pattern)
Example #2
0
    def testMultipleKeys(self):
        in_dicts = {"a": [1, 2], "b": [3, 4], "c": [5, 6]}
        out_dicts = [
            {
                "a": 1,
                "b": 3,
                "c": 5
            },
            {
                "a": 1,
                "b": 3,
                "c": 6
            },
            {
                "a": 1,
                "b": 4,
                "c": 5
            },
            {
                "a": 1,
                "b": 4,
                "c": 6
            },
            {
                "a": 2,
                "b": 3,
                "c": 5
            },
            {
                "a": 2,
                "b": 3,
                "c": 6
            },
            {
                "a": 2,
                "b": 4,
                "c": 5
            },
            {
                "a": 2,
                "b": 4,
                "c": 6
            },
        ]

        self.assertCountEqual(list(collection.DictProduct(in_dicts)),
                              out_dicts)
Example #3
0
 def testSingleKeys(self):
   in_dict = {"a": [1], "b": [2], "c": [3]}
   out_dicts = [{"a": 1, "b": 2, "c": 3}]
   self.assertEqual(list(collection.DictProduct(in_dict)), out_dicts)
Example #4
0
 def testEmptyValues(self):
   in_dict = {"a": [1, 2], "b": [], "c": [5, 6]}
   self.assertEqual(list(collection.DictProduct(in_dict)), [])
Example #5
0
 def testEmptyDict(self):
   in_dict = {}
   self.assertEqual(list(collection.DictProduct(in_dict)), [{}])