Vega strike Python Modules doc
0.5.1
Documentation of the " Modules " folder of Vega strike
|
Public Member Functions | |
def | __init__ |
def | runstring |
def | rundoc |
def | rundict |
def | run__test__ |
def | summarize |
def | merge |
Data Fields | |
globs | |
verbose | |
isprivate | |
name2ft | |
compileflags | |
Class Tester -- runs docstring examples and accumulates stats. In normal use, function doctest.testmod() hides all this from you, so use that if you can. Create your own instances of Tester to do fancier things. Methods: runstring(s, name) Search string s for examples to run; use name for logging. Return (#failures, #tries). rundoc(object, name=None) Search object.__doc__ for examples to run; use name (or object.__name__) for logging. Return (#failures, #tries). rundict(d, name, module=None) Search for examples in docstrings in all of d.values(); use name for logging. Exclude functions and classes not defined in module if specified. Return (#failures, #tries). run__test__(d, name) Treat dict d like module.__test__. Return (#failures, #tries). summarize(verbose=None) Display summary of testing results, to stdout. Return (#failures, #tries). merge(other) Merge in the test results from Tester instance "other". >>> from doctest import Tester >>> t = Tester(globs={'x': 42}, verbose=0) >>> t.runstring(r''' ... >>> x = x * 2 ... >>> print x ... 42 ... ''', 'XYZ') ***************************************************************** Failure in example: print x from line #2 of XYZ Expected: 42 Got: 84 (1, 2) >>> t.runstring(">>> x = x * 2\\n>>> print x\\n84\\n", 'example2') (0, 2) >>> t.summarize() ***************************************************************** 1 items had failures: 1 of 2 in XYZ ***Test Failed*** 1 failures. (1, 4) >>> t.summarize(verbose=1) 1 items passed all tests: 2 tests in example2 ***************************************************************** 1 items had failures: 1 of 2 in XYZ 4 tests in 2 items. 3 passed and 1 failed. ***Test Failed*** 1 failures. (1, 4) >>>
Definition at line 570 of file doctest.py.
def __init__ | ( | self, | |
mod = None , |
|||
globs = None , |
|||
verbose = None , |
|||
isprivate = None |
|||
) |
mod=None, globs=None, verbose=None, isprivate=None See doctest.__doc__ for an overview. Optional keyword arg "mod" is a module, whose globals are used for executing examples. If not specified, globs must be specified. Optional keyword arg "globs" gives a dict to be used as the globals when executing examples; if not specified, use the globals from module mod. In either case, a copy of the dict is used for each docstring examined. Optional keyword arg "verbose" prints lots of stuff if true, only failures if false; by default, it's true iff "-v" is in sys.argv. Optional keyword arg "isprivate" specifies a function used to determine whether a name is private. The default function is doctest.is_private; see its docs for details.
Definition at line 636 of file doctest.py.
def merge | ( | self, | |
other | |||
) |
other -> merge in test results from the other Tester instance. If self and other both have a test result for something with the same name, the (#failures, #tests) results are summed, and a warning is printed to stdout. >>> from doctest import Tester >>> t1 = Tester(globs={}, verbose=0) >>> t1.runstring(''' ... >>> x = 12 ... >>> print x ... 12 ... ''', "t1example") (0, 2) >>> >>> t2 = Tester(globs={}, verbose=0) >>> t2.runstring(''' ... >>> x = 13 ... >>> print x ... 13 ... ''', "t2example") (0, 2) >>> common = ">>> assert 1 + 2 == 3\\n" >>> t1.runstring(common, "common") (0, 1) >>> t2.runstring(common, "common") (0, 1) >>> t1.merge(t2) *** Tester.merge: 'common' in both testers; summing outcomes. >>> t1.summarize(1) 3 items passed all tests: 2 tests in common 2 tests in t1example 2 tests in t2example 6 tests in 3 items. 6 passed and 0 failed. Test passed. (0, 6) >>>
Definition at line 969 of file doctest.py.
References Tester.isprivate, Tester.name2ft, and Tester.rundoc().
def run__test__ | ( | self, | |
d, | |||
name | |||
) |
d, name -> Treat dict d like module.__test__. Return (#failures, #tries). See testmod.__doc__ for details.
Definition at line 883 of file doctest.py.
References Tester.isprivate, Tester.rundoc(), and Tester.runstring().
def rundict | ( | self, | |
d, | |||
name, | |||
module = None |
|||
) |
d, name, module=None -> search for docstring examples in d.values(). For k, v in d.items() such that v is a function or class, do self.rundoc(v, name + "." + k). Whether this includes objects with private names depends on the constructor's "isprivate" argument. If module is specified, functions and classes that are not defined in module are excluded. Return aggregate (#failures, #examples). Build and populate two modules with sample functions to test that exclusion of external functions and classes works. >>> import new >>> m1 = new.module('_m1') >>> m2 = new.module('_m2') >>> test_data = \
Definition at line 804 of file doctest.py.
References Tester.__runone().
def rundoc | ( | self, | |
object, | |||
name = None |
|||
) |
object, name=None -> search object.__doc__ for examples to run. Use optional string name as the key for logging the outcome; by default use object.__name__. Return (#failures, #examples). If object is a class object, search recursively for method docstrings too. object.__doc__ is examined regardless of name, but if object is a class, whether private names reached from object are searched depends on the constructor's "isprivate" argument. >>> t = Tester(globs={}, verbose=0) >>> def _f(): ... '''Trivial docstring example. ... >>> assert 2 == 2 ... ''' ... return 32 ... >>> t.rundoc(_f) # expect 0 failures in 1 example (0, 1)
Definition at line 719 of file doctest.py.
References Tester.__record_outcome(), Tester.compileflags, Tester.globs, Tester.isprivate, Tester.run__test__(), doctest.run_docstring_examples(), locale.str(), and Tester.verbose.
def runstring | ( | self, | |
s, | |||
name | |||
) |
s, name -> search string s for examples to run, logging as name. Use string name as the key for logging the outcome. Return (#failures, #examples). >>> t = Tester(globs={}, verbose=1) >>> test = r''' ... # just an example ... >>> x = 1 + 2 ... >>> x ... 3 ... ''' >>> t.runstring(test, "Example") Running string Example Trying: x = 1 + 2 Expecting: nothing ok Trying: x Expecting: 3 ok 0 of 2 examples failed in string Example (0, 2)
Definition at line 681 of file doctest.py.
References Tester.__record_outcome(), Tester.compileflags, Tester.globs, and Tester.verbose.
def summarize | ( | self, | |
verbose = None |
|||
) |
verbose=None -> summarize results, return (#failures, #tests). Print summary of test results to stdout. Optional arg 'verbose' controls how wordy this is. By default, use the verbose setting established by the constructor.
Definition at line 916 of file doctest.py.
References Tester.name2ft, and Tester.verbose.
compileflags |
Definition at line 679 of file doctest.py.
globs |
Definition at line 666 of file doctest.py.
isprivate |
Definition at line 675 of file doctest.py.
name2ft |
Definition at line 677 of file doctest.py.
verbose |
Definition at line 671 of file doctest.py.