# HG changeset patch
# User Jeroen Demeyer <jdemeyer@cage.ugent.be>
# Date 1361973198 3600
# Node ID f2b2bce7579c2d732cdef2db306cc2f94b6c214d
# Parent c7b751daeaf5c488a4a52afa89212376e791edef
#12415: changes to Jeroen's changes
diff git a/sage/doctest/control.py b/sage/doctest/control.py
a

b


379  379  def expand_files_into_sources(self): 
380  380  """ 
381  381  Expands ``self.files``, which may include directories, into a 
382   list of :class:sage.doctest.FileDocTestSource 
 382  list of :class:`sage.doctest.FileDocTestSource` 
383  383  
384  384  This function also handles the optional command line option. 
385  385  
… 
… 

621  621  sage: print DC._assemble_cmd() 
622  622  python "$SAGE_LOCAL/bin/sageruntests" serial timeout=300 hello_world.py 
623  623  """ 
624   cmd = '''python "$SAGE_LOCAL/bin/sageruntests" serial ''' 
 624  cmd = '''python "%s" serial '''%(os.path.join("$SAGE_LOCAL","bin","sageruntests")) 
625  625  opt = dict_difference(self.options.__dict__, DocTestDefaults().__dict__) 
626  626  for o in ("all", "sagenb"): 
627  627  if o in opt: 
… 
… 

690  690  flags = os.getenv("SAGE_MEMCHECK_FLAGS") 
691  691  if flags is None: 
692  692  flags = "leakresolution=high leakcheck=full numcallers=25 " 
693   flags += '''suppressions="$SAGE_LOCAL/lib/valgrind/sage.supp" ''' 
 693  flags += '''suppressions="%s" '''%(os.path.join("$SAGE_LOCAL","lib","valgrind","sage.supp")) 
694  694  elif opt.massif: 
695  695  toolname = "massif" 
696  696  flags = os.getenv("SAGE_MASSIF_FLAGS", "depth=6 ") 
diff git a/sage/doctest/forker.py b/sage/doctest/forker.py
a

b


1466  1466  pass 
1467  1467  finally: 
1468  1468  os._exit(0) 
1469   
 1469  
1470  1470  # Hack to ensure multiprocessing leaves these processes alone 
1471  1471  multiprocessing.current_process()._children = set() 
1472  1472  
1473   def dispatch(self): # todo, nthreads=options.nthreads, streaming=False, verbose=options.verbose, debug=options.debug, run_id=run_id 
 1473  def dispatch(self): 
1474  1474  """ 
1475  1475  Run the doctests for the controller's specified sources, 
1476  1476  by calling :meth:`parallel_dispatch` or :meth:`serial_dispatch` 
… 
… 

1644  1644  def start(self): 
1645  1645  """ 
1646  1646  Start the worker and close the writing end of the message pipe. 
 1647  
 1648  TESTS:: 
 1649  
 1650  sage: from sage.doctest.forker import DocTestWorker, DocTestTask 
 1651  sage: from sage.doctest.sources import FileDocTestSource 
 1652  sage: from sage.doctest.reporting import DocTestReporter 
 1653  sage: from sage.doctest.control import DocTestController, DocTestDefaults 
 1654  sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py') 
 1655  sage: DD = DocTestDefaults() 
 1656  sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None) 
 1657  sage: W = DocTestWorker(FDS, DD) 
 1658  sage: W.start() 
 1659  sage: try: 
 1660  ....: os.fstat(W.wmessages) 
 1661  ....: except OSError: 
 1662  ....: print "Write end of pipe successfully closed" 
 1663  Write end of pipe successfully closed 
 1664  sage: W.join() # Wait for worker to finish 
