Lines Matching refs:example
25 This won't display anything unless an example fails, in which case the
26 failing example(s) and the cause(s) of the failure(s) are printed to stdout
428 ## - An "example" is a <source, want> pair, where "source" is a
431 ## where the example was extracted from.
439 A single doctest example, consisting of source code and expected
450 - exc_msg: The exception message generated by the example, if
451 the example is expected to generate an exception; or `None` if
462 - indent: The example's indentation in the DocTest string.
464 example's first prompt.
468 example. Any option flags not contained in this dictionary
547 examples = '1 example'
646 # Add the pre-example text to `output`.
648 # Update lineno (lines before this example)
659 # Update lineno (lines inside this example)
663 # Add any remaining post-example text to `output`.
697 example's source code (with prompts and indentation stripped);
698 and `want` is the example's expected output (with indentation
702 where the example starts; both are used for error messages.
704 # Get the example's indentation level.
738 # source code of an example. Option directives are comments
753 where the example starts; both are used for error messages.
769 'directive on a line with no example: %r' %
1239 def report_start(self, out, test, example):
1242 example. (Only displays a message if verbose=True)
1245 if example.want:
1246 out('Trying:\n' + _indent(example.source) +
1247 'Expecting:\n' + _indent(example.want))
1249 out('Trying:\n' + _indent(example.source) +
1252 def report_success(self, out, test, example, got):
1254 Report that the given example ran successfully. (Only
1260 def report_failure(self, out, test, example, got):
1262 Report that the given example failed.
1264 out(self._failure_header(test, example) +
1265 self._checker.output_difference(example, got, self.optionflags))
1267 def report_unexpected_exception(self, out, test, example, exc_info):
1269 Report that the given example raised an unexpected exception.
1271 out(self._failure_header(test, example) +
1274 def _failure_header(self, test, example):
1277 if test.lineno is not None and example.lineno is not None:
1278 lineno = test.lineno + example.lineno + 1
1284 out.append('Line %s, in %s' % (example.lineno+1, test.name))
1285 out.append('Failed example:')
1286 source = example.source
1296 Run the examples in `test`. Write the outcome of each example
1315 # Process each example.
1316 for examplenum, example in enumerate(test.examples):
1323 # Merge in the example's options.
1325 if example.options:
1326 for (optionflag, val) in example.options.items():
1332 # If 'SKIP' is set, then skip this example.
1336 # Record that we started this example.
1339 self.report_start(out, test, example)
1346 # Run the example in the given context (globs), and record
1351 exec(compile(example.source, filename, "single",
1365 # If the example executed without raising any exceptions,
1368 if check(example.want, got, self.optionflags):
1371 # The example raised an exception: check if it was expected.
1377 # If `example.exc_msg` is None, then we weren't expecting
1379 if example.exc_msg is None:
1383 elif check(example.exc_msg, exc_msg, self.optionflags):
1388 if check(_strip_exception_details(example.exc_msg),
1396 self.report_success(out, test, example, got)
1399 self.report_failure(out, test, example, got)
1403 self.report_unexpected_exception(out, test, example,
1435 example = self.test.examples[int(m.group('examplenum'))]
1436 return example.source.splitlines(keepends=True)
1456 The output of each example is checked using
1488 # Patch linecache.getlines, so we can see the example's source
1586 example matches the expected output. `OutputChecker` defines two
1599 Return True iff the actual output from an example (`got`)
1683 def output_difference(self, example, got, optionflags):
1686 expected output for a given example (`example`) and the actual
1690 want = example.want
1730 """A DocTest example has failed in debugging mode.
1736 - example: the Example object that failed
1740 def __init__(self, test, example, got):
1742 self.example = example
1749 """A DocTest example has encountered an unexpected exception
1755 - example: the Example object that failed
1759 def __init__(self, test, example, exc_info):
1761 self.example = example
1771 It contains the test, the example, and the original exception:
1784 >>> failure.example.want
1794 access to the test and example information.
1814 As well as to the example:
1816 >>> failure.example.want
1864 def report_unexpected_exception(self, out, test, example, exc_info):
1865 raise UnexpectedException(test, example, exc_info)
1867 def report_failure(self, out, test, example, got):
1868 raise DocTestFailure(test, example, got)
2256 The UnexpectedException contains the test, the example, and
2262 >>> failure.example.want
2290 As well as to the example:
2292 >>> failure.example.want
2594 # Add the example's source code (strip trailing NL)
2602 # Add non-example text.