Added some tests for --docstring-encoding option. Added option to specify encoding for internal testdir._makefile() for the tests.

This commit is contained in:
Manuel Krebber 2016-11-29 12:18:41 +01:00
parent ed977513ec
commit d254c6b0ae
2 changed files with 48 additions and 2 deletions

View File

@ -471,7 +471,7 @@ class Testdir:
if not hasattr(self, '_olddir'):
self._olddir = old
def _makefile(self, ext, args, kwargs):
def _makefile(self, ext, args, kwargs, encoding="utf-8"):
items = list(kwargs.items())
if args:
source = py.builtin._totext("\n").join(
@ -490,7 +490,7 @@ class Testdir:
source_unicode = "\n".join([my_totext(line) for line in source.lines])
source = py.builtin._totext(source_unicode)
content = source.strip().encode("utf-8") # + "\n"
content = source.strip().encode(encoding) # + "\n"
#content = content.rstrip() + "\n"
p.write(content, "wb")
if ret is None:

View File

@ -129,6 +129,52 @@ class TestDoctests:
'*1 passed*',
])
def test_encoding_ascii(self, testdir):
"""Test support for --doctest-encoding option.
"""
testdir._makefile(".txt", ["""
>>> 1
1
"""], {}, encoding='ascii')
result = testdir.runpytest("--doctest-encoding=ascii")
result.stdout.fnmatch_lines([
'*1 passed*',
])
def test_encoding_latin1(self, testdir):
"""Test support for --doctest-encoding option.
"""
testdir._makefile(".txt", ["""
>>> 'üäö'
'üäö'
"""], {}, encoding='latin1')
result = testdir.runpytest("--doctest-encoding=latin1")
result.stdout.fnmatch_lines([
'*1 passed*',
])
def test_encoding_utf8(self, testdir):
"""Test support for --doctest-encoding option.
"""
testdir.maketxtfile("""
>>> 'üäö'
'üäö'
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines([
'*1 passed*',
])
result = testdir.runpytest("--doctest-encoding=utf-8")
result.stdout.fnmatch_lines([
'*1 passed*',
])
def test_doctest_unexpected_exception(self, testdir):
testdir.maketxtfile("""
>>> i = 0