git @ Cat's Eye Technologies Falderal / 6c75f4b
Add some failing tests. Chris Pressey 5 years ago
1 changed file(s) with 61 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
371371
372372
373373 class Pragma(Block):
374 pass
374 def execute(self, state):
375 pragma_text = self.text(seperator=' ')
376 match = re.match(r'^\s*Tests\s+for\s+functionality\s*\"(.*?)\"\s*$', pragma_text)
377 if match:
378 functionality_name = match.group(1)
379 state.current_functionality = state.functionalities.setdefault(
380 functionality_name,
381 Functionality(functionality_name)
382 )
383 match = re.match(r'^\s*Functionality\s*\"(.*?)\"\s*is\s+implemented\s+by\s+shell\s+command\s*\"(.*?)\"\s*$', pragma_text)
384 if match:
385 functionality_name = match.group(1)
386 command = match.group(2)
387 functionality = state.functionalities.setdefault(
388 functionality_name,
389 Functionality(functionality_name)
390 )
391 implementation = ShellImplementation(command)
392 functionality.add_implementation(implementation)
375393
376394
377395 class TestBody(Block):
511529 def parse_lines_to_tests(self, functionalities):
512530 r"""Parse the lines of the Document into Tests.
513531
532 >>> functionalities = {}
533 >>> d = Document()
534 >>> d.append(u'This is a test file.')
535 >>> d.append(u' -> Tests for functionality "Parse Thing"')
536 >>> d.append(u'')
537 >>> d.append(u" | This is some test body.")
538 >>> d.append(u" | It extends over two lines.")
539 >>> d.append(u' ? Expected Error')
540 >>> d.append(u'')
541 >>> d.append(u' | Test with input')
542 >>> d.append(u' + input-for-test')
543 >>> d.append(u' = Expected result on output')
544 >>> d.append(u'')
545 >>> d.append(u' + Other input-for-test')
546 >>> d.append(u' = Other Expected result on output')
547 >>> d.append(u'')
548 >>> d.append(u' -> Tests for functionality "Run Thing"')
549 >>> d.append(u'')
550 >>> d.append(u" | Thing")
551 >>> d.append(u' ? Oops')
552 >>> tests = d.parse_lines_to_tests(functionalities)
553 >>> [t.body for t in tests]
554 [u'This is some test body.\nIt extends over two lines.',
555 u'Test with input', u'Test with input', u'Thing']
556 >>> [t.input_block for t in tests]
557 [None, TestInput(line_num=8), TestInput(line_num=12), None]
558 >>> tests[1].input_block.text()
559 u'input-for-test'
560 >>> tests[2].input_block.text()
561 u'Other input-for-test'
562 >>> [t.expectation for t in tests]
563 [ErrorOutcome(u'Expected Error'),
564 OutputOutcome(u'Expected result on output'),
565 OutputOutcome(u'Other Expected result on output'),
566 ErrorOutcome(u'Oops')]
567 >>> [t.functionality.name for t in tests]
568 [u'Parse Thing', u'Parse Thing', u'Parse Thing', u'Run Thing']
569 >>> sorted(funs.keys())
570 [u'Parse Thing', u'Run Thing']
571
514572 """
515573 indent = None
516574 blocks = []
555613 # now process Blocks into Tests
556614
557615 state = ParseState()
616 state.functionalities = functionalities
558617
559618 tests = []
560619 for block in blocks:
569628 if isinstance(test_or_pragma, Test):
570629 tests.append(test_or_pragma)
571630 elif isinstance(test_or_pragma, Pragma):
572 block = test_or_pragma
573 pragma_text = block.text(seperator=' ')
574 match = re.match(r'^\s*Tests\s+for\s+functionality\s*\"(.*?)\"\s*$', pragma_text)
575 if match:
576 functionality_name = match.group(1)
577 state.current_functionality = functionalities.setdefault(
578 functionality_name,
579 Functionality(functionality_name)
580 )
581 match = re.match(r'^\s*Functionality\s*\"(.*?)\"\s*is\s+implemented\s+by\s+shell\s+command\s*\"(.*?)\"\s*$', pragma_text)
582 if match:
583 functionality_name = match.group(1)
584 command = match.group(2)
585 functionality = functionalities.setdefault(
586 functionality_name,
587 Functionality(functionality_name)
588 )
589 implementation = ShellImplementation(command)
590 functionality.add_implementation(implementation)
631 test_or_pragma.execute(state)
591632 else:
592633 raise NotImplementedError('need Pragma or Test')
593634