Ticket #7650: trac_7650-scripts_doctest_force_lib_v5.patch

File trac_7650-scripts_doctest_force_lib_v5.patch, 16.7 KB (added by mpatel, 13 years ago)

Document new options. More os.path.join-ery. Replaces previous.

  • sage-doctest

    # HG changeset patch
    # User Mitesh Patel <qed777@gmail.com>
    # Date 1260769644 28800
    # Node ID 9f65e5bf20218471be2096cc2448cd53d29cef8f
    # Parent  505395136942ebc633b23694e16d9644ce9fe127
    #7650/doctest: Doctest option to force "library code" test mode
    
    diff --git a/sage-doctest b/sage-doctest
    a b def is_64bit(): 
    5757######################################################   
    5858DOT_SAGE = os.environ['DOT_SAGE']
    5959if 'SAGE_TESTDIR' not in os.environ or os.environ['SAGE_TESTDIR'] is "":
    60     SAGE_TESTDIR = DOT_SAGE + "/tmp"
     60    SAGE_TESTDIR = os.path.join(DOT_SAGE, "tmp")
    6161else:
    6262    SAGE_TESTDIR = os.environ['SAGE_TESTDIR']
    6363
    def delete_tmpfiles(): 
    7575######################################################   
    7676SAGE_ROOT = os.environ["SAGE_ROOT"]
    7777LD = os.environ["LD_LIBRARY_PATH"]
    78 os.environ["LD_LIBRARY_PATH"] = SAGE_ROOT + "/local/lib:" + LD
    79 os.environ["PYTHONPATH"]=SAGE_ROOT + "/local/lib/python/site-packages"
     78os.environ["LD_LIBRARY_PATH"] = os.path.join(SAGE_ROOT, 'local',
     79                                             'lib') + ":" + LD
     80os.environ["PYTHONPATH"] = os.path.join(SAGE_ROOT, 'local', 'lib', 'python',
     81                                        'site-packages')
    8082if os.environ.has_key('SAGE_PATH'):
    81     os.environ["PYTHONPATH"]= os.environ["PYTHONPATH"]+ ':'+os.environ['SAGE_PATH']
     83    os.environ["PYTHONPATH"] = os.environ["PYTHONPATH"] + ':' + os.environ['SAGE_PATH']
    8284
    8385
    8486######################################################
    8587# Custom flags for the valgrind modes
    8688######################################################
     89logfile = ' --log-file=' + os.path.join('$HOME', '.sage', 'valgrind', 'sage-%s') + ' '
    8790try:
    88     SAGE_MEMCHECK_FLAGS=os.environ['SAGE_MEMCHECK_FLAGS']
     91    SAGE_MEMCHECK_FLAGS = os.environ['SAGE_MEMCHECK_FLAGS']
    8992    print SAGE_MEMCHECK_FLAGS
    9093except:
    91     SAGE_MEMCHECK_FLAGS=" --leak-resolution=high --log-file=$HOME/.sage/valgrind/sage-memcheck.%p --leak-check=full --num-callers=25 --suppressions=$SAGE_LOCAL/lib/valgrind/sage.supp "
     94    suppfile = os.path.join('$SAGE_LOCAL', 'lib', 'valgrind', 'sage.supp')
     95    SAGE_MEMCHECK_FLAGS = " --leak-resolution=high %s --leak-check=full --num-callers=25 --suppressions=%s " % (logfile % 'memcheck.%p', suppfile)
    9296
    9397try:
    94     SAGE_MASSIF_FLAGS=os.environ['SAGE_MASSIF_FLAGS']
     98    SAGE_MASSIF_FLAGS = os.environ['SAGE_MASSIF_FLAGS']
    9599except:
    96     SAGE_MASSIF_FLAGS=" --depth=6 --log-file=$HOME/.sage/valgrind/sage-massif.%p "
     100    SAGE_MASSIF_FLAGS = " --depth=6 " + (logfile % 'massif.%p')
    97101
    98102try:
    99     SAGE_CALLGRIND_FLAGS=os.environ['SAGE_CALLGRIND_FLAGS']
     103    SAGE_CALLGRIND_FLAGS = os.environ['SAGE_CALLGRIND_FLAGS']
    100104except:
    101     SAGE_CALLGRIND_FLAGS = " --log-file=$HOME/.sage/valgrind/sage-callgrind.%p "
     105    SAGE_CALLGRIND_FLAGS = logfile % 'callgrind.%p'
    102106
    103107try:
    104     SAGE_CACHEGRIND_FLAGS=os.environ['SAGE_CACHEGRIND_FLAGS']
     108    SAGE_CACHEGRIND_FLAGS = os.environ['SAGE_CACHEGRIND_FLAGS']
    105109except:
    106     SAGE_CACHEGRIND_FLAGS=" --log-file=$HOME/.sage/valgrind/sage-cachegrind.%p "
     110    SAGE_CALLGRIND_FLAGS = logfile % 'cachegrind.%p'
    107111
    108112try:
    109     SAGE_OMEGA_FLAGS=os.environ['SAGE_OMEGA_FLAGS']
     113    SAGE_OMEGA_FLAGS = os.environ['SAGE_OMEGA_FLAGS']
    110114except:
    111    SAGE_OMEGA_FLAGS = " --log-file=$HOME/.sage/valgrind/sage-omega.%p "
     115    SAGE_OMEGA_FLAGS = logfile % 'omega.%p'
    112116
    113117######################################################
    114118# The Python binary
    def new_index(n): 
    148152        return n
    149153
    150154def test_code(filename):
    151     dict = { 'DIR'             : repr('%s/local/bin' % SAGE_ROOT),
     155    dict = { 'DIR'             : repr(os.path.join(SAGE_ROOT, 'local', 'bin')),
    152156             'FILENAME'        : repr(filename),
    153157             'OUTPUT_FILENAME' : repr(filename + '.timeit.sobj'),
    154158             'TIMEIT'          : do_timeit, # global
    def change_warning_output(file): 
    404408    if not library_code:
    405409        if ext in ['.py', '.pyx','.spyx']:
    406410            os.system('cp -f %s %s' % (file_name, SAGE_TESTDIR))
    407             tmpfiles.append('%s/%s%s' % (SAGE_TESTDIR, name, ext))
     411            tmpfiles.append(os.path.join(SAGE_TESTDIR, '%s%s' % (name, ext)))
    408412            if ext == '.py':
    409413                s += "from %s import *\n\n" % name
    410414            else:
    def change_warning_output(file): 
    412416        elif ext == '.sage':
    413417            os.system('sage -preparse %s' % file_name)
    414418            os.system('mv -f %s.py %s' % (base, SAGE_TESTDIR))
    415             tmpfiles.append('%s/%s.py' % (SAGE_TESTDIR, name))
     419            tmpfiles.append(os.path.join(SAGE_TESTDIR, name + '.py'))
    416420            s += "from %s import *\n\n" % (name)
    417421        if ext in ['.py', '.sage']:
    418             tmpfiles.append('%s/%s.pyc' % (SAGE_TESTDIR, name))
     422            tmpfiles.append(os.path.join(SAGE_TESTDIR, name + '.pyc'))
    419423
    420424    n = 0
    421425    while True:
    def test_file(file, library_code): 
    589593        if len(s) == 0:
    590594            sys.exit(0)
    591595
    592         f = "%s/.doctest_%s.py"%(SAGE_TESTDIR,name)
     596        f = os.path.join(SAGE_TESTDIR, ".doctest_%s.py" % name)
    593597
    594598        open(f,"w").write(s)
    595599        tmpfiles.append(f)
    def test_file(file, library_code): 
    610614        if omega:
    611615            cmd = "valgrind --tool=exp-omega " + SAGE_OMEGA_FLAGS + cmd
    612616
    613         VALGRIND = '%s/valgrind/'%DOT_SAGE
     617        VALGRIND = os.path.join(DOT_SAGE, 'valgrind')
    614618        if not os.path.exists(VALGRIND):
    615619          os.makedirs(VALGRIND)
    616620
    if __name__ == '__main__': 
    742746        massif     = has_opt('massif')
    743747        cachegrind = has_opt('cachegrind')
    744748        omega      = has_opt('omega')
     749        force_lib  = has_opt('force_lib')
    745750        random_order = parse_rand()
    746751        only_optional, only_optional_tags = parse_only_opt()
    747752        if long_time:
    if __name__ == '__main__': 
    751756        if argv[1][0] == '-':
    752757            usage()
    753758           
     759        ext = os.path.splitext(argv[1])[1]
     760
    754761        library_code = True
    755         ext = os.path.splitext(argv[1])[1]
    756         if ext in ['.spyx', '.sage'] or \
    757                 not (os.path.realpath(os.path.join(SAGE_ROOT, 'devel')) in os.path.realpath(argv[1])):
     762        dev_path = os.path.realpath(os.path.join(SAGE_ROOT, 'devel'))
     763        our_path = os.path.realpath(argv[1])
     764
     765        if not force_lib and (ext in ['.spyx', '.sage'] or
     766                              not dev_path in our_path):
    758767            library_code = False
    759768
    760769        try:
  • sage-maketest

    diff --git a/sage-maketest b/sage-maketest
    a b fi 
    2323# (We do this all in a single run of "sage -t" so we get a single summary.)
    2424# We test three subdirectories of doc/, rather than testing the
    2525# entirety of doc/, so that we can skip doc/output.
    26 "$SAGE_ROOT"/sage -t "$@" "$SAGE_ROOT"/devel/sage/doc/common "$SAGE_ROOT"/devel/sage/doc/en "$SAGE_ROOT"/devel/sage/doc/fr  "$SAGE_ROOT"/devel/sage/sage 2>&1 | tee -a "$SAGE_TEST_LOG"
     26"$SAGE_ROOT"/sage -t -sagenb "$@" "$SAGE_ROOT"/devel/sage/doc/common "$SAGE_ROOT"/devel/sage/doc/en "$SAGE_ROOT"/devel/sage/doc/fr  "$SAGE_ROOT"/devel/sage/sage 2>&1 | tee -a "$SAGE_TEST_LOG"
    2727
    2828# Print the small summary report for dsage unit tests, if necessary.
    2929# TODO -- skip this for now.
  • sage-ptest

    diff --git a/sage-ptest b/sage-ptest
    a b except: 
    1717    numglobaliteration = 1
    1818
    1919SAGE_ROOT = os.environ['SAGE_ROOT']
    20 BUILD_DIR = os.path.realpath(SAGE_ROOT + "/devel/sage/build")
     20SAGE_SITE = os.path.realpath(os.path.join(os.environ['SAGE_LOCAL'],
     21                                          'lib', 'python', 'site-packages'))
     22BUILD_DIR = os.path.realpath(os.path.join(SAGE_ROOT, 'devel', 'sage', 'build'))
    2123
    2224print 'Global iterations: ' + str(numglobaliteration)
    2325print 'File iterations: ' + str(numiteration)
    def skip(F): 
    100102    if not os.path.exists(F):
    101103        return True
    102104    G = abspath(F)
    103     i = G.rfind('/')
    104     if os.path.exists('%s/nodoctest.py'%G[:i]):
     105    i = G.rfind(os.path.sep)
     106    if os.path.exists(os.path.join(G[:i], 'nodoctest.py')):
    105107        printmutex.acquire()
    106108        print "%s (skipping) -- nodoctest.py file in directory"%abs(F)
    107109        printmutex.release()
    108110        return True
    109111    filenm = os.path.split(F)[1]
    110     if filenm[0] == '.' or '/.' in G.lstrip('/.') or \
    111           'nodoctest' in open(G).read()[:50]:
     112    if (filenm[0] == '.' or (os.path.sep + '.' in G.lstrip(os.path.sep + '.'))
     113        or 'nodoctest' in open(G).read()[:50]):
    112114        return True
    113     if G.find('doc/output') != -1:
     115    if G.find(os.path.join('doc', 'output')) != -1:
    114116        return True
    115117    if not (os.path.splitext(F)[1] in ['.py', '.pyx', '.tex', '.pxi', '.sage', '.rst']):
    116118        return True
    def test_file(F): 
    122124    """
    123125    outfile = tempfile.NamedTemporaryFile()
    124126    base, ext = os.path.splitext(F)
     127
    125128    if use_sage_only or ext == '.sage':
    126129        cmd =  'doctest_tex ' + opts
    127130    elif ext in ['.py', '.pyx', '.tex', '.pxi', '.rst']:
    128         cmd = 'doctest '+opts
     131        cmd = 'doctest ' + opts
     132    if SAGE_SITE in os.path.realpath(F) and not '-force_lib' in cmd:
     133        cmd += ' -force_lib'
     134
    129135    filestr = os.path.split(F)[1]
    130136    for i in range(0,numiteration):
    131137        os.chdir(os.path.dirname(F))
    132         s = 'bash -c "%s/local/bin/sage-%s %s > %s" ' %(SAGE_ROOT, cmd, filestr, outfile.name)
     138        command = os.path.join(SAGE_ROOT, 'local', 'bin', 'sage-%s' % cmd)
     139        s = 'bash -c "%s %s > %s" ' % (command, filestr, outfile.name)
    133140        try:
    134141            t = time.time()
    135142            ret = os.system(s)
    def populatefilelist(filelist): 
    204211                continue
    205212            if not os.path.isabs(FF):
    206213                cwd = os.getcwd()
    207                 files.append(cwd + '/' +  FF)
     214                files.append(os.path.join(cwd, FF))
    208215            else:
    209216                files.append(FF)
    210217            continue
    def populatefilelist(filelist): 
    228235                    continue
    229236                files.append(appendstr)
    230237            for D in dirs:
    231                 if '#' in D or '/notes' in D:
     238                if '#' in D or (os.path.sep + 'notes' in D):
    232239                    dirs.remove(D)
    233240    filemutex.release()
    234241    return 0
    235242
    236243
    237 
    238 
    239 
    240 
    241 
    242 
    243 
    244 
    245244for gr in range(0,numglobaliteration):
    246245
    247246    try:
    for gr in range(0,numglobaliteration): 
    261260        numthreads = 1
    262261        infiles = argv[1:]
    263262
     263    if '-sagenb' in opts:
     264        opts = opts.replace('--sagenb', '').replace('-sagenb', '')
     265
     266        # Find SageNB's home.
     267        from pkg_resources import Requirement, working_set
     268        sagenb_loc = working_set.find(Requirement.parse('sagenb')).location
     269
     270        # In case we're using setuptools' "develop" mode.
     271        if not SAGE_SITE in sagenb_loc:
     272            opts += ' -force_lib'
     273
     274        infiles.append(os.path.join(sagenb_loc, 'sagenb'))
     275
    264276    if numthreads == 0:
    265277        # Set numthreads to be the number of processors, with a default
    266278        # maximum of 8.
    for gr in range(0,numglobaliteration): 
    298310    filemutex = thread.allocate_lock()
    299311    printmutex = thread.allocate_lock()
    300312    #Pick a filename for the timing files -- long vs normal
    301     time_file_name = os.environ["SAGE_TESTDIR"]+"/"
    302313    if opts.count("-long"):
    303         time_file_name+=".ptest_timing_long"
     314        time_file_name = os.path.join(os.environ["SAGE_TESTDIR"],
     315                                      '.ptest_timing_long')
    304316    else:
    305         time_file_name+=".ptest_timing"
     317        time_file_name = os.path.join(os.environ["SAGE_TESTDIR"],
     318                                      '.ptest_timing')
    306319    time_dict = { }
    307320    try:
    308321        with open(time_file_name) as time_file:
    for gr in range(0,numglobaliteration): 
    324337    failed = []
    325338
    326339    SAGE_ROOT=os.environ['SAGE_ROOT']
    327     TMP=os.environ['SAGE_TESTDIR'] + "/tmp/test/"
     340    TMP = os.path.join(os.environ['SAGE_TESTDIR'], 'tmp', 'test')
    328341    if not os.path.exists(TMP):
    329342        os.makedirs(TMP)
    330343
    for gr in range(0,numglobaliteration): 
    380393        print "-"*int(70)
    381394
    382395    print "Total time for all tests: %.1f seconds"%(time.time() - t0)
    383 
    384 
  • sage-test

    diff --git a/sage-test b/sage-test
    a b def strip_automount_prefix(filename): 
    4141    return filename
    4242
    4343
    44 SAGE_ROOT=os.environ['SAGE_ROOT']
     44SAGE_ROOT = os.environ['SAGE_ROOT']
     45SAGE_SITE = os.path.realpath(os.path.join(os.environ['SAGE_LOCAL'],
     46                                          'lib', 'python', 'site-packages'))
     47
    4548if 'SAGE_TESTDIR' not in os.environ:
    46     os.environ['SAGE_TESTDIR'] = SAGE_ROOT + "/tmp"
    47 TMP=os.environ['SAGE_TESTDIR'] + "/tmp"
     49    os.environ['SAGE_TESTDIR'] = os.path.join(SAGE_ROOT, "tmp")
     50TMP = os.path.join(os.environ['SAGE_TESTDIR'], "tmp")
    4851if not os.path.exists(TMP):
    4952    os.makedirs(TMP)
    5053
    def sage_test_command(f): 
    5659
    5760def skip(F):
    5861    G = abspath(F)
    59     i = G.rfind('/')
    60     if os.path.exists('%s/nodoctest.py'%G[:i]):
     62    i = G.rfind(os.sep)
     63    if os.path.exists(os.path.join(G[:i], 'nodoctest.py')):
    6164        print "%s (skipping) -- nodoctest.py file in directory"%sage_test_command(F)
    6265        return True
    6366
    6467    if 'nodoctest' in open(G).read()[:50]:
    6568        return True
    66     if G.find('doc/output') != -1:
     69    if G.find(os.path.join('doc', 'output')) != -1:
    6770        return True
    6871
    6972    sys.stdout.write("%-60s"%sage_test_command(F)+"\n")
    def test(F, cmd): 
    7780    if skip(F):
    7881        return 0
    7982    try:
    80         s = '%s/local/bin/sage-%s "%s"'%(SAGE_ROOT, cmd, F)
     83        s = os.path.join(SAGE_ROOT, 'local', 'bin',
     84                         'sage-%s' % cmd) + ' "%s"' % F
    8185        err = os.system(s)   # need to catch control c by writing to a file and looking at it??
    8286    except KeyboardInterrupt:
    8387        print "Keyboard Interrupt"
    def test(F, cmd): 
    9296
    9397def test_file(F):
    9498    if not os.path.exists(F):
    95         if os.path.exists(os.environ["SAGE_ROOT"] + "/" + F):
    96             F = os.environ["SAGE_ROOT"] + "/" + F
     99        if os.path.exists(os.path.join(SAGE_ROOT, F)):
     100            F = os.path.join(SAGE_ROOT, F)
    97101    if not os.path.exists(F):
    98102        if F[:6] != "__test" and not F.endswith('.png'):
    99             print "ERROR: File %s/%s is missing"%(os.curdir,F)
    100             failed.append('%s/%s'%(os.curdir,F))
     103            print "ERROR: File %s is missing" % os.path.join(os.curdir, F)
     104            failed.append(os.path.join(os.curdir, F))
    101105        return 1
    102106
     107    extra_opts = ''
     108    if SAGE_SITE in os.path.realpath(F) and not '-force_lib' in opts:
     109        extra_opts = ' -force_lib'
     110
    103111    base, ext = os.path.splitext(F)
    104112    if ext in ['.py', '.spyx', '.pyx', '.tex', '.pxi', '.sage', '.rst']:
    105         return test(F, 'doctest '+opts)
     113        return test(F, 'doctest ' + opts + extra_opts)
    106114    elif os.path.isdir(F) and not (F[:1] == '.') \
    107             and not '#' in F and not '/notes' in F:
     115            and not '#' in F and not os.sep + 'notes' in F:
    108116        ld = os.listdir(F)
    109117        if not ('__nodoctest__' in ld):
    110118            for L in ld:
    111                 k = test_file('%s/%s'%(F,L))
     119                k = test_file(os.path.join(F, L))
    112120    return 0
    113121
    114122files = argv[1:]
     123
     124if '-sagenb' in opts:
     125    opts = opts.replace('--sagenb', '').replace('-sagenb', '')
     126
     127    # Find SageNB's home.
     128    from pkg_resources import Requirement, working_set
     129    sagenb_loc = working_set.find(Requirement.parse('sagenb')).location
     130
     131    # In case we're using setuptools' "develop" mode.
     132    if not SAGE_SITE in sagenb_loc:
     133        opts += ' -force_lib'
     134
     135    files.append(os.path.join(sagenb_loc, 'sagenb'))
     136
    115137if len(files) == 0:
    116138    print "Usage: sage -t [-verbose] [-long] [-optional] [-only-optional=list,of,tags] <files or directories>"
    117139    print "Test the docstrings in each listed Python or Cython file, and "
    if len(files) == 0: 
    119141    print "all subdirectories of that directory."
    120142    print ""
    121143    print "OPTIONS:"
     144    print "     -force_lib     -- assume all files are Sage library files,"
     145    print "                       regardless of location"
    122146    print "     -long          -- include lines with the phrase 'long time'"
    123     print "     -verbose       -- print debuging output during the test"
     147    print "     -verbose       -- print debugging output during the test"
    124148    print "     -optional      -- also test all #optional examples"
    125149    print "     -only-optional=list,of,tags -- only run doctests with "
    126150    print "                       #optional <nonempty subset of tags>"
    127151    print "      if the list of tags is omitted, run all optional doctests"
    128152    print "     -randorder     -- if given, randomize *order* of tests"
    129153    print "     -randorder=seed-- use seed to get same random order"
     154    print "     -sagenb        -- test all sagenb files"
    130155   
    131156    sys.exit(1)
    132157
    else: 
    148173    print "\n\t" + "\n\t".join(failed)
    149174
    150175print "Total time for all tests: %.1f seconds"%(time.time() - t0)
    151 
    152 
    153