Code

Ticket #13958: unittest_13958.2.diff

File unittest_13958.2.diff, 1.9 KB (added by fredrik.kers@…, 3 years ago)
Line 
1Index: tests/regressiontests/views/tests/debug.py
2===================================================================
3--- tests/regressiontests/views/tests/debug.py  (revision 17029)
4+++ tests/regressiontests/views/tests/debug.py  (working copy)
5@@ -3,6 +3,7 @@
6 import inspect
7 import os
8 import sys
9+import tempfile
10 
11 from django.conf import settings
12 from django.core.files.uploadedfile import SimpleUploadedFile
13@@ -171,6 +172,28 @@
14         self.assertIn('<h2>Request information</h2>', html)
15         self.assertIn('<p>Request data not supplied</p>', html)
16 
17+    def test_eol_support(self):
18+        """Test that the ExceptionReporter supports Unix, Windows and Macintosh EOL markers"""
19+        FILE_CONTENT = 'print 1\nprint 2\nprint 3\nprint 4\nprint 5\n'
20+        unix_fd, unix_filename = tempfile.mkstemp(text = False)
21+        windows_fd, windows_filename = tempfile.mkstemp(text = False)
22+        macintosh_fd, macintosh_filename = tempfile.mkstemp(text = False)
23+        os.write(unix_fd, FILE_CONTENT)
24+        os.write(windows_fd, FILE_CONTENT.replace('\n', '\r\n'))
25+        os.write(macintosh_fd, FILE_CONTENT.replace('\n', '\r'))
26+        os.close(unix_fd)
27+        os.close(windows_fd)
28+        os.close(macintosh_fd)
29+       
30+        reporter = ExceptionReporter(None, None, None, None)
31+        try:
32+            self.assertEqual(reporter._get_lines_from_file(unix_filename, 3, 2), (1, [u'print 2', u'print 3'], u'print 4', [u'print 5']))
33+            self.assertEqual(reporter._get_lines_from_file(windows_filename, 3, 2), (1, [u'print 2', u'print 3'], u'print 4', [u'print 5']))
34+            self.assertEqual(reporter._get_lines_from_file(macintosh_filename, 3, 2), (1, [u'print 2', u'print 3'], u'print 4', [u'print 5']))
35+        finally:
36+            os.unlink(unix_filename)
37+            os.unlink(windows_filename)
38+            os.unlink(macintosh_filename)
39 
40 class PlainTextReportTests(TestCase):
41     rf = RequestFactory()