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)
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)
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)
def testEmptyValues(self): in_dict = {"a": [1, 2], "b": [], "c": [5, 6]} self.assertEqual(list(collection.DictProduct(in_dict)), [])
def testEmptyDict(self): in_dict = {} self.assertEqual(list(collection.DictProduct(in_dict)), [{}])