Home | History | Annotate | Download | only in tests
      1 import doctest
      2 from paste.util.import_string import simple_import
      3 import os
      4 
      5 filenames = [
      6     'tests/test_template.txt',
      7     ]
      8 
      9 modules = [
     10     'paste.util.template',
     11     'paste.util.looper',
     12     # This one opens up httpserver, which is bad:
     13     #'paste.auth.cookie',
     14     #'paste.auth.multi',
     15     #'paste.auth.digest',
     16     #'paste.auth.basic',
     17     #'paste.auth.form',
     18     #'paste.progress',
     19     'paste.exceptions.serial_number_generator',
     20     'paste.evalexception.evalcontext',
     21     'paste.util.dateinterval',
     22     'paste.util.quoting',
     23     'paste.wsgilib',
     24     'paste.url',
     25     'paste.request',
     26     ]
     27 
     28 options = doctest.ELLIPSIS|doctest.REPORT_ONLY_FIRST_FAILURE
     29 
     30 def test_doctests():
     31     for filename in filenames:
     32         filename = os.path.join(
     33             os.path.dirname(os.path.dirname(__file__)),
     34             filename)
     35         yield do_doctest, filename
     36 
     37 def do_doctest(filename):
     38     failure, total = doctest.testfile(
     39         filename, module_relative=False,
     40         optionflags=options)
     41     assert not failure, "Failure in %r" % filename
     42 
     43 def test_doctest_mods():
     44     for module in modules:
     45         yield do_doctest_mod, module
     46 
     47 def do_doctest_mod(module):
     48     module = simple_import(module)
     49     failure, total = doctest.testmod(
     50         module, optionflags=options)
     51     assert not failure, "Failure in %r" % module
     52 
     53 if __name__ == '__main__':
     54     import sys
     55     import doctest
     56     args = sys.argv[1:]
     57     if not args:
     58         args = filenames
     59     for filename in args:
     60         doctest.testfile(filename, module_relative=False)
     61