Ticket #8641: trac_8641-doctest_exit_codes.2.patch

File trac_8641-doctest_exit_codes.2.patch, 7.1 KB (added by Mitesh Patel, 12 years ago)

Modify sage-ptest, too. Apply to 4.4.4.alpha0 + #8891. Apply only this patch.

  • sage-ptest

    # HG changeset patch
    # User Mitesh Patel <qed777@gmail.com>
    # Date 1276593643 25200
    # Node ID 5af4d4b8651d32b5569a97d7f4091a8c6704eec3
    # Parent  41c43d811d77ebc06c2fc223c3bb7bd36c8322c6
    trac 8641: return nonzero code if tests fail.  Dan Drake, John Palmieri
    
    diff --git a/sage-ptest b/sage-ptest
    a b  
    11#!/usr/bin/env python
    22
    33from __future__ import with_statement
    4 import os, signal, sys, time, thread, threading, tempfile, pickle, multiprocessing
    5 
    6 ####################################
    7 
    8 argv = sys.argv
    9 try:
    10     numiteration = int(os.environ['SAGE_TEST_ITER'])
    11 except:
    12     numiteration = 1
    13 
    14 try:
    15     numglobaliteration = int(os.environ['SAGE_TEST_GLOBAL_ITER'])
    16 except:
    17     numglobaliteration = 1
     4import os
     5import sys
     6import time
     7import pickle
     8import signal
     9import thread
     10import tempfile
     11import subprocess
     12import multiprocessing
    1813
    1914SAGE_ROOT = os.environ['SAGE_ROOT']
    2015SAGE_SITE = os.path.realpath(os.path.join(os.environ['SAGE_LOCAL'],
    2116                                          'lib', 'python', 'site-packages'))
    2217BUILD_DIR = os.path.realpath(os.path.join(SAGE_ROOT, 'devel', 'sage', 'build'))
    2318
     19numiteration = int(os.environ.get('SAGE_TEST_ITER', 1))
     20numglobaliteration = int(os.environ.get('SAGE_TEST_GLOBAL_ITER', 1))
    2421print 'Global iterations: ' + str(numglobaliteration)
    2522print 'File iterations: ' + str(numiteration)
    2623
    27 abort = False
     24# Exit status for the whole run.
     25err = 0
    2826
    2927def abspath(x):
    3028    """
    def abs(f): 
    5755    """
    5856    Return the test command for the file
    5957    """
     58    global opts
    6059    return "sage -t %s %s"%(opts, abspath(f)[len(SAGE_ROOT)+1:])
    6160
    6261def sage_test_cmd(f):
    6362    """
    6463    Return the test command for the file as given
    6564    """
     65    global opts
    6666    return "sage -t %s %s"%(opts, f)
    6767
    6868def abs_sage_path(f):
    def test_file(F): 
    9898    """
    9999    This is the function that actually tests a file
    100100    """
     101    global opts
    101102    outfile = tempfile.NamedTemporaryFile()
    102103    base, ext = os.path.splitext(F)
    103104
    def test_file(F): 
    112113        s = 'bash -c "%s %s > %s" ' % (command, filestr, outfile.name)
    113114        try:
    114115            t = time.time()
    115             ret = os.system(s)
     116            ret = subprocess.call(s, shell=True)
    116117            finished_time = time.time() - t
    117             if ret>=256:
    118                 ret=ret/256
    119             ret = -ret
    120118        except:
    121119            ol = outfile.read()
    122             return (-5, 0, ol)
     120            return (F, 5, 0, ol)
    123121        ol = outfile.read()
    124122        if ret != 0:
    125123            break
    def process_result(result): 
    131129    (F, ret, finished_time, ol)
    132130    and processes it to display/log the appropriate output.
    133131    """
    134     global failed
     132    global err, failed, time_dict
    135133    F = result[0]
    136134    ret = result[1]
    137135    finished_time = result[2]
    138136    ol = result[3]
     137    err = err | ret
    139138    if ret != 0:
    140         if ret == -100:
     139        if ret == 100:
    141140            numfail = ol.count('Expected:') + ol.count('Expected nothing') + ol.count('Exception raised:')
    142141            failed.append(abs(F)+(" # %s doctests failed" % numfail))
    143142            ret = numfail
    144         elif ret == -4:
     143        elif ret == 4:
    145144            failed.append(abs(F)+" # Exception from doctest framework")
    146         elif ret == -3:
     145        elif ret == 3:
    147146            failed.append(abs(F)+" # Killed/crashed")
    148         elif ret == -2:
     147        elif ret == 2:
    149148            failed.append(abs(F)+" # KeyboardInterrupt")
    150         elif ret == -1:
     149        elif ret == 1:
    151150            failed.append(abs(F)+" # File not found")
    152151        else:
    153152            failed.append(abs(F))
    def infiles_cmp(a,b): 
    166165    """
    167166    This compare function is used to sort the list of filenames by the time they take to run
    168167    """
     168    global time_dict
    169169    if time_dict.has_key(abs_sage_path(a)):
    170170        if time_dict.has_key(abs_sage_path(b)):
    171171            return cmp(time_dict[abs_sage_path(a)],time_dict[abs_sage_path(b)])
    def populatefilelist(filelist): 
    215215
    216216
    217217for gr in range(0,numglobaliteration):
    218 
     218    argv = sys.argv
    219219    opts = ' '.join([X for X in argv if X[0] == '-'])
    220220    argv = [X for X in argv if X[0] != '-']
    221221
    for gr in range(0,numglobaliteration): 
    305305
    306306    failed = []
    307307
    308     SAGE_ROOT=os.environ['SAGE_ROOT']
    309308    TMP = os.path.join(os.environ['SAGE_TESTDIR'], 'tmp', 'test')
    310309    if not os.path.exists(TMP):
    311310        os.makedirs(TMP)
    for gr in range(0,numglobaliteration): 
    330329    print "Doctesting %s %s" % (file_str, jobs_str)
    331330       
    332331    try:
    333         from multiprocessing import Pool
    334         p = Pool(numthreads)
     332        p = multiprocessing.Pool(numthreads)
    335333        for r in p.imap_unordered(test_file, files):
    336334            #The format is  (F, ret, finished_time, ol)
    337335            process_result(r)
    338336    except KeyboardInterrupt:
     337        err = 2
    339338        interrupt = True
    340339        pass
    341340    print " "
    for gr in range(0,numglobaliteration): 
    379378            print "Timings have been updated."
    380379
    381380    print "Total time for all tests: %.1f seconds"%(time.time() - t0)
     381
     382sys.exit(err)
  • sage-test

    diff --git a/sage-test b/sage-test
    a b def strip_automount_prefix(filename): 
    2323    """
    2424    Strip prefixes added on automounted filesystems in some cases,
    2525    which make the absolute path appear hidden.
    26    
     26
    2727    AUTHOR:
    2828        -- Kate Minola
    2929    """
    def skip(F): 
    7676failed = []
    7777
    7878def test(F, cmd):
     79    from subprocess import call
    7980    t = time.time()
    8081    if skip(F):
    8182        return 0
    8283    s = os.path.join(SAGE_ROOT, 'local', 'bin', 'sage-%s' % cmd) + ' "%s"' % F
    83     err = os.system(s)
    84     # On unix systems, the return value of os.system has the process return
    85     # value in the second byte.
    86     err = err // 256
     84    err = call(s, shell=True)
    8785
    8886    # Check the process exit code that sage-doctest returns
    8987
    def test_file(F): 
    120118        extra_opts = ' -force_lib'
    121119
    122120    base, ext = os.path.splitext(F)
     121    err = 0
    123122    if ext in ['.py', '.spyx', '.pyx', '.tex', '.pxi', '.sage', '.rst']:
    124         test(F, 'doctest ' + opts + extra_opts)
     123        err = err | test(F, 'doctest ' + opts + extra_opts)
    125124    elif (os.path.isdir(F) and  not '#' in F and
    126125          not os.sep + 'notes' in F):
    127126        ld = os.listdir(F)
    128127        if not ('__nodoctest__' in ld):
    129128            for L in ld:
    130                 k = test_file(os.path.join(F, L))
    131     return 0
     129                err = err | test_file(os.path.join(F, L))
     130    return err
    132131
    133132files = argv[1:]
    134133
    if len(files) == 0: 
    163162    print "     -randorder     -- if given, randomize *order* of tests"
    164163    print "     -randorder=seed-- use seed to get same random order"
    165164    print "     -sagenb        -- test all sagenb files"
    166    
     165
    167166    sys.exit(1)
    168167
    169168files.sort()
    170        
     169
     170err = 0
    171171for F in files:
    172172    try:
    173         test_file(F)
     173        err = err | test_file(F)
    174174    except KeyboardInterrupt:
    175175        print "Aborting further tests."
     176        err = 2
    176177        break
    177    
     178
    178179print " "
    179180print "-"*int(70)
    180181
    else: 
    185186    print "\n\t" + "\n\t".join(failed)
    186187
    187188print "Total time for all tests: %.1f seconds"%(time.time() - t0)
     189sys.exit(err)