[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,18 +62,20 @@ class ReSTSyntaxTest(py.test.Item): | ||||||
| 
 | 
 | ||||||
| class DoctestText(py.test.Item):  | class DoctestText(py.test.Item):  | ||||||
|     def run(self):  |     def run(self):  | ||||||
|         s = self.fspath.read() |         # XXX quite nasty... but it works (fixes win32 issues) | ||||||
|  |         s = self._normalize_linesep() | ||||||
|         l = [] |         l = [] | ||||||
|         prefix = '.. >>> ' |         prefix = '.. >>> ' | ||||||
|         mod = py.std.types.ModuleType(self.fspath.purebasename)  |         mod = py.std.types.ModuleType(self.fspath.purebasename)  | ||||||
|         for line in s.split('\n'):  |         for line in s.split('\n'): | ||||||
|             if line.startswith(prefix):  |             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 = "" |                 line = "" | ||||||
|             else:  |             else: | ||||||
|                 l.append(line) |                 l.append(line) | ||||||
|         docstring = "\n".join(l)  |         docstring = "\n".join(l) | ||||||
|         self.execute(mod, docstring)  |         self.execute(mod, docstring) | ||||||
| 
 | 
 | ||||||
|     def execute(self, mod, docstring):  |     def execute(self, mod, docstring):  | ||||||
|         mod.__doc__ = docstring  |         mod.__doc__ = docstring  | ||||||
|  | @ -81,6 +83,20 @@ class DoctestText(py.test.Item): | ||||||
|         if failed:  |         if failed:  | ||||||
|             py.test.fail("doctest %s: %s failed out of %s" %( |             py.test.fail("doctest %s: %s failed out of %s" %( | ||||||
|                          self.fspath, failed, tot)) |                          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):  | class LinkCheckerMaker(py.test.collect.Collector):  | ||||||
|     def run(self):  |     def run(self):  | ||||||
|  |  | ||||||
|  | @ -36,6 +36,21 @@ def test_doctest_basic(): | ||||||
|     l2 = session.getitemoutcomepairs(py.test.Item.Skipped) |     l2 = session.getitemoutcomepairs(py.test.Item.Skipped) | ||||||
|     assert len(l+l2) == 2 |     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(): | def test_js_ignore(): | ||||||
|     py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py')) |     py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py')) | ||||||
|     tmpdir.ensure('__init__.py') |     tmpdir.ensure('__init__.py') | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue