[svn r37330] Replacing any non-Unix newlines with plain \n in

doctests, this fixes some win32 problem.

--HG--
branch : trunk
This commit is contained in:
guido 2007-01-25 15:08:48 +01:00
parent 4feb8d6c01
commit bedeb1e640
2 changed files with 38 additions and 7 deletions

View File

@ -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):

View File

@ -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')