Parse a list of lines that represent a sequence of test items.
(raw_data: str, name: str)
| 457 | |
| 458 | |
| 459 | def parse_test_data(raw_data: str, name: str) -> list[TestItem]: |
| 460 | """Parse a list of lines that represent a sequence of test items.""" |
| 461 | |
| 462 | lines = ["", "[case " + name + "]"] + raw_data.split("\n") |
| 463 | ret: list[TestItem] = [] |
| 464 | data: list[str] = [] |
| 465 | |
| 466 | id: str | None = None |
| 467 | arg: str | None = None |
| 468 | |
| 469 | i = 0 |
| 470 | i0 = 0 |
| 471 | while i < len(lines): |
| 472 | s = lines[i].strip() |
| 473 | |
| 474 | if lines[i].startswith("[") and s.endswith("]"): |
| 475 | if id: |
| 476 | data = collapse_line_continuation(data) |
| 477 | data = strip_list(data) |
| 478 | ret.append(TestItem(id, arg, data, i0 + 1, i)) |
| 479 | |
| 480 | i0 = i |
| 481 | id = s[1:-1] |
| 482 | arg = None |
| 483 | if " " in id: |
| 484 | arg = id[id.index(" ") + 1 :] |
| 485 | id = id[: id.index(" ")] |
| 486 | data = [] |
| 487 | elif lines[i].startswith("\\["): |
| 488 | data.append(lines[i][1:]) |
| 489 | elif not lines[i].startswith("--"): |
| 490 | data.append(lines[i]) |
| 491 | elif lines[i].startswith("----"): |
| 492 | data.append(lines[i][2:]) |
| 493 | i += 1 |
| 494 | |
| 495 | # Process the last item. |
| 496 | if id: |
| 497 | data = collapse_line_continuation(data) |
| 498 | data = strip_list(data) |
| 499 | ret.append(TestItem(id, arg, data, i0 + 1, i - 1)) |
| 500 | |
| 501 | return ret |
| 502 | |
| 503 | |
| 504 | def strip_list(l: list[str]) -> list[str]: |
no test coverage detected
searching dependent graphs…