Added some tests for --docstring-encoding option. Added option to specify encoding for internal testdir._makefile() for the tests.
This commit is contained in:
parent
ed977513ec
commit
d254c6b0ae
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue