call site 0 for compat.doctest.DocTestRunner.report_start
test/testing/test_doctest.py - line 23
16
17
18
19
20
21
22
23
   def test_simple_docteststring_failing():
       testitem = DoctestText(name="dummy2", parent=None)
       testitem._setcontent("""
       >>> i = 0
       >>> i + 1
       2
       """)
->     py.test.raises(Failed, "testitem.run()")
test/raises.py - line 20
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
   def raises(ExpectedException, *args, **kwargs):
       """ raise AssertionError, if target code does not raise the expected
           exception.
       """
       assert args
       __tracebackhide__ = True 
       if isinstance(args[0], str):
           expr, = args
           assert isinstance(expr, str)
           frame = sys._getframe(1)
           loc = frame.f_locals.copy()
           loc.update(kwargs)
           #print "raises frame scope: %r" % frame.f_locals
           source = py.code.Source(expr)
           try:
->             exec source.compile() in frame.f_globals, loc
               #del __traceback__
               # XXX didn'T mean f_globals == f_locals something special?
               #     this is destroyed here ...
           except ExpectedException:
               return py.code.ExceptionInfo()
       else:
           func = args[0]
           assert callable
           try:
               func(*args[1:], **kwargs)
               #del __traceback__
           except ExpectedException:
               return py.code.ExceptionInfo()
           k = ", ".join(["%s=%r" % x for x in kwargs.items()])
           if k:
               k = ', ' + k
           expr = '%s(%r%s)' %(func.__name__, args, k)
       raise ExceptionFailure(msg="DID NOT RAISE", 
                              expr=args, expected=ExpectedException) 
None</build/buildd/codespeak-lib-0.9.0/py/test/raises.py:20> - line 1
1
-> testitem.run()
test/doctest.py - line 26
18
19
20
21
22
23
24
25
26
   def run(self):
       mod = py.std.types.ModuleType(self.name) 
       #for line in s.split('\n'): 
       #    if line.startswith(prefix): 
       #        exec py.code.Source(line[len(prefix):]).compile() in mod.__dict__ 
       #        line = ""
       #    else: 
       #        l.append(line)
->     self.execute(mod, self._content) 
test/doctest.py - line 30
28
29
30
31
32
33
   def execute(self, mod, docstring):
       mod.__doc__ = docstring 
->     failed, tot = py.compat.doctest.testmod(mod, verbose=1)
       if failed: 
           py.test.fail("doctest %s: %s failed out of %s" %(
                        self.fspath, failed, tot))
compat/doctest.py - line 1847
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
   def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None,
               report=True, optionflags=0, extraglobs=None,
               raise_on_error=False, exclude_empty=False):
       """m=None, name=None, globs=None, verbose=None, isprivate=None,
          report=True, optionflags=0, extraglobs=None, raise_on_error=False,
          exclude_empty=False
   
       Test examples in docstrings in functions and classes reachable
       from module m (or the current module if m is not supplied), starting
       with m.__doc__.  Unless isprivate is specified, private names
       are not skipped.
   
       Also test examples reachable from dict m.__test__ if it exists and is
       not None.  m.__test__ maps names to functions, classes and strings;
       function and class docstrings are tested even if the name is private;
       strings are tested directly, as if they were docstrings.
   
       Return (#failures, #tests).
   
       See doctest.__doc__ for an overview.
   
       Optional keyword arg "name" gives the name of the module; by default
       use m.__name__.
   
       Optional keyword arg "globs" gives a dict to be used as the globals
       when executing examples; by default, use m.__dict__.  A copy of this
       dict is actually used for each docstring, so that each docstring's
       examples start with a clean slate.
   
       Optional keyword arg "extraglobs" gives a dictionary that should be
       merged into the globals that are used to execute examples.  By
       default, no extra globals are used.  This is new in 2.4.
   
       Optional keyword arg "verbose" prints lots of stuff if true, prints
       only failures if false; by default, it's true iff "-v" is in sys.argv.
   
       Optional keyword arg "report" prints a summary at the end when true,
       else prints nothing at the end.  In verbose mode, the summary is
       detailed, else very brief (in fact, empty if all tests passed).
   
       Optional keyword arg "optionflags" or's together module constants,
       and defaults to 0.  This is new in 2.3.  Possible values (see the
       docs for details):
   
           DONT_ACCEPT_TRUE_FOR_1
           DONT_ACCEPT_BLANKLINE
           NORMALIZE_WHITESPACE
           ELLIPSIS
           IGNORE_EXCEPTION_DETAIL
           REPORT_UDIFF
           REPORT_CDIFF
           REPORT_NDIFF
           REPORT_ONLY_FIRST_FAILURE
   
       Optional keyword arg "raise_on_error" raises an exception on the
       first unexpected exception or failure. This allows failures to be
       post-mortem debugged.
   
       Deprecated in Python 2.4:
       Optional keyword arg "isprivate" specifies a function used to
       determine whether a name is private.  The default function is
       treat all functions as public.  Optionally, "isprivate" can be
       set to doctest.is_private to skip over functions marked as private
       using the underscore naming convention; see its docs for details.
   
       Advanced tomfoolery:  testmod runs methods of a local instance of
       class doctest.Tester, then merges the results into (or creates)
       global Tester instance doctest.master.  Methods of doctest.master
       can be called directly too, if you want to do something unusual.
       Passing report=0 to testmod is especially useful then, to delay
       displaying a summary.  Invoke doctest.master.summarize(verbose)
       when you're done fiddling.
       """
       global master
   
       if isprivate is not None:
           warnings.warn("the isprivate argument is deprecated; "
                         "examine DocTestFinder.find() lists instead",
                         DeprecationWarning)
   
       # If no module was given, then use __main__.
       if m is None:
           # DWA - m will still be None if this wasn't invoked from the command
           # line, in which case the following TypeError is about as good an error
           # as we should expect
           m = sys.modules.get('__main__')
   
       # Check that we were actually given a module.
       if not inspect.ismodule(m):
           raise TypeError("testmod: module required; %r" % (m,))
   
       # If no name was given, then use the module's name.
       if name is None:
           name = m.__name__
   
       # Find, parse, and run all tests in the given module.
       finder = DocTestFinder(_namefilter=isprivate, exclude_empty=exclude_empty)
   
       if raise_on_error:
           runner = DebugRunner(verbose=verbose, optionflags=optionflags)
       else:
           runner = DocTestRunner(verbose=verbose, optionflags=optionflags)
   
       for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
->         runner.run(test)
   
       if report:
           runner.summarize()
   
       if master is None:
           master = runner
       else:
           master.merge(runner)
   
       return runner.failures, runner.tries
compat/doctest.py - line 1381
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
   def run(self, test, compileflags=None, out=None, clear_globs=True):
       """
           Run the examples in `test`, and display the results using the
           writer function `out`.
   
           The examples are run in the namespace `test.globs`.  If
           `clear_globs` is true (the default), then this namespace will
           be cleared after the test runs, to help with garbage
           collection.  If you would like to examine the namespace after
           the test completes, then use `clear_globs=False`.
   
           `compileflags` gives the set of flags that should be used by
           the Python compiler when running the examples.  If not
           specified, then it will default to the set of future-import
           flags that apply to `globs`.
   
           The output of each example is checked using
           `DocTestRunner.check_output`, and the results are formatted by
           the `DocTestRunner.report_*` methods.
           """
       self.test = test
   
       if compileflags is None:
           compileflags = _extract_future_flags(test.globs)
   
       save_stdout = sys.stdout
       if out is None:
           out = save_stdout.write
       sys.stdout = self._fakeout
   
       # Patch pdb.set_trace to restore sys.stdout during interactive
       # debugging (so it's not still redirected to self._fakeout).
       # Note that the interactive output will go to *our*
       # save_stdout, even if that's not the real sys.stdout; this
       # allows us to write test cases for the set_trace behavior.
       save_set_trace = pdb.set_trace
       self.debugger = _OutputRedirectingPdb(save_stdout)
       self.debugger.reset()
       pdb.set_trace = self.debugger.set_trace
   
       # Patch linecache.getlines, so we can see the example's source
       # when we're inside the debugger.
       self.save_linecache_getlines = linecache.getlines
       linecache.getlines = self.__patched_linecache_getlines
   
       try:
->         return self.__run(test, compileflags, out)
       finally:
           sys.stdout = save_stdout
           pdb.set_trace = save_set_trace
           linecache.getlines = self.save_linecache_getlines
           if clear_globs:
               test.globs.clear()
compat/doctest.py - line 1235
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
   def __run(self, test, compileflags, out):
       """
           Run the examples in `test`.  Write the outcome of each example
           with one of the `DocTestRunner.report_*` methods, using the
           writer function `out`.  `compileflags` is the set of compiler
           flags that should be used to execute examples.  Return a tuple
           `(f, t)`, where `t` is the number of examples tried, and `f`
           is the number of examples that failed.  The examples are run
           in the namespace `test.globs`.
           """
       # Keep track of the number of failures and tries.
       failures = tries = 0
   
       # Save the option flags (since option directives can be used
       # to modify them).
       original_optionflags = self.optionflags
   
       SUCCESS, FAILURE, BOOM = range(3) # `outcome` state
   
       check = self._checker.check_output
   
       # Process each example.
       for examplenum, example in enumerate(test.examples):
   
           # If REPORT_ONLY_FIRST_FAILURE is set, then supress
           # reporting after the first failure.
           quiet = (self.optionflags & REPORT_ONLY_FIRST_FAILURE and
                    failures > 0)
   
           # Merge in the example's options.
           self.optionflags = original_optionflags
           if example.options:
               for (optionflag, val) in example.options.items():
                   if val:
                       self.optionflags |= optionflag
                   else:
                       self.optionflags &= ~optionflag
   
           # Record that we started this example.
           tries += 1
           if not quiet:
->             self.report_start(out, test, example)
   
           # Use a special filename for compile(), so we can retrieve
           # the source code during interactive debugging (see
           # __patched_linecache_getlines).
           filename = '<doctest %s[%d]>' % (test.name, examplenum)
   
           # Run the example in the given context (globs), and record
           # any exception that gets raised.  (But don't intercept
           # keyboard interrupts.)
           try:
               # Don't blink!  This is where the user's code gets run.
               exec compile(example.source, filename, "single",
                            compileflags, 1) in test.globs
               self.debugger.set_continue() # ==== Example Finished ====
               exception = None
           except KeyboardInterrupt:
               raise
           except:
               exception = sys.exc_info()
               self.debugger.set_continue() # ==== Example Finished ====
   
           got = self._fakeout.getvalue()  # the actual output
           self._fakeout.truncate(0)
           outcome = FAILURE   # guilty until proved innocent or insane
   
           # If the example executed without raising any exceptions,
           # verify its output.
           if exception is None:
               if check(example.want, got, self.optionflags):
                   outcome = SUCCESS
   
           # The example raised an exception:  check if it was expected.
           else:
               exc_info = sys.exc_info()
               exc_msg = traceback.format_exception_only(*exc_info[:2])[-1]
               if not quiet:
                   got += _exception_traceback(exc_info)
   
               # If `example.exc_msg` is None, then we weren't expecting
               # an exception.
               if example.exc_msg is None:
                   outcome = BOOM
   
               # We expected an exception:  see whether it matches.
               elif check(example.exc_msg, exc_msg, self.optionflags):
                   outcome = SUCCESS
   
               # Another chance if they didn't care about the detail.
               elif self.optionflags & IGNORE_EXCEPTION_DETAIL:
                   m1 = re.match(r'[^:]*:', example.exc_msg)
                   m2 = re.match(r'[^:]*:', exc_msg)
                   if m1 and m2 and check(m1.group(0), m2.group(0),
                                          self.optionflags):
                       outcome = SUCCESS
   
           # Report the outcome.
           if outcome is SUCCESS:
               if not quiet:
                   self.report_success(out, test, example, got)
           elif outcome is FAILURE:
               if not quiet:
                   self.report_failure(out, test, example, got)
               failures += 1
           elif outcome is BOOM:
               if not quiet:
                   self.report_unexpected_exception(out, test, example,
                                                    exc_info)
               failures += 1
           else:
               assert False, ("unknown outcome", outcome)
   
       # Restore the option flags (in case they were modified)
       self.optionflags = original_optionflags
   
       # Record and return the number of failures and tries.
       self.__record_outcome(test, failures, tries)
       return failures, tries