Ticket #715: failing_test_under_gdb.py

File failing_test_under_gdb.py, 3.6 KB (added by SimonKing, 7 years ago)

Temporary file created by sage -t on a test that fails with gdb

Line 
1# -*- coding: utf-8 -*-
2
3# This file was generated by 'sage-doctest' from
4# '/scratch/sking/sage-5.4.beta0/devel/sage-main/sage/misc/my_test.py'.
5
6from sage.all_cmdline import *; 
7import sage.plot.plot; sage.plot.plot.DOCTEST_MODE=True
8
9def warning_function(f):
10    import warnings
11
12    def doctest_showwarning(message, category, filename, lineno, file=f, line=None):
13        try:
14            file.write(warnings.formatwarning(message, category, 'doctest', lineno, line))
15        except IOError:
16            pass # the file (probably stdout) is invalid
17    return doctest_showwarning
18
19def change_warning_output(file):
20    import warnings
21    warnings.showwarning = warning_function(file)
22
23import re
24float_pattern = re.compile('[+-]?((\d*\.?\d+)|(\d+\.?))([eE][+-]?\d+)?')
25
26def check_with_tolerance(expected, actual, epsilon, rel_or_abs=None):
27    if actual is Exception:
28        return # error computing actual
29    else:
30        actual = str(actual)
31    expected = re.sub('\n +', '\n', expected)
32    actual = re.sub('\n +', '\n', actual)
33    assert float_pattern.sub('#', expected.strip()) == float_pattern.sub('#', actual.strip()), \
34        "Expected '" + expected + "' got '" + actual + "'"
35    for expected_value, actual_value in zip(float_pattern.finditer(expected), float_pattern.finditer(actual)):
36        expected_value = float(expected_value.group())
37        actual_value = float(actual_value.group())
38        if rel_or_abs == 'abs' or expected_value == 0:
39            assert abs(expected_value - actual_value) < epsilon, "Out of tolerance %s vs %s" % (expected_value, actual_value)
40        else:
41            assert abs((expected_value - actual_value) / expected_value) < epsilon, "Out of tolerance %s vs %s" % (expected_value, actual_value)
42def example_0():        r""">>> set_random_seed(0L)
43
44>>> change_warning_output(sys.stdout)
45
46
47        EXAMPLES::
48
49            >>> @cached_function###line 6:_sage_    >>> @cached_function
50            ... def oddprime_factors(n):
51            ...     l = [p for p,e in factor(n) if p != Integer(2)]
52            ...     return len(l)
53            >>> oddprime_factors.precompute(range(Integer(1),Integer(100)), Integer(4))###line 10:_sage_    >>> oddprime_factors.precompute(range(1,100), 4)
54            >>> oddprime_factors.cache[(Integer(25),),()]###line 11:_sage_    >>> oddprime_factors.cache[(25,),()]
55            1
56       
57>>> sig_on_count()
580
59"""
60
61
62if __name__ ==  '__main__':
63    verbose = False
64    do_timeit = False
65    output_filename = '/scratch/sking/sage-5.4.beta0/devel/sage-main/sage/misc/my_test.py.timeit.sobj'
66
67    import sys
68    sys.path = sys.path + ['/scratch/sking/sage-5.4.beta0/local/bin']
69    import sagedoctest
70
71    # execfile('/scratch/sking/sage-5.4.beta0/devel/sage-main/sage/misc/my_test.py')
72    m = sys.modules[__name__]
73    m.__file__ = '/scratch/sking/sage-5.4.beta0/devel/sage-main/sage/misc/my_test.py'
74
75    try:
76
77        # configure special sage doc test runner
78        runner = sagedoctest.SageDocTestRunner(checker=None, verbose=verbose, optionflags=0)
79        runner._collect_timeit_stats = do_timeit
80        runner._reset_random_seed = True
81
82        runner = sagedoctest.testmod_returning_runner(m,
83                       # filename='/scratch/sking/sage-5.4.beta0/devel/sage-main/sage/misc/my_test.py',
84                       verbose=verbose,
85                       globs=globals(),
86                       runner=runner)
87        runner.save_timeit_stats_to_file_named(output_filename)
88    except:
89        quit_sage(verbose=False)
90        import traceback
91        traceback.print_exc(file=sys.stdout)
92        sys.exit(255)
93    quit_sage(verbose=False)
94    if runner.failures > 254:
95        sys.exit(254)
96    sys.exit(runner.failures)