# 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: |
80 | 80 | tmpfiles = [] # list of temporary files to be deleted if doctesting succeeds |
81 | 81 | |
82 | 82 | def delete_tmpfiles(): |
83 | | try: |
84 | | for f in tmpfiles: |
| 83 | for f in tmpfiles: |
| 84 | try: |
85 | 85 | os.remove(f) |
86 | | except OSError: |
87 | | pass |
| 86 | except OSError: |
| 87 | pass |
88 | 88 | |
89 | 89 | ###################################################### |
90 | 90 | # Set environment variables |
… |
… |
def check_with_tolerance(expected, actua |
510 | 510 | |
511 | 511 | elif ext in ['.py', '.sage']: |
512 | 512 | |
| 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 | |
513 | 526 | root_name = os.path.basename(root_name) |
514 | 527 | target_name = "%s_%d" % (root_name, os.getpid()) # like 'root_name', but unique |
515 | 528 | target_base = os.path.join(SAGE_TESTDIR, target_name) # like 'target_name' but with full path |
… |
… |
def check_with_tolerance(expected, actua |
524 | 537 | os.system("cp '%s' %s.sage" % (file_name, target_base)) |
525 | 538 | # Now create SAGE_TESTDIR/<target_name>.py: |
526 | 539 | os.system("sage -preparse %s.sage" % target_base) |
| 540 | os.system("mv '%s'.py %s_preparsed.py" % (target_base, target_base)) |
527 | 541 | 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 |
528 | 545 | else: |
529 | 546 | # TODO: instead of copying the file, add its source |
530 | 547 | # directory to PYTHONPATH. We would also have to |
531 | 548 | # 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 |
533 | 553 | |
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 |
538 | 556 | |
539 | 557 | # Prefix/suffix for all doctests replacing the starting/ending """ |
540 | 558 | doc_prefix = 'r""">>> set_random_seed(0L)\n\n>>> change_warning_output(sys.stdout)\n\n' |