Commits

ianb  committed b4ef11b

moving over

  • Participants

Comments (0)

Files changed (8)

File docs/license.txt

+Copyright (c) 2007 Ian Bicking and Contributors
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

File dtopt/COMPARE.py

+from dtopt import install_option
+import doctest
+install_option(doctest.COMPARISON_FLAGS,
+               __name__)

File dtopt/ELLIPSIS.py

+from dtopt import install_option
+install_option(__name__.split('.')[-1],
+               __name__)

File dtopt/NORMALIZE_WHITESPACE.py

+from dtopt import install_option
+install_option(__name__.split('.')[-1],
+               __name__)

File dtopt/__init__.py

+import doctest
+import sys
+
+def install_option(option, after_unload=None):
+    if isinstance(option, basestring):
+        if option not in doctest.OPTIONFLAGS_BY_NAME:
+            raise ValueError(
+                "Unknown option: %r" % option)
+        option = doctest.OPTIONFLAGS_BY_NAME[option]
+    frame = _find_doctest_frame()
+    test = frame.f_locals['test']
+    dt_self = frame.f_locals['self']
+    for example in test.examples:
+        example.options.setdefault(option, 1)
+    if after_unload:
+        _add_after_unload(dt_self, after_unload)
+
+def _find_doctest_frame():
+    import sys
+    frame = sys._getframe(1)
+    while frame:
+        l = frame.f_locals
+        if 'BOOM' in l:
+            # Sign of doctest
+            return frame
+        frame = frame.f_back
+    raise LookupError(
+        "Could not find doctest (only use this function *inside* a doctest)")
+    
+def _add_after_unload(dt_self, after_unload):
+    def finish():
+        _del_module(after_unload)
+    _add_doctest_finish(dt_self, finish)
+
+def _del_module(name):
+    import sys
+    del sys.modules[name]
+    if '.' not in name:
+        return
+    package, module = name.rsplit('.', 1)
+    package_mod = sys.modules[package]
+    delattr(package_mod, module)
+
+class _add_doctest_finish(object):
+    def __init__(self, dt_self, finish_func):
+        self.dt_self = dt_self
+        self.prev_func = dt_self._DocTestRunner__record_outcome
+        dt_self._DocTestRunner__record_outcome = self
+        self.finish_func = finish_func
+    def __call__(self, *args, **kw):
+        self.finish_func()
+        self.dt_self._DocTestRunner__record_outcome = self.prev_func
+        return self.prev_func(*args, **kw)        

File dtopt/tests.py

+__test__ = {
+    'test this': """
+Ellisis in particular are tested here.  First, an
+error:
+
+    >>> o = object()
+    >>> o # Expect a doctest error here!
+    ...   # really, it's okay
+    <object object at ...>
+
+See, you got an error!  Next:
+
+    >>> from dtopt import ELLIPSIS
+    >>> o
+    <object object at ...>
+""",
+    }
+
+if __name__ == '__main__':
+    import doctest
+    doctest.testmod()
+    print 'Expect *one* error.  Zero is bad, two is bad.'
+    print 'One error is good'
+    
+[egg_info]
+tag_build = dev
+tag_svn_revision = true
+from setuptools import setup, find_packages
+import sys, os
+
+version = '0.1'
+
+setup(name='dtopt',
+      version=version,
+      description="Add options to doctest examples while they are running",
+      long_description="""\
+""",
+      classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      keywords='doctest',
+      author='Ian Bicking',
+      author_email='ianb@colorstudy.com',
+      url='',
+      license='MIT',
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+          # -*- Extra requirements: -*-
+      ],
+      entry_points="""
+      # -*- Entry points: -*-
+      """,
+      )