[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,13 +62,15 @@ 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__
exec py.code.Source(line[len(prefix):]).compile() in \
mod.__dict__
line = ""
else:
l.append(line)
@ -82,6 +84,20 @@ class DoctestText(py.test.Item):
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):
l = []

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