Stateful bundled program object Takes a BundledProgramTestData and generates a bundled program
| 160 | |
| 161 | |
| 162 | class BundledProgramManager: |
| 163 | """ |
| 164 | Stateful bundled program object |
| 165 | Takes a BundledProgramTestData and generates a bundled program |
| 166 | """ |
| 167 | |
| 168 | def __init__(self, bundled_program_test_data: List[BundledProgramTestData]) -> None: |
| 169 | self.bundled_program_test_data: List[BundledProgramTestData] = ( |
| 170 | bundled_program_test_data |
| 171 | ) |
| 172 | |
| 173 | @staticmethod |
| 174 | # pyre-fixme[2]: Parameter `**args` has no type specified. |
| 175 | def bundled_program_test_data_gen(**args) -> BundledProgramTestData: |
| 176 | return BundledProgramTestData(**args) |
| 177 | |
| 178 | def get_method_test_suites(self) -> List[MethodTestSuite]: |
| 179 | return [ |
| 180 | self._gen_method_test_suite(bptd) for bptd in self.bundled_program_test_data |
| 181 | ] |
| 182 | |
| 183 | def _gen_method_test_suite(self, bptd: BundledProgramTestData) -> MethodTestSuite: |
| 184 | method_test_case = MethodTestCase( |
| 185 | inputs=bptd.inputs, |
| 186 | expected_outputs=bptd.expected_outputs, |
| 187 | ) |
| 188 | return MethodTestSuite( |
| 189 | method_name=bptd.method, |
| 190 | test_cases=[method_test_case], |
| 191 | ) |
| 192 | |
| 193 | def _serialize( |
| 194 | self, |
| 195 | executorch_program: Union[ |
| 196 | ExecutorchProgram, |
| 197 | ExecutorchProgramManager, |
| 198 | ], |
| 199 | method_test_suites: Sequence[MethodTestSuite], |
| 200 | bptd: BundledProgramTestData, |
| 201 | ) -> bytes: |
| 202 | bundled_program = BundledProgram( |
| 203 | executorch_program=executorch_program, method_test_suites=method_test_suites |
| 204 | ) |
| 205 | bundled_program_buffer = serialize_from_bundled_program_to_flatbuffer( |
| 206 | bundled_program |
| 207 | ) |
| 208 | return bundled_program_buffer |