From bedeb1e64031d9416ae560215d11adf65a361f6e Mon Sep 17 00:00:00 2001 From: guido Date: Thu, 25 Jan 2007 15:08:48 +0100 Subject: [PATCH] [svn r37330] Replacing any non-Unix newlines with plain \n in doctests, this fixes some win32 problem. --HG-- branch : trunk --- py/doc/conftest.py | 30 +++++++++++++++++++++++------- py/doc/test_conftest.py | 15 +++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/py/doc/conftest.py b/py/doc/conftest.py index 8e78bbc32..febdb0c6f 100644 --- a/py/doc/conftest.py +++ b/py/doc/conftest.py @@ -62,18 +62,20 @@ class ReSTSyntaxTest(py.test.Item): class DoctestText(py.test.Item): def run(self): - s = self.fspath.read() + # XXX quite nasty... but it works (fixes win32 issues) + s = self._normalize_linesep() l = [] prefix = '.. >>> ' mod = py.std.types.ModuleType(self.fspath.purebasename) - for line in s.split('\n'): - if line.startswith(prefix): - exec py.code.Source(line[len(prefix):]).compile() in mod.__dict__ + for line in s.split('\n'): + if line.startswith(prefix): + exec py.code.Source(line[len(prefix):]).compile() in \ + mod.__dict__ line = "" - else: + else: l.append(line) - docstring = "\n".join(l) - self.execute(mod, docstring) + docstring = "\n".join(l) + self.execute(mod, docstring) def execute(self, mod, docstring): mod.__doc__ = docstring @@ -81,6 +83,20 @@ class DoctestText(py.test.Item): if failed: py.test.fail("doctest %s: %s failed out of %s" %( self.fspath, failed, tot)) + + def _normalize_linesep(self): + s = self.fspath.read() + linesep = '\n' + if '\r' in s: + if '\n' not in s: + linesep = '\r' + else: + linesep = '\r\n' + print 'linesep:', repr(linesep) + s = s.replace(linesep, '\n') + self.fspath.write(s) + print 's:', repr(s) + return s class LinkCheckerMaker(py.test.collect.Collector): def run(self): diff --git a/py/doc/test_conftest.py b/py/doc/test_conftest.py index 4c71bde92..155c0c49e 100644 --- a/py/doc/test_conftest.py +++ b/py/doc/test_conftest.py @@ -36,6 +36,21 @@ def test_doctest_basic(): l2 = session.getitemoutcomepairs(py.test.Item.Skipped) assert len(l+l2) == 2 +def test_doctest_eol(): + # XXX get rid of the next line: + py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py')) + + ytxt = tmpdir.join('y.txt') + ytxt.write(py.code.Source(".. >>> 1 + 1\r\n 2\r\n\r\n")) + config = py.test.config._reparse([ytxt]) + session = config.initsession() + session.main() + l = session.getitemoutcomepairs(py.test.Item.Failed) + assert len(l) == 0 + l = session.getitemoutcomepairs(py.test.Item.Passed) + l2 = session.getitemoutcomepairs(py.test.Item.Skipped) + assert len(l+l2) == 2 + def test_js_ignore(): py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py')) tmpdir.ensure('__init__.py')