Ticket #13958: unittest_13958.diff

File unittest_13958.diff, 1.9 KB (added by fredrik.kers@…, 4 years ago)
  • tests/regressiontests/views/tests/debug.py

     
    33import inspect
    44import os
    55import sys
     6import tempfile
    67
    78from django.conf import settings
    89from django.core.files.uploadedfile import SimpleUploadedFile
     
    171172        self.assertIn('<h2>Request information</h2>', html)
    172173        self.assertIn('<p>Request data not supplied</p>', html)
    173174
     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            assertEqual(reporter._get_lines_from_file(unix_filename, 3, 2), (1, [u'print 2', u'print 3'], u'print 4', [u'print 5']))
     191            assertEqual(reporter._get_lines_from_file(windows_filename, 3, 2), (1, [u'print 2', u'print 3'], u'print 4', [u'print 5']))
     192            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)
    174197
    175198class PlainTextReportTests(TestCase):
    176199    rf = RequestFactory()
Back to Top