Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Sep 8, 2021
1 parent f0e014f commit 7e7859d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ Thus, a test that fails in ``doctest`` based on a "got"/"want" check, may pass
in ``xdoctest``. For this reason it is recommended that you rely on coded
``assert``-statements for system-critical code. This also makes it much easier
to transform your ``xdoctest`` into a ``unittest`` when you realize your
doctests start getting too long.
doctests are getting too long.



Expand Down
17 changes: 17 additions & 0 deletions dev/_compare/demo_enhancements.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,20 @@ def multiple_eval_for_loops_v2():
0
1
"""


def compact_style_code():
"""
This compact style is a bit ugly, but it should still be valid python
Exception:
>>> try: raise Exception # doctest: +ELLIPSIS
... except Exception: raise
Traceback (most recent call last):
...
Exception
...
"""
try: raise Exception # NOQA
except Exception: pass # NOQA
58 changes: 58 additions & 0 deletions dev/_compare/demo_issue_106.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
https://github.com/Erotemic/xdoctest/issues/106
python -m xdoctest demo_issue_106.py
python -m doctest demo_issue_106.py
"""
import sys


def logTraceback(logFunction):
r""" Logs the exception traceback to the specified log function.
>>> try: raise Exception() # doctest: +ELLIPSIS
... except Exception: logTraceback(lambda *a, **b: sys.stdout.write(a[0] + "\n", *a[1:], **b))
Traceback (most recent call last):
...
Exception
...
"""
sys.exc_info()
import xdev
xdev.embed()
logFunction
pass


# def compact_style_code():
# """
# This compact style is a bit ugly, but it should still be valid python

# Exception:
# >>> try: raise Exception # doctest: +ELLIPSIS
# ... except Exception: raise
# Traceback (most recent call last):
# ...
# Exception
# ...

# """
# try: raise Exception # NOQA
# except Exception: pass # NOQA


def logTraceback2(logFunction):
r""" Logs the exception traceback to the specified log function.
>>> try:
... raise Exception()
... except Exception:
... logTraceback(lambda *a, **b: sys.stdout.write(a[0] + "\n", *a[1:], **b))
Traceback (most recent call last):
...
Exception
...
"""
import sys
logFunction(*sys.exec_info)
logFunction()
pass

0 comments on commit 7e7859d

Please sign in to comment.