[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:
parent
4feb8d6c01
commit
bedeb1e640
|
@ -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 = []
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue