(self, prompt, testcase, multiple = False)
| 359 | |
| 360 | |
| 361 | def format_testcase(self, prompt, testcase, multiple = False): |
| 362 | if not multiple and isinstance(testcase, dict) and "input" in testcase and "output" in testcase: |
| 363 | new_testcase = {} |
| 364 | inputs = self.format_strs(testcase["input"]) |
| 365 | outputs = self.format_strs(testcase["output"]) |
| 366 | if self.add_list[self.name]: |
| 367 | new_testcase["input"] = [inputs] |
| 368 | new_testcase["output"] = outputs |
| 369 | else: |
| 370 | new_testcase["input"] = inputs |
| 371 | new_testcase["output"] = outputs[0] |
| 372 | |
| 373 | return new_testcase |
| 374 | elif multiple and isinstance(testcase, dict): |
| 375 | new_testcases = [] |
| 376 | if "inputs" in testcase: |
| 377 | inputs = self.format_strs(testcase["inputs"]) |
| 378 | outputs = self.format_strs(testcase["outputs"]) |
| 379 | elif "input" in testcase: |
| 380 | inputs = self.format_strs(testcase["input"]) |
| 381 | outputs = self.format_strs(testcase["output"]) |
| 382 | |
| 383 | |
| 384 | if self.name in ["codeparrot/apps", "BAAI/TACO"] and "fn_name" not in testcase: |
| 385 | new_inputs = [] |
| 386 | for inp in inputs: |
| 387 | if isinstance(inp, list): |
| 388 | new_inputs.append("\n".join(inp)) |
| 389 | else: |
| 390 | new_inputs.append(inp) |
| 391 | inputs = new_inputs |
| 392 | new_outputs = [] |
| 393 | for op in outputs: |
| 394 | if isinstance(op, list): |
| 395 | new_outputs.append("\n".join(op)) |
| 396 | else: |
| 397 | new_outputs.append(op) |
| 398 | outputs = new_outputs |
| 399 | |
| 400 | for index, inp in enumerate(inputs): |
| 401 | new_testcase = {} |
| 402 | if self.add_list[self.name]: |
| 403 | if self.name == "codeparrot/apps": |
| 404 | if "fn_name" not in testcase: |
| 405 | new_testcase["input"] = [inp] |
| 406 | new_testcase["output"] = [None] if outputs == None else [outputs[index]] |
| 407 | new_testcase["entry_point"] = None |
| 408 | else: |
| 409 | new_testcase["input"] = inp |
| 410 | new_testcase["output"] = [None] if outputs == None else outputs[index] |
| 411 | if not isinstance(new_testcase["output"], list): |
| 412 | new_testcase["output"] = [new_testcase["output"]] |
| 413 | new_testcase["entry_point"] = testcase["fn_name"] |
| 414 | elif self.name == "BAAI/TACO": |
| 415 | if "fn_name" not in testcase: |
| 416 | new_testcase["input"] = [inp] |
| 417 | if not isinstance(outputs[index], list): |
| 418 | new_testcase["output"] = [None] if outputs == None else [outputs[index]] |
no test coverage detected