Ticket #10952: trac_10952-ref.patch

File trac_10952-ref.patch, 2.1 KB (added by jhpalmieri, 9 years ago)

scripts repo; apply on top of other scripts patch

  • sage-doctest

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1315605479 25200
    # Node ID 036a515b86cb02c80c7dc5cbde65ea0d5d3bf080
    # Parent  b8a5292b124243e87dbec5c2f42aade98612c92b
    #10952: make tolerance failures print more concisely
    and also include the line number.
    
    diff --git a/sage-doctest b/sage-doctest
    a b def doc_preparse(s): 
    279279    for L in s.splitlines():
    280280        if not L.strip():
    281281            if has_tolerance:
    282                 t.append(close_tolerance(c))
     282                t.append(close_tolerance(c) + old_cmd)
    283283                has_tolerance = False
    284284       
    285285        begin = L.lstrip()[:5]
    286286        comment = ''
    287287        if begin == 'sage:':
    288288            if has_tolerance:
    289                 t.append(close_tolerance(c))
     289                # old_cmd contains the command being tested along with
     290                # the line number.
     291                t.append(close_tolerance(c) + old_cmd)
    290292            c, comment = comment_modifier(L)
    291293            last_prompt_comment = comment
    292294            line = ''
    def doc_preparse(s): 
    316318                # and an empty line, to ignore the output given in the test
    317319                line += '\n' + ' '*i + 'ignore ...\n'
    318320            if has_tolerance:
     321                # save the current command along with the line number
     322                try:
     323                    idx = line.index('###_sage"line')
     324                    old_cmd = line[idx:]
     325                except IndexError:
     326                    old_cmd = ''
    319327                line += "\n>>> check_with_tolerance('''"
    320328            t.append(line)
    321329           
    def post_process(s, file, tmpname): 
    667675        j = s[i:].find('###line')
    668676        s = s[:k] + ', ' + s[i+j+3:]
    669677        i = s.find("Failed example:")
     678        if i != -1:
     679            t = s[:i]
     680        else:
     681            t = s
     682        if t.find('check_with_tolerance') != -1:
     683            j = s.find('Exception raised')
     684            ass = 'AssertionError: '
     685            k = s.find(ass)
     686            s = s[:j] + s[k+len(ass):]
     687        i = s.find("Failed example:")
    670688        cnt += 1
    671689        if cnt > 1000:
    672690            break