Ticket #12069: trac_12069-doctest.patch

File trac_12069-doctest.patch, 3.5 KB (added by jhpalmieri, 11 years ago)

scripts repo

  • sage-doctest

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1321990477 28800
    # Node ID 2f4a1857ea4c0077f2ada607e98476967958a7be
    # Parent  f1e15fa8092f88b108e1331bf74ae16a838f57d3
    #12069: fix doctesting of non-library sage files
    
    diff --git a/sage-doctest b/sage-doctest
    a b else: 
    8080tmpfiles = [] # list of temporary files to be deleted if doctesting succeeds
    8181
    8282def delete_tmpfiles():
    83     try:
    84         for f in tmpfiles:
     83    for f in tmpfiles:
     84        try:
    8585            os.remove(f)
    86     except OSError:
    87         pass
     86        except OSError:
     87            pass
    8888   
    8989######################################################
    9090# Set environment variables
    def check_with_tolerance(expected, actua 
    510510
    511511        elif ext in ['.py', '.sage']:
    512512
     513            # For non-libary files, we need two different Python
     514            # files: one which contains the original Python code,
     515            # which we import, and one which contains the doctesting
     516            # framework.  First for FILE.py or FILE.sage, we replace
     517            # FILE with FILE_PID.  Then for FILE.sage, the imported
     518            # file is the preparsed version, so call that
     519            # FILE_PID_preparsed.py.  For FILE.py, the imported
     520            # version is just a copy of the original file, called
     521            # FILE_PID_orig.py.  The file containing doctesting
     522            # framework will be FILE_PID.py; this gets run through the
     523            # actual doctesting procedure by the 'test_file' function
     524            # below.
     525 
    513526            root_name = os.path.basename(root_name)
    514527            target_name = "%s_%d" % (root_name, os.getpid()) # like 'root_name', but unique
    515528            target_base = os.path.join(SAGE_TESTDIR, target_name) # like 'target_name' but with full path
    def check_with_tolerance(expected, actua 
    524537                os.system("cp '%s' %s.sage" % (file_name, target_base))
    525538                # Now create SAGE_TESTDIR/<target_name>.py:
    526539                os.system("sage -preparse %s.sage" % target_base)
     540                os.system("mv '%s'.py %s_preparsed.py" % (target_base, target_base))
    527541                tmpfiles.append(target_base + ".sage")
     542                s += "\nfrom %s_preparsed import *\n\n" % target_name
     543                tmpfiles.append(target_base + "_preparsed.py") # preparsed version of original
     544                tmpfiles.append(target_base + "_preparsed.pyc") # compiled version
    528545            else:
    529546                # TODO: instead of copying the file, add its source
    530547                # directory to PYTHONPATH.  We would also have to
    531548                # import from 'name' instead of 'target_name'.
    532                 os.system("cp '%s' %s.py" % (file_name, target_base))
     549                os.system("cp '%s' %s_orig.py" % (file_name, target_base))
     550                s += "\nfrom %s_orig import *\n\n" % target_name
     551                tmpfiles.append(target_base + "_orig.py") # copied original
     552                tmpfiles.append(target_base + "_orig.pyc") # compiled version
    533553
    534             s += "from %s import *\n\n" % target_name
    535 
    536             tmpfiles.append(target_base + ".py") # preparsed or copied original
    537             tmpfiles.append(target_base + ".pyc") # compiled version of it
     554            tmpfiles.append(target_base + ".py") # file with doctesting framework
     555            tmpfiles.append(target_base + ".pyc") # compiled version
    538556
    539557    # Prefix/suffix for all doctests replacing the starting/ending """
    540558    doc_prefix = 'r""">>> set_random_seed(0L)\n\n>>> change_warning_output(sys.stdout)\n\n'