| 175 | def test_eol_support(self): |
| 176 | """Test that the ExceptionReporter supports Unix, Windows and Macintosh EOL markers""" |
| 177 | FILE_CONTENT = 'print 1\nprint 2\nprint 3\nprint 4\nprint 5\n' |
| 178 | unix_fd, unix_filename = tempfile.mkstemp(text = False) |
| 179 | windows_fd, windows_filename = tempfile.mkstemp(text = False) |
| 180 | macintosh_fd, macintosh_filename = tempfile.mkstemp(text = False) |
| 181 | os.write(unix_fd, FILE_CONTENT) |
| 182 | os.write(windows_fd, FILE_CONTENT.replace('\n', '\r\n')) |
| 183 | os.write(macintosh_fd, FILE_CONTENT.replace('\n', '\r')) |
| 184 | os.close(unix_fd) |
| 185 | os.close(windows_fd) |
| 186 | os.close(macintosh_fd) |
| 187 | |
| 188 | reporter = ExceptionReporter(None, None, None, None) |
| 189 | try: |
| 190 | self.assertEqual(reporter._get_lines_from_file(unix_filename, 3, 2), (1, [u'print 2', u'print 3'], u'print 4', [u'print 5'])) |
| 191 | self.assertEqual(reporter._get_lines_from_file(windows_filename, 3, 2), (1, [u'print 2', u'print 3'], u'print 4', [u'print 5'])) |
| 192 | self.assertEqual(reporter._get_lines_from_file(macintosh_filename, 3, 2), (1, [u'print 2', u'print 3'], u'print 4', [u'print 5'])) |
| 193 | finally: |
| 194 | os.unlink(unix_filename) |
| 195 | os.unlink(windows_filename) |
| 196 | os.unlink(macintosh_filename) |