def test_get_collection(self): # Instantiating the empty collection does not create a path. coll = ParametricType.get_collection([], ParameterizedList.all_lists) self.assertIsNone(coll) empty = ParameterizedList([]) coll = ParametricType.get_collection([], ParameterizedList.all_lists) self.assertIsNone(coll) # Instantiating anything else does. coll = ParametricType.get_collection([int], ParameterizedList.all_lists) self.assertIsNone(coll) intlist = ParameterizedList([int]) coll = ParametricType.get_collection([int], ParameterizedList.all_lists) self.assertIs(coll, intlist)
def test_get_list(self): coll = ParameterizedList.all_lists ParametricType.get_collection([bool], coll) self.assertIn(bool, coll) ParametricType.get_collection([int], coll) self.assertIn(int, coll) ParametricType.get_collection([bool, int], coll) first_type, second_type = sorted([bool, int], key=lambda t: t.__name__) self.assertIn(second_type, coll[first_type][1]) pl = ParametricType.get_collection([ParameterizedList([bool])], coll) # There is now a reified parameterized list of bools that serves as # a key, e.g.: # { ... # <type 'int'>: ( # None, { # }), # <google3.video.youtube.frontend.utils.python.bocado.classes.ParameterizedList object at 0x1490190>: ( # None, { # }), # <type 'bool'>: ( # <google3.video.youtube.frontend.utils.python.bocado.classes.ParameterizedList object at 0x1490190>, { # <type 'int'>: ( # None, { # })}) # ... } self.assertIn(ParametricType.get_collection([bool], coll), coll)
def test_init(self): coll = ParameterizedTuple.all_tuples ParametricType.get_collection([bool], coll) self.assertIn(bool, coll) ParametricType.get_collection([bool, int], coll) first_type, second_type = sorted([bool, int], key=lambda t: t.__name__) self.assertIn(second_type, coll[first_type][1]) # Calling `ParameterizedTuple([int])` creates a key for an int tuple. ParametricType.get_collection([ParameterizedTuple([int])], coll) self.assertIn(ParametricType.get_collection([int], coll), coll)