/usr/share/pyshared/nose2/plugins/doctests.py is in python-nose2 0.4.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | """
Load tests from doctests.
This plugin implements :func:`handleFile` to load doctests from text files
and python modules.
To disable loading doctests from text files, configure an empty extensions list:
.. code-block :: ini
[doctest]
extensions =
"""
import doctest
import os
from nose2.events import Plugin
from nose2 import util
__unittest = True
class DocTestLoader(Plugin):
configSection = 'doctest'
commandLineSwitch = (None, 'with-doctest',
'Load doctests from text files and modules')
def __init__(self):
self.extensions = self.config.as_list('extensions', ['.txt', '.rst'])
def handleFile(self, event):
"""Load doctests from text files and modules"""
path = event.path
_root, ext = os.path.splitext(path)
if ext in self.extensions:
suite = doctest.DocFileTest(path, module_relative=False)
event.extraTests.append(suite)
return
elif not util.valid_module_name(os.path.basename(path)):
return
name = util.name_from_path(path)
try:
module = util.module_from_name(name)
except Exception:
# XXX log warning here?
return
if hasattr(module, '__test__') and not module.__test__:
return
try:
suite = doctest.DocTestSuite(module)
except ValueError:
# doctest, very annoyingly, raises ValueError when
# a module has no tests.
return
event.extraTests.append(suite)
|