All doctests pass once again!
Chris Pressey
6 years ago
271 | 271 | # TODO: interpret this according to the new, not-yet-written rules. |
272 | 272 | return [] |
273 | 273 | else: |
274 | if pattern_prefixes in [[u'= '], [u'? ']]: | |
275 | raise FalderalSyntaxError( | |
276 | ("line %d: " % self.line_num) + | |
277 | "expectation must be preceded by test body or test input") | |
278 | ||
279 | if pattern_prefixes in [[u'| ']]: | |
280 | raise FalderalSyntaxError( | |
281 | ("line %d: " % self.line_num) + | |
282 | "test body must be followed by expectation or test input") | |
283 | ||
274 | 284 | valid_patterns = [ |
275 | 285 | [u'->'], |
276 | 286 | [u'> '], |
285 | 295 | return [self.PREFIX_MAP[prefix](line_num=self.line_num, filename=self.filename, lines=lines) for (prefix, lines) in pattern] |
286 | 296 | raise FalderalSyntaxError( |
287 | 297 | ("line %d: " % self.line_num) + |
288 | "test block must consist of test body and/or test input, then expectation, in that order") | |
298 | "incorrectly formatted test block") | |
289 | 299 | |
290 | 300 | |
291 | 301 | class LiterateCode(Block): |
431 | 441 | >>> d = Document() |
432 | 442 | >>> d.append(u'This is a test file.') |
433 | 443 | >>> d.append(u' -> Tests for functionality "Parse Thing"') |
444 | >>> d.append(u'') | |
434 | 445 | >>> d.append(u" | This is some test body.") |
435 | 446 | >>> d.append(u" | It extends over two lines.") |
436 | 447 | >>> d.append(u' ? Expected Error') |
448 | >>> d.append(u'') | |
437 | 449 | >>> d.append(u' | Test with input') |
438 | 450 | >>> d.append(u' + input-for-test') |
439 | 451 | >>> d.append(u' = Expected result on output') |
452 | >>> d.append(u'') | |
440 | 453 | >>> d.append(u' + Other input-for-test') |
441 | 454 | >>> d.append(u' = Other Expected result on output') |
455 | >>> d.append(u'') | |
442 | 456 | >>> d.append(u' -> Tests for functionality "Run Thing"') |
457 | >>> d.append(u'') | |
443 | 458 | >>> d.append(u" | Thing") |
444 | 459 | >>> d.append(u' ? Oops') |
445 | 460 | >>> d.parse_lines_to_blocks() |
452 | 467 | [u'This is some test body.\nIt extends over two lines.', |
453 | 468 | u'Test with input', u'Test with input', u'Thing'] |
454 | 469 | >>> [t.input_block for t in tests] |
455 | [None, TestInput(u' + ', line_num=7, filename=None), | |
456 | TestInput(u' + ', line_num=9, filename=None), None] | |
470 | [None, TestInput(line_num=8), TestInput(line_num=12), None] | |
457 | 471 | >>> tests[1].input_block.text() |
458 | 472 | u'input-for-test' |
459 | 473 | >>> tests[2].input_block.text() |
474 | 488 | >>> d.parse_blocks_to_tests({}) |
475 | 489 | Traceback (most recent call last): |
476 | 490 | ... |
477 | FalderalSyntaxError: line 2: functionality under test not specified | |
491 | FalderalSyntaxError: line 1: functionality under test not specified | |
478 | 492 | |
479 | 493 | >>> d = Document() |
480 | 494 | >>> d.append(u'This is a test file.') |
490 | 504 | >>> d.parse_blocks_to_tests({}) |
491 | 505 | Traceback (most recent call last): |
492 | 506 | ... |
493 | FalderalSyntaxError: line 2: expectation must be preceded by test body or test input | |
507 | FalderalSyntaxError: line 1: incorrectly formatted test block | |
494 | 508 | |
495 | 509 | >>> d = Document() |
496 | 510 | >>> d.append(u' | This is test') |
498 | 512 | >>> d.parse_blocks_to_tests({}) |
499 | 513 | Traceback (most recent call last): |
500 | 514 | ... |
501 | FalderalSyntaxError: line 2: test body must be followed by expectation or test input | |
515 | FalderalSyntaxError: line 1: test body must be followed by expectation or test input | |
502 | 516 | |
503 | 517 | >>> d = Document() |
504 | 518 | >>> d.append(u' -> Hello, this is pragma') |
506 | 520 | >>> d.parse_blocks_to_tests({}) |
507 | 521 | Traceback (most recent call last): |
508 | 522 | ... |
509 | FalderalSyntaxError: line 2: test input must be preceded by test body | |
523 | FalderalSyntaxError: line 1: incorrectly formatted test block | |
510 | 524 | |
511 | 525 | >>> d = Document() |
512 | 526 | >>> funs = {} |
825 | 839 | |
826 | 840 | TODO: maybe write a helper function for that instead. |
827 | 841 | |
828 | >>> b = TestBody(u' | ') | |
829 | >>> b.append(u' | foo') | |
830 | >>> b.append(u' | bar') | |
831 | >>> i = TestInput(u' + ') | |
832 | >>> i.append(u' + green') | |
842 | >>> b = TestBody() | |
843 | >>> b.append(u'foo') | |
844 | >>> b.append(u'bar') | |
845 | >>> i = TestInput() | |
846 | >>> i.append(u'green') | |
833 | 847 | >>> t = Test(body_block=b, input_block=i) |
834 | 848 | >>> print t.body |
835 | 849 | foo |