Ticket #1276: trac_1276_scripts.patch
File trac_1276_scripts.patch, 3.5 KB (added by , 15 years ago) |
---|
-
sage-doctest
# HG changeset patch # User Gary Furnish <gfurnish@gfurnish.net> # Date 1211668843 21600 # Node ID 4db48de805ef3999f3e07fdcffb17ad92770c572 # Parent d8687692111eba0b3c8439914c82fefe5b42301f trac #1276 diff -r d8687692111e -r 4db48de805ef sage-doctest
a b optional = False 12 12 optional = False 13 13 long_time = False 14 14 verbose = False 15 time_runs = False 15 16 16 17 argv = sys.argv 17 18 18 19 import sage.misc.preparser 20 from sage.misc.misc import pad_zeros 19 21 20 22 ###################################################### 21 23 # This code is copied from sage.misc.misc for speed: … … os.environ["PYTHONPATH"]=SAGE_ROOT + "/l 42 44 43 45 PYTHON = SAGE_ROOT + "/local/bin/python" 44 46 45 def test_code(): 46 return """ 47 def test_code(file_name): 48 if not time_runs: 49 return """ 47 50 if __name__ == '__main__': 48 51 import doctest, sys 49 52 s = doctest.testmod(sys.modules[__name__], … … if __name__ == '__main__': 53 56 globs=globals()) 54 57 quit_sage(verbose=False) 55 58 """%verbose 59 else: 60 #TODO: before computing dochash, only keep actual input (and possibly 61 # output), stripping all comments from the docstring 62 return """ 63 from sage.misc.timing import DocTestTiming 64 timings = {} 65 66 def time_run(self, test, *p, **k): 67 import time, re 68 from sage.misc.misc import cputime 69 t = cputime() 70 starttime = time.time() 71 self.old_run(test, *p, **k) 72 cput = cputime(t) 73 wallt = time.time()-starttime 74 p = test.name.find("example_") 75 if p != -1: 76 num = test.name[p:] 77 r = re.compile(r"###line (\d+):_sage_") 78 try: 79 linenum = r.search(test.docstring).group(1) 80 dochash = hash(r.sub("###line N:_sage_", test.docstring)) 81 t = DocTestTiming("%s", linenum, num, dochash, cput, wallt) 82 timings[dochash] = t 83 if %s: 84 t.show() 85 except: 86 pass 87 88 if __name__ == '__main__': 89 import doctest, sys 90 from sage.misc.db import save,load 91 doctest.DocTestRunner.old_run = doctest.DocTestRunner.run 92 doctest.DocTestRunner.run = time_run 93 try: 94 timings = load("tmp/.doctest/timings.sobj") 95 except AssertionError: 96 timings = {} 97 s = doctest.testmod(sys.modules[__name__], 98 optionflags=doctest.NORMALIZE_WHITESPACE 99 |doctest.ELLIPSIS, 100 verbose=%s, 101 globs=globals()) 102 quit_sage(verbose=False) 103 save(timings, "tmp/.doctest/timings.sobj") 104 """%(file_name,verbose,verbose) 56 105 57 106 ALARM = """ 58 107 import signal … … def extract_doc(file_name, module): 212 261 ## name = 'example' 213 262 k = F[i+3].find('"""') 214 263 j = i+3 + F[i+3:].find('"""') 215 s += "def %s_%s():"%(name, n)264 s += "def %s_%s():"%(name,pad_zeros(n)) 216 265 n += 1 217 266 try: 218 267 doc = doc_preparse(F[i:j+3]) … … def extract_doc(file_name, module): 229 278 # s += test_code() 230 279 # s += ' __doctest_cleanup()\n' 231 280 #else: 232 s += test_code( )281 s += test_code(file_name) 233 282 s += ' sys.exit(s[0])' 234 283 235 284 … … if __name__ == '__main__': 423 472 massif = has_opt('massif') 424 473 cachegrind = has_opt('cachegrind') 425 474 omega = has_opt('omega') 475 time_runs = has_opt('time') 426 476 if long_time: 427 477 TIMEOUT = TIMEOUT_LONG 428 478 if gdb or memcheck or massif or cachegrind or omega: