Ticket #7650: trac_7650-scripts_doctest_force_lib_v3.patch

File trac_7650-scripts_doctest_force_lib_v3.patch, 10.0 KB (added by mpatel, 13 years ago)

Auto-detect site-packages. scripts repo. Replaces previous.

  • sage-doctest

    # HG changeset patch
    # User Mitesh Patel <qed777@gmail.com>
    # Date 1260758966 28800
    # Node ID a5fe7b3281d407d75ca683402200b29c97939ea3
    # Parent  2c17a7cee6e7b76fe67053f34c20ed7c6c33d7cb
    #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/lib") + ":" + LD
     79os.environ["PYTHONPATH"] = os.path.join(SAGE_ROOT,
     80                                        "local/lib/python/site-packages")
    8081if os.environ.has_key('SAGE_PATH'):
    81     os.environ["PYTHONPATH"]= os.environ["PYTHONPATH"]+ ':'+os.environ['SAGE_PATH']
     82    os.environ["PYTHONPATH"] = os.environ["PYTHONPATH"] + ':' + os.environ['SAGE_PATH']
    8283
    8384
    8485######################################################
    8586# Custom flags for the valgrind modes
    8687######################################################
    8788try:
    88     SAGE_MEMCHECK_FLAGS=os.environ['SAGE_MEMCHECK_FLAGS']
     89    SAGE_MEMCHECK_FLAGS = os.environ['SAGE_MEMCHECK_FLAGS']
    8990    print SAGE_MEMCHECK_FLAGS
    9091except:
    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 "
     92    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 "
    9293
    9394try:
    94     SAGE_MASSIF_FLAGS=os.environ['SAGE_MASSIF_FLAGS']
     95    SAGE_MASSIF_FLAGS = os.environ['SAGE_MASSIF_FLAGS']
    9596except:
    96     SAGE_MASSIF_FLAGS=" --depth=6 --log-file=$HOME/.sage/valgrind/sage-massif.%p "
     97    SAGE_MASSIF_FLAGS = " --depth=6 --log-file=$HOME/.sage/valgrind/sage-massif.%p "
    9798
    9899try:
    99     SAGE_CALLGRIND_FLAGS=os.environ['SAGE_CALLGRIND_FLAGS']
     100    SAGE_CALLGRIND_FLAGS = os.environ['SAGE_CALLGRIND_FLAGS']
    100101except:
    101102    SAGE_CALLGRIND_FLAGS = " --log-file=$HOME/.sage/valgrind/sage-callgrind.%p "
    102103
    103104try:
    104     SAGE_CACHEGRIND_FLAGS=os.environ['SAGE_CACHEGRIND_FLAGS']
     105    SAGE_CACHEGRIND_FLAGS = os.environ['SAGE_CACHEGRIND_FLAGS']
    105106except:
    106     SAGE_CACHEGRIND_FLAGS=" --log-file=$HOME/.sage/valgrind/sage-cachegrind.%p "
     107    SAGE_CACHEGRIND_FLAGS = " --log-file=$HOME/.sage/valgrind/sage-cachegrind.%p "
    107108
    108109try:
    109     SAGE_OMEGA_FLAGS=os.environ['SAGE_OMEGA_FLAGS']
     110    SAGE_OMEGA_FLAGS = os.environ['SAGE_OMEGA_FLAGS']
    110111except:
    111112   SAGE_OMEGA_FLAGS = " --log-file=$HOME/.sage/valgrind/sage-omega.%p "
    112113
    def new_index(n): 
    148149        return n
    149150
    150151def test_code(filename):
    151     dict = { 'DIR'             : repr('%s/local/bin' % SAGE_ROOT),
     152    dict = { 'DIR'             : repr(os.path.join(SAGE_ROOT, 'local/bin')),
    152153             'FILENAME'        : repr(filename),
    153154             'OUTPUT_FILENAME' : repr(filename + '.timeit.sobj'),
    154155             'TIMEIT'          : do_timeit, # global
    def change_warning_output(file): 
    404405    if not library_code:
    405406        if ext in ['.py', '.pyx','.spyx']:
    406407            os.system('cp -f %s %s' % (file_name, SAGE_TESTDIR))
    407             tmpfiles.append('%s/%s%s' % (SAGE_TESTDIR, name, ext))
     408            tmpfiles.append(os.path.join(SAGE_TESTDIR, '%s%s' % (name, ext)))
    408409            if ext == '.py':
    409410                s += "from %s import *\n\n" % name
    410411            else:
    def change_warning_output(file): 
    412413        elif ext == '.sage':
    413414            os.system('sage -preparse %s' % file_name)
    414415            os.system('mv -f %s.py %s' % (base, SAGE_TESTDIR))
    415             tmpfiles.append('%s/%s.py' % (SAGE_TESTDIR, name))
     416            tmpfiles.append(os.path.join(SAGE_TESTDIR, name + '.py'))
    416417            s += "from %s import *\n\n" % (name)
    417418        if ext in ['.py', '.sage']:
    418             tmpfiles.append('%s/%s.pyc' % (SAGE_TESTDIR, name))
     419            tmpfiles.append(os.path.join(SAGE_TESTDIR, name + '.pyc'))
    419420
    420421    n = 0
    421422    while True:
    def test_file(file, library_code): 
    589590        if len(s) == 0:
    590591            sys.exit(0)
    591592
    592         f = "%s/.doctest_%s.py"%(SAGE_TESTDIR,name)
     593        f = os.path.join(SAGE_TESTDIR, ".doctest_%s.py" % name)
    593594
    594595        open(f,"w").write(s)
    595596        tmpfiles.append(f)
    def test_file(file, library_code): 
    610611        if omega:
    611612            cmd = "valgrind --tool=exp-omega " + SAGE_OMEGA_FLAGS + cmd
    612613
    613         VALGRIND = '%s/valgrind/'%DOT_SAGE
     614        VALGRIND = os.path.join(DOT_SAGE, 'valgrind')
    614615        if not os.path.exists(VALGRIND):
    615616          os.makedirs(VALGRIND)
    616617
    if __name__ == '__main__': 
    742743        massif     = has_opt('massif')
    743744        cachegrind = has_opt('cachegrind')
    744745        omega      = has_opt('omega')
     746        force_lib  = has_opt('force_lib')
    745747        random_order = parse_rand()
    746748        only_optional, only_optional_tags = parse_only_opt()
    747749        if long_time:
    if __name__ == '__main__': 
    751753        if argv[1][0] == '-':
    752754            usage()
    753755           
     756        ext = os.path.splitext(argv[1])[1]
     757
    754758        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])):
     759        dev_path = os.path.realpath(os.path.join(SAGE_ROOT, 'devel'))
     760        our_path = os.path.realpath(argv[1])
     761
     762        if not force_lib and (ext in ['.spyx', '.sage'] or
     763                              not dev_path in our_path):
    758764            library_code = False
    759765
    760766        try:
  • sage-ptest

    diff --git a/sage-ptest b/sage-ptest
    a b except: 
    1717    numglobaliteration = 1
    1818
    1919SAGE_ROOT = os.environ['SAGE_ROOT']
     20SAGE_SITE = os.path.realpath(os.path.join(os.environ['SAGE_LOCAL'],
     21                                          'lib/python/site-packages'))
    2022BUILD_DIR = os.path.realpath(SAGE_ROOT + "/devel/sage/build")
    2123
    2224print 'Global iterations: ' + str(numglobaliteration)
    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):
     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))
    def populatefilelist(filelist): 
    234240    return 0
    235241
    236242
    237 
    238 
    239 
    240 
    241 
    242 
    243 
    244 
    245243for gr in range(0,numglobaliteration):
    246244
    247245    try:
  • 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/sage-%s' % cmd) + ' "%s"' % F
    8184        err = os.system(s)   # need to catch control c by writing to a file and looking at it??
    8285    except KeyboardInterrupt:
    8386        print "Keyboard Interrupt"
    def test(F, cmd): 
    9295
    9396def test_file(F):
    9497    if not os.path.exists(F):
    95         if os.path.exists(os.environ["SAGE_ROOT"] + "/" + F):
    96             F = os.environ["SAGE_ROOT"] + "/" + F
     98        if os.path.exists(os.path.join(SAGE_ROOT, F)):
     99            F = os.path.join(SAGE_ROOT, F)
    97100    if not os.path.exists(F):
    98101        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))
     102            print "ERROR: File %s is missing" % os.path.join(os.curdir, F)
     103            failed.append(os.path.join(os.curdir, F))
    101104        return 1
    102105
     106    extra_opts = ''
     107    if SAGE_SITE in os.path.realpath(F):
     108        extra_opts = ' -force_lib'
     109
    103110    base, ext = os.path.splitext(F)
    104111    if ext in ['.py', '.spyx', '.pyx', '.tex', '.pxi', '.sage', '.rst']:
    105         return test(F, 'doctest '+opts)
     112        return test(F, 'doctest ' + opts + extra_opts)
    106113    elif os.path.isdir(F) and not (F[:1] == '.') \
    107             and not '#' in F and not '/notes' in F:
     114            and not '#' in F and not os.sep + 'notes' in F:
    108115        ld = os.listdir(F)
    109116        if not ('__nodoctest__' in ld):
    110117            for L in ld:
    111                 k = test_file('%s/%s'%(F,L))
     118                k = test_file(os.path.join(F, L))
    112119    return 0
    113120
    114121files = argv[1:]