Ticket #8708: trac_8708-doctest_quotes.patch

File trac_8708-doctest_quotes.patch, 2.1 KB (added by Burcin Erocal, 11 years ago)
  • sage-doctest

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1313052074 -7200
    # Node ID ddfd9eb432e2cdd9f178462a7031b0314b420011
    # Parent  14dc82c9b207e74663d45df424fb2746889c6843
    trac 8708: Make the doctest script recognize triple single quotes.
    
    diff --git a/sage-doctest b/sage-doctest
    a b  
    452452            tmpfiles.append(os.path.join(SAGE_TESTDIR, name + '.pyc'))
    453453
    454454    # 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"""'
     455    doc_prefix_dq = 'r""">>> set_random_seed(0L)\n\n>>> change_warning_output(sys.stdout)\n\n'
     456    doc_prefix_sq = doc_prefix_dq.replace('"""',"'''")
     457    doc_suffix_dq = '\n>>> sig_on_count()\n0\n"""'
     458    doc_suffix_sq = doc_suffix_dq.replace('"""',"'''")
    457459
    458460    n = 0
    459461    while True:
    460         i = F.find('"""')
    461         if i == -1: break
    462         name = "example"       
    463         k = F[i+3:].find('"""')
     462        dq_ind = F.find('"""')
     463        sq_ind = F.find("'''")
     464        min_ind = min(dq_ind, sq_ind)
     465        if min_ind == -1:
     466            break
     467        i = min_ind
     468        if min_ind == dq_ind:
     469            single_quote = False
     470        else:
     471            single_quote = True
     472        name = "example"
     473        if single_quote:
     474            k = F[i+3:].find("'''")
     475        else:
     476            k = F[i+3:].find('"""')
    464477        if k == -1: break
    465478        j = i+3 + k
    466479        try:
     
    468481        except SyntaxError:
    469482            doc = F[i:j+3]
    470483        if len(doc):
    471             doc = doc_prefix + doc[3:-3] + doc_suffix
     484            if single_quote:
     485                doc = doc_prefix_sq + doc[3:-3] + doc_suffix_sq
     486            else:
     487                doc = doc_prefix_dq + doc[3:-3] + doc_suffix_dq
    472488            if random_order:
    473489                n_str = pad_zeros(new_index(n),10)
    474490            else:
     
    484500
    485501    # Allow for "sage:" instead of the traditional Python ">>>".
    486502    s = s.replace("sage:",">>>").replace('_sage"','')
    487    
     503
    488504    return s
    489505
    490506def pythonify_tex(F):