Skip to content

Commit

Permalink
Rename EXCEPTION_2TO3 into IGNORE_EXCEPTION_MODULE_IN_PYTHON2
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed Sep 30, 2016
1 parent 2690ae7 commit 197cf79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/zope/testing/renormalizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import doctest


EXCEPTION_2TO3 = doctest.register_optionflag('EXCEPTION_2TO3')
EXCEPTION_2TO3_HINT = """\
IGNORE_EXCEPTION_MODULE_IN_PYTHON2 = doctest.register_optionflag(
'IGNORE_EXCEPTION_MODULE_IN_PYTHON2')
IGNORE_EXCEPTION_MODULE_IN_PYTHON2_HINT = """\
===============================================================
HINT:
You seem to test traceback output.
The optionflag EXCEPTION_2TO3 is set.
The optionflag IGNORE_EXCEPTION_MODULE_IN_PYTHON2 is set.
Do you use the full dotted name for the exception class name?
==============================================================="""

Expand Down Expand Up @@ -54,7 +55,7 @@ def check_output(self, want, got, optionflags):
got = transformer(got)

if sys.version_info[0] < 3:
if optionflags & EXCEPTION_2TO3:
if optionflags & IGNORE_EXCEPTION_MODULE_IN_PYTHON2:
want = strip_dottedname_from_traceback(want)

return doctest.OutputChecker.check_output(self, want, got, optionflags)
Expand Down Expand Up @@ -82,9 +83,9 @@ def output_difference(self, example, got, optionflags):
example.want = want

if sys.version_info[0] < 3:
if optionflags & EXCEPTION_2TO3:
if optionflags & IGNORE_EXCEPTION_MODULE_IN_PYTHON2:
if maybe_a_traceback(got) is not None:
got += EXCEPTION_2TO3_HINT
got += IGNORE_EXCEPTION_MODULE_IN_PYTHON2_HINT

result = doctest.OutputChecker.output_difference(
self, example, got, optionflags)
Expand Down
13 changes: 8 additions & 5 deletions src/zope/testing/renormalizing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,17 @@ Combining a checker with something else does not work:

Using the 2to3 exception normalization:

>>> from zope.testing.renormalizing import EXCEPTION_2TO3
>>> from zope.testing.renormalizing import (
... IGNORE_EXCEPTION_MODULE_IN_PYTHON2)
>>> checker = OutputChecker()
>>> want = """\
... Traceback (most recent call last):
... foo.bar.FooBarError: requires at least one argument."""
>>> got = """\
... Traceback (most recent call last):
... FooBarError: requires at least one argument."""
>>> result = checker.check_output(want, got, EXCEPTION_2TO3)
>>> result = checker.check_output(
... want, got, IGNORE_EXCEPTION_MODULE_IN_PYTHON2)
>>> import sys
>>> if sys.version_info[0] < 3:
... expected = True
Expand All @@ -264,11 +266,12 @@ to be helpful by explaining how to test for exceptions in the traceback output.
... Traceback (most recent call last):
... FooBarError: requires at least one argument.
... """
>>> checker.check_output(want, got, EXCEPTION_2TO3)
>>> checker.check_output(want, got, IGNORE_EXCEPTION_MODULE_IN_PYTHON2)
False
>>> from doctest import Example
>>> example = Example('dummy', want)
>>> result = checker.output_difference(example, got, EXCEPTION_2TO3)
>>> result = checker.output_difference(
... example, got, IGNORE_EXCEPTION_MODULE_IN_PYTHON2)
>>> output = """\
... Expected:
... Traceback (most recent call last):
Expand All @@ -281,7 +284,7 @@ to be helpful by explaining how to test for exceptions in the traceback output.
... ===============================================================
... HINT:
... You seem to test traceback output.
... The optionflag EXCEPTION_2TO3 is set.
... The optionflag IGNORE_EXCEPTION_MODULE_IN_PYTHON2 is set.
... Do you use the full dotted name for the exception class name?
... ==============================================================="""
>>> if sys.version_info[0] < 3:
Expand Down

0 comments on commit 197cf79

Please sign in to comment.