Ticket #9224: doctest.py

File doctest.py, 2.5 KB (added by Mitesh Patel, 12 years ago)

Doctester class pseudo-interface. Not a patch.

Line 
1# Ticket #9224: Sage Doctester class pseudo-interface.  Separate code,
2# possibly in the same script, (arg/opt)parses command-line arguments,
3# instantiates a Doctester object, and calls it.
4
5class Doctester(object):
6    def __init__(self, paths=[], library_code=False, logfile=None,
7                 long=False, only_optional=[], optional=[], processes=1,
8                 randorder=False, repeat=1, sagenb=False, stats={},
9                 verbose=False):
10        # Optional list of paths to test.  Overridable in
11        # self.__call__.  Later generalize to functions and classes?
12        self._paths = paths
13        # Assume all files are Sage library files, regardless of
14        # location.  This seems a better name for force_lib, which we
15        # can deprecate.
16        self._library_code = library_code
17        # Save/append output to a file?
18        self._logfile = logfile
19        # Run the long tests, too?
20        self._long = long
21        # Run only selected optional tests?  'all' tests only all
22        # optional tests.
23        self._only_optional = only_optional
24        # Also run selected optional tests?  'all' adds them all.
25        self._optional = optional
26        # Number of parallel jobs.  'auto' uses
27        # multiprocessing.cpu_count(), possibly with a cap.
28        self._processes = processes
29        # Randomize order of tests in each file?  An int value turns
30        # on randomized testing with the given seed.
31        self._randorder = randorder
32        # Number of times to run the whole suite.
33        self._repeat = repeat
34        # Also test SageNB files?
35        self._sagenb = sagenb
36        # Update an existing stats object.  Use a dict for a simple
37        # initial implementation.
38        self._stats = stats
39        # Print debugging output?
40        self._verbose = verbose
41
42    def __repr__(self):
43        # Print this instance's settings.
44        raise NotImplementedError
45
46    def __call__(self, *paths):
47        # This does most of the work.  Search paths/self._paths for
48        # files to test and run their tests with self's settings.
49        # Print results as requested but also collect details for each
50        # file in self._stats (pass/fail status, messages, exit codes,
51        # number of runs, run times, version, etc.).
52        raise NotImplementedError
53
54    def stats(self):
55        # We could save/load stats externally or add save/load
56        # methods.
57        return self._stats
58
59    def reset_stats(self):
60        self._stats = {}
61
62
63def doctest(*paths, **options):
64    return Doctester(**options)(*paths)