Lines Matching defs: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
66 # 2. Example & DocTest
67 'Example',
107 # - Example: a <source, want> pair, plus an intra-docstring line number.
120 # | Example |
122 # | Example |
164 # 2. Example & DocTest -- store test cases
172 # 10. Example Usage
258 # case they used print with a trailing comma in an example.
390 ## 2. Example & DocTest
392 ## - An "example" is a <source, want> pair, where "source" is a
394 ## "source." The Example class also includes information about
395 ## where the example was extracted from.
401 class Example:
403 A single doctest example, consisting of source code and expected
404 output. `Example` defines the following attributes:
414 - exc_msg: The exception message generated by the example, if
415 the example is expected to generate an exception; or `None` if
423 this Example where the Example begins. This line number is
426 - indent: The example's indentation in the DocTest string.
428 example's first prompt.
432 example. Any option flags not contained in this dictionary
515 examples = '1 example'
615 # Add the pre-example text to `output`.
617 # Update lineno (lines before this example)
622 # Create an Example, and add it to the list.
624 output.append( Example(source, want, exc_msg,
628 # Update lineno (lines inside this example)
632 # Add any remaining post-example text to `output`.
651 them as a list of `Example` objects. Line numbers are
660 if isinstance(x, Example)]
666 example's source code (with prompts and indentation stripped);
667 and `want` is the example's expected output (with indentation
671 where the example starts; both are used for error messages.
673 # Get the example's indentation level.
707 # source code of an example. Option directives are comments
722 where the example starts; both are used for error messages.
738 'directive on a line with no example: %r' %
1176 def report_start(self, out, test, example):
1179 example. (Only displays a message if verbose=True)
1182 if example.want:
1183 out('Trying:\n' + _indent(example.source) +
1184 'Expecting:\n' + _indent(example.want))
1186 out('Trying:\n' + _indent(example.source) +
1189 def report_success(self, out, test, example, got):
1191 Report that the given example ran successfully. (Only
1197 def report_failure(self, out, test, example, got):
1199 Report that the given example failed.
1201 out(self._failure_header(test, example) +
1202 self._checker.output_difference(example, got, self.optionflags))
1204 def report_unexpected_exception(self, out, test, example, exc_info):
1206 Report that the given example raised an unexpected exception.
1208 out(self._failure_header(test, example) +
1211 def _failure_header(self, test, example):
1214 if test.lineno is not None and example.lineno is not None:
1215 lineno = test.lineno + example.lineno + 1
1221 out.append('Line %s, in %s' % (example.lineno+1, test.name))
1222 out.append('Failed example:')
1223 source = example.source
1233 Run the examples in `test`. Write the outcome of each example
1252 # Process each example.
1253 for examplenum, example in enumerate(test.examples):
1260 # Merge in the example's options.
1262 if example.options:
1263 for (optionflag, val) in example.options.items():
1269 # If 'SKIP' is set, then skip this example.
1273 # Record that we started this example.
1276 self.report_start(out, test, example)
1283 # Run the example in the given context (globs), and record
1288 exec compile(example.source, filename, "single",
1290 self.debugger.set_continue() # ==== Example Finished ====
1296 self.debugger.set_continue() # ==== Example Finished ====
1302 # If the example executed without raising any exceptions,
1305 if check(example.want, got, self.optionflags):
1308 # The example raised an exception: check if it was expected.
1315 # If `example.exc_msg` is None, then we weren't expecting
1317 if example.exc_msg is None:
1321 elif check(example.exc_msg, exc_msg, self.optionflags):
1326 m1 = re.match(r'(?:[^:]*\.)?([^:]*:)', example.exc_msg)
1335 self.report_success(out, test, example, got)
1338 self.report_failure(out, test, example, got)
1342 self.report_unexpected_exception(out, test, example,
1371 example = self.test.examples[int(m.group('examplenum'))]
1372 source = example.source
1395 The output of each example is checked using
1419 # Patch linecache.getlines, so we can see the example's source
1514 example matches the expected output. `OutputChecker` defines two
1521 Return True iff the actual output from an example (`got`)
1596 def output_difference(self, example, got, optionflags):
1599 expected output for a given example (`example`) and the actual
1603 want = example.want
1645 """A DocTest example has failed in debugging mode.
1651 - example: the Example object that failed
1655 def __init__(self, test, example, got):
1657 self.example = example
1664 """A DocTest example has encountered an unexpected exception
1670 - example: the Example object that failed
1674 def __init__(self, test, example, exc_info):
1676 self.example = example
1686 It contains the test, the example, and the original exception:
1699 >>> failure.example.want
1709 access to the test and example information.
1729 As well as to the example:
1731 >>> failure.example.want
1779 def report_unexpected_exception(self, out, test, example, exc_info):
1780 raise UnexpectedException(test, example, exc_info)
1782 def report_failure(self, out, test, example, got):
1783 raise DocTestFailure(test, example, got)
2235 The UnexpectedException contains the test, the example, and
2241 >>> failure.example.want
2269 As well as to the example:
2271 >>> failure.example.want
2525 Converts text with examples to a Python script. Example input is
2526 converted to regular code. Example output and all other words
2582 if isinstance(piece, Example):
2583 # Add the example's source code (strip trailing NL)
2591 # Add non-example text.
2669 ## 10. Example Usage
2717 Example of a string object, searched as-is.