Fix coverage
Also make sure a test that doesn't set ALLOW_UNICODE fails on Python 2 and passes Python 3.
This commit is contained in:
parent
93aee0f814
commit
d749021a31
|
@ -202,21 +202,26 @@ def _get_unicode_checker():
|
||||||
|
|
||||||
_literal_re = re.compile(r"(\W|^)[uU]([rR]?[\'\"])", re.UNICODE)
|
_literal_re = re.compile(r"(\W|^)[uU]([rR]?[\'\"])", re.UNICODE)
|
||||||
|
|
||||||
def _remove_u_prefixes(self, txt):
|
|
||||||
return re.sub(self._literal_re, r'\1\2', txt)
|
|
||||||
|
|
||||||
def check_output(self, want, got, optionflags):
|
def check_output(self, want, got, optionflags):
|
||||||
res = doctest.OutputChecker.check_output(self, want, got, optionflags)
|
res = doctest.OutputChecker.check_output(self, want, got,
|
||||||
|
optionflags)
|
||||||
if res:
|
if res:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not (optionflags & _get_allow_unicode_flag()):
|
if not (optionflags & _get_allow_unicode_flag()):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
cleaned_want = self._remove_u_prefixes(want)
|
else: # pragma: no cover
|
||||||
cleaned_got = self._remove_u_prefixes(got)
|
# the code below will end up executed only in Python 2 in
|
||||||
res = doctest.OutputChecker.check_output(self, cleaned_want, cleaned_got, optionflags)
|
# our tests, and our coverage check runs in Python 3 only
|
||||||
return res
|
def remove_u_prefixes(txt):
|
||||||
|
return re.sub(self._literal_re, r'\1\2', txt)
|
||||||
|
|
||||||
|
want = remove_u_prefixes(want)
|
||||||
|
got = remove_u_prefixes(got)
|
||||||
|
res = doctest.OutputChecker.check_output(self, want, got,
|
||||||
|
optionflags)
|
||||||
|
return res
|
||||||
|
|
||||||
_get_unicode_checker.UnicodeOutputChecker = UnicodeOutputChecker
|
_get_unicode_checker.UnicodeOutputChecker = UnicodeOutputChecker
|
||||||
return _get_unicode_checker.UnicodeOutputChecker()
|
return _get_unicode_checker.UnicodeOutputChecker()
|
||||||
|
|
|
@ -432,16 +432,17 @@ class TestDoctests:
|
||||||
reprec = testdir.inline_run("--doctest-modules")
|
reprec = testdir.inline_run("--doctest-modules")
|
||||||
reprec.assertoutcome(passed=2)
|
reprec.assertoutcome(passed=2)
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info[0] >= 3, reason='Python 2 only')
|
def test_unicode_string(self, testdir):
|
||||||
def test_unicode_string_fails(self, testdir):
|
|
||||||
"""Test that doctests which output unicode fail in Python 2 when
|
"""Test that doctests which output unicode fail in Python 2 when
|
||||||
the ALLOW_UNICODE option is not used.
|
the ALLOW_UNICODE option is not used. The same test should pass
|
||||||
|
in Python 3.
|
||||||
"""
|
"""
|
||||||
testdir.maketxtfile(test_doc="""
|
testdir.maketxtfile(test_doc="""
|
||||||
>>> b'12'.decode('ascii') {comment}
|
>>> b'12'.decode('ascii')
|
||||||
'12'
|
'12'
|
||||||
""")
|
""")
|
||||||
reprec = testdir.inline_run()
|
reprec = testdir.inline_run()
|
||||||
reprec.assertoutcome(failed=1)
|
passed = int(sys.version_info[0] >= 3)
|
||||||
|
reprec.assertoutcome(passed=passed, failed=int(not passed))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue