def test_bad_multi_output(self): with self.assertRaises(AssertionError) as cm: MultiOutput[None] self.assertEqual("MultiOutput must be of non-zero length.", str(cm.exception)) def bad_num_outputs() -> MultiOutput['s':str]: return 1, 2 system = FunctionSystem(bad_num_outputs) context = system.CreateDefaultContext() with self.assertRaises(AssertionError) as cm: system.GetOutputPort("s").Eval(context) self.assertEqual( "Output must be tuple of length 1. Got length 2 instead.", str(cm.exception)) def bad_output_type() -> MultiOutput['s':str]: return [1, 2] system = FunctionSystem(bad_output_type) context = system.CreateDefaultContext() with self.assertRaises(AssertionError) as cm: system.GetOutputPort("s").Eval(context) self.assertEqual( "Output type must be a tuple. Got <class 'list'> instead.", str(cm.exception))
def check(func, u): system = FunctionSystem(func) context = system.CreateDefaultContext() system.get_input_port(0).FixValue(context, u) return system.get_output_port(0).Eval(context)