summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/doctest.py7
-rw-r--r--Lib/test/test_doctest.py20
-rw-r--r--Modules/zlibmodule.c5
3 files changed, 26 insertions, 6 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 97bc053..eee2f51 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -209,8 +209,11 @@ def _load_testfile(filename, package, module_relative, encoding):
filename = _module_relative_path(package, filename)
if hasattr(package, '__loader__'):
if hasattr(package.__loader__, 'get_data'):
- return (package.__loader__.get_data(filename).decode(encoding),
- filename)
+ file_contents = package.__loader__.get_data(filename)
+ file_contents = file_contents.decode(encoding)
+ # get_data() opens files as 'rb', so one must do the equivalent
+ # conversion as universal newlines would do.
+ return file_contents.replace(os.linesep, '\n'), filename
return open(filename, encoding=encoding).read(), filename
def _indent(s, indent=4):
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index be2ffe2..3b89097 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -1912,6 +1912,24 @@ def test_DocFileSuite():
>>> suite.run(unittest.TestResult())
<unittest.TestResult run=3 errors=0 failures=2>
+ Support for using a package's __loader__.get_data() is also
+ provided.
+
+ >>> import unittest, pkgutil, test
+ >>> if not hasattr(test, '__loader__'):
+ ... test.__loader__ = pkgutil.get_loader(test)
+ ... added_loader = True
+ >>> try:
+ ... suite = doctest.DocFileSuite('test_doctest.txt',
+ ... 'test_doctest2.txt',
+ ... 'test_doctest4.txt',
+ ... package='test')
+ ... suite.run(unittest.TestResult())
+ ... finally:
+ ... if added_loader:
+ ... del test.__loader__
+ <unittest.TestResult run=3 errors=0 failures=2>
+
'/' should be used as a path separator. It will be converted
to a native separator at run time:
@@ -1973,8 +1991,6 @@ def test_DocFileSuite():
And, you can provide setUp and tearDown functions:
- You can supply setUp and teatDoen functions:
-
>>> def setUp(t):
... import test.test_doctest
... test.test_doctest.sillySetup = True
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index fd6c0b7..8f3202d 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -197,10 +197,11 @@ PyZlib_decompress(PyObject *self, PyObject *args)
PyObject *result_str;
Byte *input;
int length, err;
- int wsize=DEF_WBITS, r_strlen=DEFAULTALLOC;
+ int wsize=DEF_WBITS;
+ Py_ssize_t r_strlen=DEFAULTALLOC;
z_stream zst;
- if (!PyArg_ParseTuple(args, "s#|ii:decompress",
+ if (!PyArg_ParseTuple(args, "s#|in:decompress",
&input, &length, &wsize, &r_strlen))
return NULL;