1647  1665  """ 
1648  1666  super(DocTestWorker, self).start() 
1649  1667  
… 
… 

1655  1673  """ 
1656  1674  In the master process, read from the pipe and store the data 
1657  1675  read in the ``messages`` attribute. 
 1676  
 1677  .. NOTE:: 
 1678  
 1679  This function may need to be called multiple times in 
 1680  order to read all of the messages. 
 1681  
 1682  EXAMPLES:: 
 1683  
 1684  sage: from sage.doctest.forker import DocTestWorker, DocTestTask 
 1685  sage: from sage.doctest.sources import FileDocTestSource 
 1686  sage: from sage.doctest.reporting import DocTestReporter 
 1687  sage: from sage.doctest.control import DocTestController, DocTestDefaults 
 1688  sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py') 
 1689  sage: DD = DocTestDefaults(verbose=True,nthreads=2) 
 1690  sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None) 
 1691  sage: W = DocTestWorker(FDS, DD) 
 1692  sage: W.start() 
 1693  sage: while W.rmessages is not None: 
 1694  ....: W.read_messages() 
 1695  sage: W.join() 
 1696  sage: len(W.messages) > 0 
 1697  True 
1658  1698  """ 
1659  1699  # It's absolutely important to execute only one read() system 
1660  1700  # call, more might block. Assuming that we used pselect() 
… 
… 

1672  1712  the ``result_queue`` and with ``self.output``, the complete 
1673  1713  contents of ``self.outtmpfile``. Then close the Queue and 
1674  1714  ``self.outtmpfile``. 
 1715  
 1716  EXAMPLES:: 
 1717  
 1718  sage: from sage.doctest.forker import DocTestWorker, DocTestTask 
 1719  sage: from sage.doctest.sources import FileDocTestSource 
 1720  sage: from sage.doctest.reporting import DocTestReporter 
 1721  sage: from sage.doctest.control import DocTestController, DocTestDefaults 
 1722  sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py') 
 1723  sage: DD = DocTestDefaults() 
 1724  sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None) 
 1725  sage: W = DocTestWorker(FDS, DD) 
 1726  sage: W.start() 
 1727  sage: W.join() 
 1728  sage: W.save_result_output() 
 1729  sage: sorted(W.result[1].keys()) 
 1730  ['cputime', 'err', 'failures', 'walltime'] 
 1731  sage: len(W.output) > 0 
 1732  True 
1675  1733  """ 
1676  1734  from Queue import Empty 
1677  1735  try: 
… 
… 

1689  1747  Kill this worker. The first time this is called, use 
1690  1748  ``SIGHUP``. Subsequent times, use ``SIGKILL``. Also close the 
1691  1749  message pipe if it was still open. 
 1750  
 1751  EXAMPLES:: 
 1752  
 1753  sage: import time 
 1754  sage: from sage.doctest.forker import DocTestWorker, DocTestTask 
 1755  sage: from sage.doctest.sources import FileDocTestSource 
 1756  sage: from sage.doctest.reporting import DocTestReporter 
 1757  sage: from sage.doctest.control import DocTestController, DocTestDefaults 
 1758  sage: filename = os.path.join(os.environ['SAGE_ROOT'],'devel','sage','sage','doctest','util.py') 
 1759  sage: DD = DocTestDefaults() 
 1760  sage: FDS = FileDocTestSource(filename,True,False,set(['sage']),None) 
 1761  sage: W = DocTestWorker(FDS, DD) 
 1762  sage: W.start() 
 1763  sage: time.sleep(0.05) 
 1764  sage: W.killed 
 1765  False 
 1766  sage: W.kill() 
 1767  sage: W.killed 
 1768  True 
 1769  sage: try: 
 1770  ....: W.kill() 
 1771  ....: except OSError: 
 1772  ....: pass 
 1773  sage: time.sleep(0.1) 
 1774  sage: W.is_alive() 
 1775  False 
1692  1776  """ 
1693  1777  if self.rmessages is not None: 
1694  1778  os.close(self.rmessages) 
… 
… 

1766  1850  
1767  1851  OUPUT: 
1768  1852  
1769    ``(doctests, runner)`` where ``doctests`` is the number of 
1770   doctests and and ``runner`` is an annotated 
1771   ``SageDocTestRunner`` instance. 
 1853   ``(doctests, result_dict)`` where ``doctests`` is the number of 
 1854  doctests and and ``result_dict`` is a dictionary annotated with 
 1855  timings and error information. 
1772  1856  
1773    Also put ``(doctests, runner)`` onto the ``result_queue`` 
 1857   Also put ``(doctests, result_dict)`` onto the ``result_queue`` 
1774  1858  if the latter isn't None. 
1775  1859  
1776  1860  EXAMPLES:: 