Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
doctest Namespace Reference

Data Structures

class  _SpoofOut
 
class  Tester
 
class  _TestClass
 

Functions

def run_docstring_examples
 
def is_private
 
def testmod
 

Variables

list __all__
 
string PS1 = ">>>"
 
string PS2 = "..."
 
tuple _isPS1 = re.compile(r"(\s*)" + re.escape(PS1))
 
tuple _isPS2 = re.compile(r"(\s*)" + re.escape(PS2))
 
tuple _isEmpty = re.compile(r"\s*$")
 
tuple _isComment = re.compile(r"\s*#")
 
 master = None
 
dictionary __test__
 

Function Documentation

def doctest.is_private (   prefix,
  base 
)
prefix, base -> true iff name prefix + "." + base is "private".

Prefix may be an empty string, and base does not contain a period.
Prefix is ignored (although functions you write conforming to this
protocol may make use of it).
Return true iff base begins with an (at least one) underscore, but
does not both begin and end with (at least) two underscores.

>>> is_private("a.b", "my_func")
0
>>> is_private("____", "_my_func")
1
>>> is_private("someclass", "__init__")
0
>>> is_private("sometypo", "__init_")
1
>>> is_private("x.y.z", "_")
1
>>> is_private("_x.y.z", "__")
0
>>> is_private("", "")  # senseless but consistent
0

Definition at line 534 of file doctest.py.

535 def is_private(prefix, base):
536  """prefix, base -> true iff name prefix + "." + base is "private".
537 
538  Prefix may be an empty string, and base does not contain a period.
539  Prefix is ignored (although functions you write conforming to this
540  protocol may make use of it).
541  Return true iff base begins with an (at least one) underscore, but
542  does not both begin and end with (at least) two underscores.
543 
544  >>> is_private("a.b", "my_func")
545  0
546  >>> is_private("____", "_my_func")
547  1
548  >>> is_private("someclass", "__init__")
549  0
550  >>> is_private("sometypo", "__init_")
551  1
552  >>> is_private("x.y.z", "_")
553  1
554  >>> is_private("_x.y.z", "__")
555  0
556  >>> is_private("", "") # senseless but consistent
557  0
558  """
559 
560  return base[:1] == "_" and not base[:2] == "__" == base[-2:]
561 
562 # Determine if a class of function was defined in the given module.
def doctest.run_docstring_examples (   f,
  globs,
  verbose = 0,
  name = "NoName",
  compileflags = None 
)
f, globs, verbose=0, name="NoName" -> run examples from f.__doc__.

Use (a shallow copy of) dict globs as the globals for execution.
Return (#failures, #tries).

If optional arg verbose is true, print stuff even if there are no
failures.
Use string name in failure msgs.

Definition at line 505 of file doctest.py.

References locale.str().

506  compileflags=None):
507  """f, globs, verbose=0, name="NoName" -> run examples from f.__doc__.
508 
509  Use (a shallow copy of) dict globs as the globals for execution.
510  Return (#failures, #tries).
511 
512  If optional arg verbose is true, print stuff even if there are no
513  failures.
514  Use string name in failure msgs.
515  """
516 
517  try:
518  doc = f.__doc__
519  if not doc:
520  # docstring empty or None
521  return 0, 0
522  # just in case CT invents a doc object that has to be forced
523  # to look like a string <0.9 wink>
524  doc = str(doc)
525  except:
526  return 0, 0
527 
528  e = _extract_examples(doc)
529  if not e:
530  return 0, 0
531  if compileflags is None:
532  compileflags = _extract_future_flags(globs)
533  return _run_examples(e, globs, verbose, name, compileflags)
def doctest.testmod (   m,
  name = None,
  globs = None,
  verbose = None,
  isprivate = None,
  report = 1 
)
m, name=None, globs=None, verbose=None, isprivate=None, report=1

Test examples in docstrings in functions and classes reachable from
module m, starting with m.__doc__.  Private names are skipped.

Also test examples reachable from dict m.__test__ if it exists and is
not None.  m.__dict__ maps names to functions, classes and strings;
function and class docstrings are tested even if the name is private;
strings are tested directly, as if they were docstrings.

Return (#failures, #tests).

See doctest.__doc__ for an overview.

Optional keyword arg "name" gives the name of the module; by default
use m.__name__.

Optional keyword arg "globs" gives a dict to be used as the globals
when executing examples; by default, use m.__dict__.  A copy of this
dict is actually used for each docstring, so that each docstring's
examples start with a clean slate.

Optional keyword arg "verbose" prints lots of stuff if true, prints
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.

Optional keyword arg "report" prints a summary at the end when true,
else prints nothing at the end.  In verbose mode, the summary is
detailed, else very brief (in fact, empty if all tests passed).

Advanced tomfoolery:  testmod runs methods of a local instance of
class doctest.Tester, then merges the results into (or creates)
global Tester instance doctest.master.  Methods of doctest.master
can be called directly too, if you want to do something unusual.
Passing report=0 to testmod is especially useful then, to delay
displaying a summary.  Invoke doctest.master.summarize(verbose)
when you're done fiddling.

Definition at line 1044 of file doctest.py.

1045  report=1):
1046  """m, name=None, globs=None, verbose=None, isprivate=None, report=1
1047 
1048  Test examples in docstrings in functions and classes reachable from
1049  module m, starting with m.__doc__. Private names are skipped.
1050 
1051  Also test examples reachable from dict m.__test__ if it exists and is
1052  not None. m.__dict__ maps names to functions, classes and strings;
1053  function and class docstrings are tested even if the name is private;
1054  strings are tested directly, as if they were docstrings.
1055 
1056  Return (#failures, #tests).
1057 
1058  See doctest.__doc__ for an overview.
1059 
1060  Optional keyword arg "name" gives the name of the module; by default
1061  use m.__name__.
1062 
1063  Optional keyword arg "globs" gives a dict to be used as the globals
1064  when executing examples; by default, use m.__dict__. A copy of this
1065  dict is actually used for each docstring, so that each docstring's
1066  examples start with a clean slate.
1067 
1068  Optional keyword arg "verbose" prints lots of stuff if true, prints
1069  only failures if false; by default, it's true iff "-v" is in sys.argv.
1070 
1071  Optional keyword arg "isprivate" specifies a function used to
1072  determine whether a name is private. The default function is
1073  doctest.is_private; see its docs for details.
1074 
1075  Optional keyword arg "report" prints a summary at the end when true,
1076  else prints nothing at the end. In verbose mode, the summary is
1077  detailed, else very brief (in fact, empty if all tests passed).
1078 
1079  Advanced tomfoolery: testmod runs methods of a local instance of
1080  class doctest.Tester, then merges the results into (or creates)
1081  global Tester instance doctest.master. Methods of doctest.master
1082  can be called directly too, if you want to do something unusual.
1083  Passing report=0 to testmod is especially useful then, to delay
1084  displaying a summary. Invoke doctest.master.summarize(verbose)
1085  when you're done fiddling.
1086  """
1087 
1088  global master
1089 
1090  if not _ismodule(m):
1091  raise TypeError("testmod: module required; " + `m`)
1092  if name is None:
1093  name = m.__name__
1094  tester = Tester(m, globs=globs, verbose=verbose, isprivate=isprivate)
1095  failures, tries = tester.rundoc(m, name)
1096  f, t = tester.rundict(m.__dict__, name, m)
1097  failures = failures + f
1098  tries = tries + t
1099  if hasattr(m, "__test__"):
1100  testdict = m.__test__
1101  if testdict:
1102  if not hasattr(testdict, "items"):
1103  raise TypeError("testmod: module.__test__ must support "
1104  ".items(); " + `testdict`)
1105  f, t = tester.run__test__(testdict, name + ".__test__")
1106  failures = failures + f
1107  tries = tries + t
1108  if report:
1109  tester.summarize()
1110  if master is None:
1111  master = tester
1112  else:
1113  master.merge(tester)
1114  return failures, tries

Variable Documentation

list __all__
Initial value:
1 = [
2  'testmod',
3  'run_docstring_examples',
4  'is_private',
5  'Tester',
6 ]

Definition at line 275 of file doctest.py.

dictionary __test__
Initial value:
1 = {"_TestClass": _TestClass,
2  "string": r""" Example of a string object, searched as-is. >>> x = 1; y = 2 >>> x + y, x * y (3, 2) """
3  }

Definition at line 1159 of file doctest.py.

tuple _isComment = re.compile(r"\s*#")

Definition at line 290 of file doctest.py.

tuple _isEmpty = re.compile(r"\s*$")

Definition at line 289 of file doctest.py.

tuple _isPS1 = re.compile(r"(\s*)" + re.escape(PS1))

Definition at line 287 of file doctest.py.

tuple _isPS2 = re.compile(r"(\s*)" + re.escape(PS2))

Definition at line 288 of file doctest.py.

master = None

Definition at line 1041 of file doctest.py.

string PS1 = ">>>"

Definition at line 285 of file doctest.py.

string PS2 = "..."

Definition at line 286 of file doctest.py.