Ticket #7493: trac_7493-check-long-time.patch

File trac_7493-check-long-time.patch, 2.8 KB (added by nthiery, 10 years ago)
  • sage-doctest

    # HG changeset patch
    # User Nicolas M. Thiery <nthiery@users.sf.net>
    # Date 1264194631 -3600
    # Node ID 469f627b90aba26779c452b2a4e70a5e3b1d7be7
    # Parent  69a821823386fd7b649ec674186957102bffac55
    le patch trac_7493-check-long-time.patch a été importé
    
    diff --git a/sage-doctest b/sage-doctest
    a b def test_code(filename): 
    156156             'FILENAME'        : repr(filename),
    157157             'OUTPUT_FILENAME' : repr(filename + '.timeit.sobj'),
    158158             'TIMEIT'          : do_timeit, # global
     159             'CHECK_LONG_TIME' : check_long_time, # global
    159160             'VERBOSE'         : verbose }
    160161    return """
    161162if __name__ ==  '__main__':
    162163    verbose = %(VERBOSE)s
    163164    do_timeit = %(TIMEIT)s
     165    check_long_time = %(CHECK_LONG_TIME)s
    164166    output_filename = %(OUTPUT_FILENAME)s
    165167
    166168    import sys
    if __name__ == '__main__': 
    174176    # configure special sage doc test runner
    175177    runner = sagedoctest.SageDocTestRunner(checker=None, verbose=verbose, optionflags=0)
    176178    runner._collect_timeit_stats = do_timeit
     179    runner._check_long_time = check_long_time
    177180    runner._reset_random_seed = True
    178181
    179182    runner = sagedoctest.testmod_returning_runner(m,
    if __name__ == '__main__': 
    741744        long_time  = has_opt('long')
    742745        verbose    = has_opt('verbose')
    743746        do_timeit  = has_opt('timeit')
     747        check_long_time = has_opt('time')
    744748        gdb        = has_opt('gdb')
    745749        memcheck   = has_opt('memcheck') or has_opt('valgrind')
    746750        massif     = has_opt('massif')
  • sagedoctest.py

    diff --git a/sagedoctest.py b/sagedoctest.py
    a b class SageDocTestRunner(OrigDocTestRunne 
    1313        self._timeit_stats = {}
    1414        self._reset_random_seed = True
    1515        self._random_seed = randstate.seed(0)
     16        self._check_long_time = True
    1617
    1718    def run(self, test, compileflags=None, out=None, clear_globs=True):
    1819        r = OrigDocTestRunner.run(self, test, compileflags=compileflags, out=out, clear_globs=clear_globs)
    class SageDocTestRunner(OrigDocTestRunne 
    3536                except Exception, e:
    3637                    self._timeit_stats[key] = e
    3738        # otherwise, just run the example
     39        if self._check_long_time:
     40            import time
     41            tm = time.clock()
    3842        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
     43        if self._check_long_time:
     44            tm = time.clock() - tm
     45            if tm > 30:
     46                print "Warning: test took %ss > 30s. This is too long!"%tm
     47            elif tm > 1:
     48                print "Warning: test took %ss > 1s. Please use # long time"%tm
    3949
    4050    def save_timeit_stats_to_file_named(self, output_filename):
    4151        if self._collect_timeit_stats: