# HG changeset patch
# User Mitesh Patel <qed777@gmail.com>
# Date 1260541594 28800
# Node ID 395d568ba559a6254fa636476444b4d516beab0d
# 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(): |
57 | 57 | ###################################################### |
58 | 58 | DOT_SAGE = os.environ['DOT_SAGE'] |
59 | 59 | if '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") |
61 | 61 | else: |
62 | 62 | SAGE_TESTDIR = os.environ['SAGE_TESTDIR'] |
63 | 63 | |
… |
… |
def delete_tmpfiles(): |
75 | 75 | ###################################################### |
76 | 76 | SAGE_ROOT = os.environ["SAGE_ROOT"] |
77 | 77 | LD = 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" |
| 78 | os.environ["LD_LIBRARY_PATH"] = os.path.join(SAGE_ROOT, "local/lib") + ":" + LD |
| 79 | os.environ["PYTHONPATH"] = os.path.join(SAGE_ROOT, |
| 80 | "local/lib/python/site-packages") |
80 | 81 | if 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'] |
82 | 83 | |
83 | 84 | |
84 | 85 | ###################################################### |
85 | 86 | # Custom flags for the valgrind modes |
86 | 87 | ###################################################### |
87 | 88 | try: |
88 | | SAGE_MEMCHECK_FLAGS=os.environ['SAGE_MEMCHECK_FLAGS'] |
| 89 | SAGE_MEMCHECK_FLAGS = os.environ['SAGE_MEMCHECK_FLAGS'] |
89 | 90 | print SAGE_MEMCHECK_FLAGS |
90 | 91 | except: |
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 " |
92 | 93 | |
93 | 94 | try: |
94 | | SAGE_MASSIF_FLAGS=os.environ['SAGE_MASSIF_FLAGS'] |
| 95 | SAGE_MASSIF_FLAGS = os.environ['SAGE_MASSIF_FLAGS'] |
95 | 96 | except: |
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 " |
97 | 98 | |
98 | 99 | try: |
99 | | SAGE_CALLGRIND_FLAGS=os.environ['SAGE_CALLGRIND_FLAGS'] |
| 100 | SAGE_CALLGRIND_FLAGS = os.environ['SAGE_CALLGRIND_FLAGS'] |
100 | 101 | except: |
101 | 102 | SAGE_CALLGRIND_FLAGS = " --log-file=$HOME/.sage/valgrind/sage-callgrind.%p " |
102 | 103 | |
103 | 104 | try: |
104 | | SAGE_CACHEGRIND_FLAGS=os.environ['SAGE_CACHEGRIND_FLAGS'] |
| 105 | SAGE_CACHEGRIND_FLAGS = os.environ['SAGE_CACHEGRIND_FLAGS'] |
105 | 106 | except: |
106 | | SAGE_CACHEGRIND_FLAGS=" --log-file=$HOME/.sage/valgrind/sage-cachegrind.%p " |
| 107 | SAGE_CACHEGRIND_FLAGS = " --log-file=$HOME/.sage/valgrind/sage-cachegrind.%p " |
107 | 108 | |
108 | 109 | try: |
109 | | SAGE_OMEGA_FLAGS=os.environ['SAGE_OMEGA_FLAGS'] |
| 110 | SAGE_OMEGA_FLAGS = os.environ['SAGE_OMEGA_FLAGS'] |
110 | 111 | except: |
111 | 112 | SAGE_OMEGA_FLAGS = " --log-file=$HOME/.sage/valgrind/sage-omega.%p " |
112 | 113 | |
… |
… |
def new_index(n): |
148 | 149 | return n |
149 | 150 | |
150 | 151 | def test_code(filename): |
151 | | dict = { 'DIR' : repr('%s/local/bin' % SAGE_ROOT), |
| 152 | dict = { 'DIR' : repr(os.path.join(SAGE_ROOT, 'local/bin')), |
152 | 153 | 'FILENAME' : repr(filename), |
153 | 154 | 'OUTPUT_FILENAME' : repr(filename + '.timeit.sobj'), |
154 | 155 | 'TIMEIT' : do_timeit, # global |
… |
… |
def change_warning_output(file): |
404 | 405 | if not library_code: |
405 | 406 | if ext in ['.py', '.pyx','.spyx']: |
406 | 407 | 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))) |
408 | 409 | if ext == '.py': |
409 | 410 | s += "from %s import *\n\n" % name |
410 | 411 | else: |
… |
… |
def change_warning_output(file): |
412 | 413 | elif ext == '.sage': |
413 | 414 | os.system('sage -preparse %s' % file_name) |
414 | 415 | 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')) |
416 | 417 | s += "from %s import *\n\n" % (name) |
417 | 418 | if ext in ['.py', '.sage']: |
418 | | tmpfiles.append('%s/%s.pyc' % (SAGE_TESTDIR, name)) |
| 419 | tmpfiles.append(os.path.join(SAGE_TESTDIR, name + '.pyc')) |
419 | 420 | |
420 | 421 | n = 0 |
421 | 422 | while True: |
… |
… |
def test_file(file, library_code): |
589 | 590 | if len(s) == 0: |
590 | 591 | sys.exit(0) |
591 | 592 | |
592 | | f = "%s/.doctest_%s.py"%(SAGE_TESTDIR,name) |
| 593 | f = os.path.join(SAGE_TESTDIR, ".doctest_%s.py" % name) |
593 | 594 | |
594 | 595 | open(f,"w").write(s) |
595 | 596 | tmpfiles.append(f) |
… |
… |
def test_file(file, library_code): |
610 | 611 | if omega: |
611 | 612 | cmd = "valgrind --tool=exp-omega " + SAGE_OMEGA_FLAGS + cmd |
612 | 613 | |
613 | | VALGRIND = '%s/valgrind/'%DOT_SAGE |
| 614 | VALGRIND = os.path.join(DOT_SAGE, 'valgrind') |
614 | 615 | if not os.path.exists(VALGRIND): |
615 | 616 | os.makedirs(VALGRIND) |
616 | 617 | |
… |
… |
if __name__ == '__main__': |
742 | 743 | massif = has_opt('massif') |
743 | 744 | cachegrind = has_opt('cachegrind') |
744 | 745 | omega = has_opt('omega') |
| 746 | force_lib = has_opt('force_lib') |
745 | 747 | random_order = parse_rand() |
746 | 748 | only_optional, only_optional_tags = parse_only_opt() |
747 | 749 | if long_time: |
… |
… |
if __name__ == '__main__': |
751 | 753 | if argv[1][0] == '-': |
752 | 754 | usage() |
753 | 755 | |
| 756 | ext = os.path.splitext(argv[1])[1] |
| 757 | |
754 | 758 | 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): |
758 | 764 | library_code = False |
759 | 765 | |
760 | 766 | try: |
diff --git a/sage-test b/sage-test
a
|
b
|
def strip_automount_prefix(filename): |
43 | 43 | |
44 | 44 | SAGE_ROOT=os.environ['SAGE_ROOT'] |
45 | 45 | if 'SAGE_TESTDIR' not in os.environ: |
46 | | os.environ['SAGE_TESTDIR'] = SAGE_ROOT + "/tmp" |
47 | | TMP=os.environ['SAGE_TESTDIR'] + "/tmp" |
| 46 | os.environ['SAGE_TESTDIR'] = os.path.join(SAGE_ROOT, "tmp") |
| 47 | TMP = os.path.join(os.environ['SAGE_TESTDIR'], "tmp") |
48 | 48 | if not os.path.exists(TMP): |
49 | 49 | os.makedirs(TMP) |
50 | 50 | |
… |
… |
def sage_test_command(f): |
56 | 56 | |
57 | 57 | def skip(F): |
58 | 58 | G = abspath(F) |
59 | | i = G.rfind('/') |
60 | | if os.path.exists('%s/nodoctest.py'%G[:i]): |
| 59 | i = G.rfind(os.sep) |
| 60 | if os.path.exists(os.path.join(G[:i], 'nodoctest.py')): |
61 | 61 | print "%s (skipping) -- nodoctest.py file in directory"%sage_test_command(F) |
62 | 62 | return True |
63 | 63 | |
64 | 64 | if 'nodoctest' in open(G).read()[:50]: |
65 | 65 | return True |
66 | | if G.find('doc/output') != -1: |
| 66 | if G.find(os.path.join('doc', 'output')) != -1: |
67 | 67 | return True |
68 | 68 | |
69 | 69 | sys.stdout.write("%-60s"%sage_test_command(F)+"\n") |
… |
… |
def test(F, cmd): |
77 | 77 | if skip(F): |
78 | 78 | return 0 |
79 | 79 | try: |
80 | | s = '%s/local/bin/sage-%s "%s"'%(SAGE_ROOT, cmd, F) |
| 80 | s = os.path.join(SAGE_ROOT, 'local/bin/sage-%s' % cmd) + ' "%s"' % F |
81 | 81 | err = os.system(s) # need to catch control c by writing to a file and looking at it?? |
82 | 82 | except KeyboardInterrupt: |
83 | 83 | print "Keyboard Interrupt" |
… |
… |
def test(F, cmd): |
92 | 92 | |
93 | 93 | def test_file(F): |
94 | 94 | if not os.path.exists(F): |
95 | | if os.path.exists(os.environ["SAGE_ROOT"] + "/" + F): |
96 | | F = os.environ["SAGE_ROOT"] + "/" + F |
| 95 | if os.path.exists(os.path.join(os.environ["SAGE_ROOT"], F)): |
| 96 | F = os.path.join(os.environ["SAGE_ROOT"], F) |
97 | 97 | if not os.path.exists(F): |
98 | 98 | 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)) |
| 99 | print "ERROR: File %s is missing" % os.path.join(os.curdir, F) |
| 100 | failed.append(os.path.join(os.curdir, F)) |
101 | 101 | return 1 |
102 | 102 | |
103 | 103 | base, ext = os.path.splitext(F) |
104 | 104 | if ext in ['.py', '.spyx', '.pyx', '.tex', '.pxi', '.sage', '.rst']: |
105 | | return test(F, 'doctest '+opts) |
| 105 | return test(F, 'doctest ' + opts) |
106 | 106 | elif os.path.isdir(F) and not (F[:1] == '.') \ |
107 | | and not '#' in F and not '/notes' in F: |
| 107 | and not '#' in F and not os.sep + 'notes' in F: |
108 | 108 | ld = os.listdir(F) |
109 | 109 | if not ('__nodoctest__' in ld): |
110 | 110 | for L in ld: |
111 | | k = test_file('%s/%s'%(F,L)) |
| 111 | k = test_file(os.path.join(F, L)) |
112 | 112 | return 0 |
113 | 113 | |
114 | 114 | files = argv[1:] |