Ticket #10030: 10030_scripts_doctest.patch

File 10030_scripts_doctest.patch, 3.7 KB (added by jdemeyer, 9 years ago)

SCRIPTS patch, patch for sage-doctest

  • sage-doctest

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1289516849 -3600
    # Node ID 51391a6883cbcaf213630311da8eee63c89bb5ae
    # Parent  a96a519334af9afa47f4eab7a0739e1d6ed915e6
    #10030: Check that sig_on_count() is 0 after every doctest
    
    diff -r a96a519334af -r 51391a6883cb sage-doctest
    a b  
    451451        if ext in ['.py', '.sage']:
    452452            tmpfiles.append(os.path.join(SAGE_TESTDIR, name + '.pyc'))
    453453
     454    # Prefix/suffix for all doctests replacing the starting/ending """
     455    doc_prefix = 'r""">>> set_random_seed(0L)\n\n>>> change_warning_output(sys.stdout)\n\n'
     456    doc_suffix = '\n>>> sig_on_count()\n0\n"""'
     457
    454458    n = 0
    455459    while True:
    456460        i = F.find('"""')
     
    464468        except SyntaxError:
    465469            doc = F[i:j+3]
    466470        if len(doc):
    467             doc = '""">>> set_random_seed(0L)\n\n' + '>>> change_warning_output(sys.stdout)\n\n' + doc[3:]
     471            doc = doc_prefix + doc[3:-3] + doc_suffix
    468472            if random_order:
    469473                n_str = pad_zeros(new_index(n),10)
    470474            else:
    471475                n_str = str(n)
    472476            s += "def %s_%s():"%(name,n_str)
    473477            n += 1
    474             s += "\tr"+ doc + "\n\n"
     478            s += "\t"+ doc + "\n\n"
    475479        F = F[j+3:]
    476480
    477481    if n == 0:
     
    615619        s += "For whitespace errors, see the file %s"%tmpname
    616620    return (s, cnt)
    617621
     622
    618623def test_file(file, library_code):
    619624    if os.path.exists(file):
    620625        name = os.path.basename(file)
     
    653658            out = ''; err = ''
    654659            if verbose or gdb or memcheck or massif or cachegrind:
    655660                import subprocess
    656                 proc = subprocess.Popen(cmd,shell=True)
     661                proc = subprocess.Popen(cmd, shell=True)
    657662                while time.time()-tm <= TIMEOUT and proc.poll() == None:
    658663                    time.sleep(0.1)
    659664                if time.time()-tm >=TIMEOUT:
     
    663668            else:
    664669                outf = tempfile.NamedTemporaryFile()
    665670                import subprocess
    666                 proc = subprocess.Popen(cmd,shell=True, stdout=outf.file.fileno(), stderr = outf.file.fileno())
     671                proc = subprocess.Popen(cmd, shell=True, \
     672                        stdout=outf.file.fileno(), stderr = outf.file.fileno())
    667673                while time.time()-tm <= TIMEOUT and proc.poll() == None:
    668674                    time.sleep(0.1)
    669675                if time.time()-tm >=TIMEOUT:
     
    675681        except KeyboardInterrupt:
    676682            print "KeyboardInterrupt -- interrupted after %.1f seconds!" % (time.time()-tm)
    677683            sys.exit(2)
    678         if not verbose and 'raise KeyboardInterrupt' in err:
     684        if 'raise KeyboardInterrupt' in err:
    679685            print "*"*80 + "Control-C pressed -- interrupting doctests." + "*"*80
    680686            sys.exit(2)
    681687
     
    699705                s = "*"*70 + "\n" + "Error: TAB character found.\n" + s
    700706        if e == 255:
    701707            # The doctesting code raised an exception
    702             if not verbose:
    703                 print "Exception raised by doctesting framework. Use -verbose for details."
     708            print "Exception raised by doctesting framework. Use -verbose for details."
    704709            sys.exit(8)
    705710
    706711        if numfail == 0 and e > 0:
     
    710715                print s
    711716            sys.exit(128)
    712717        elif e < 0:
    713             if not verbose:
    714                 print "The doctested process was killed by signal %s" % (-e)
     718            print "The doctested process was killed by signal %s" % (-e)
    715719            sys.exit(4)
    716720        else:
    717721            delete_tmpfiles()