Mailing List Archive

python/dist/src/Lib/test test_univnewlines.py,1.2,1.3
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv10396

Modified Files:
test_univnewlines.py
Log Message:
Assorted code cleanups for readability. Greatly boosted the size of the
test data: this test fails on WIndows now if universal newlines are
enabled (which they aren't yet, by default). I don't know whether the
test will also fail on Linux now.


Index: test_univnewlines.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_univnewlines.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_univnewlines.py 16 Apr 2002 01:38:40 -0000 1.2
--- test_univnewlines.py 21 Apr 2002 06:12:02 -0000 1.3
***************
*** 5,27 ****
import sys

! DATA_TEMPLATE=[
"line1=1",
! "line2='this is a very long line designed to go past the magic " +
! "hundred character limit that is inside fileobject.c and which " +
! "is meant to speed up the common case, but we also want to test " +
! "the uncommon case, naturally.'",
! "def line3():pass"
]
DATA_LF = "\n".join(DATA_TEMPLATE) + "\n"
DATA_CR = "\r".join(DATA_TEMPLATE) + "\r"
DATA_CRLF = "\r\n".join(DATA_TEMPLATE) + "\r\n"
# Note that DATA_MIXED also tests the ability to recognize a lone \r
# before end-of-file.
DATA_MIXED = "\n".join(DATA_TEMPLATE) + "\r"
! DATA_SPLIT = map(lambda x: x+"\n", DATA_TEMPLATE)
!
! if not hasattr(sys.stdin, 'newlines'):
! raise test_support.TestSkipped, \
! "This Python does not have universal newline support"

class TestGenericUnivNewlines(unittest.TestCase):
--- 5,33 ----
import sys

! if not hasattr(sys.stdin, 'newlines'):
! raise test_support.TestSkipped, \
! "This Python does not have universal newline support"
!
! FATX = 'x' * (2**14)
!
! DATA_TEMPLATE = [
"line1=1",
! "line2='this is a very long line designed to go past the magic " +
! "hundred character limit that is inside fileobject.c and which " +
! "is meant to speed up the common case, but we also want to test " +
! "the uncommon case, naturally.'",
! "def line3():pass",
! "line4 = '%s'" % FATX,
]
+
DATA_LF = "\n".join(DATA_TEMPLATE) + "\n"
DATA_CR = "\r".join(DATA_TEMPLATE) + "\r"
DATA_CRLF = "\r\n".join(DATA_TEMPLATE) + "\r\n"
+
# Note that DATA_MIXED also tests the ability to recognize a lone \r
# before end-of-file.
DATA_MIXED = "\n".join(DATA_TEMPLATE) + "\r"
! DATA_SPLIT = [x + "\n" for x in DATA_TEMPLATE]
! del x

class TestGenericUnivNewlines(unittest.TestCase):
***************
*** 75,105 ****

def test_execfile(self):
! dict = {}
! execfile(test_support.TESTFN, dict)
! func = dict['line3']
self.assertEqual(func.func_code.co_firstlineno, 3)


class TestNativeNewlines(TestGenericUnivNewlines):
! NEWLINE=None
! DATA=DATA_LF
! READMODE='r'
! WRITEMODE='w'

class TestCRNewlines(TestGenericUnivNewlines):
! NEWLINE='\r'
! DATA=DATA_CR

class TestLFNewlines(TestGenericUnivNewlines):
! NEWLINE='\n'
! DATA=DATA_LF

class TestCRLFNewlines(TestGenericUnivNewlines):
! NEWLINE='\r\n'
! DATA=DATA_CRLF

class TestMixedNewlines(TestGenericUnivNewlines):
! NEWLINE=('\r', '\n')
! DATA=DATA_MIXED


--- 81,112 ----

def test_execfile(self):
! namespace = {}
! execfile(test_support.TESTFN, namespace)
! func = namespace['line3']
self.assertEqual(func.func_code.co_firstlineno, 3)
+ self.assertEqual(namespace['line4'], FATX)


class TestNativeNewlines(TestGenericUnivNewlines):
! NEWLINE = None
! DATA = DATA_LF
! READMODE = 'r'
! WRITEMODE = 'w'

class TestCRNewlines(TestGenericUnivNewlines):
! NEWLINE = '\r'
! DATA = DATA_CR

class TestLFNewlines(TestGenericUnivNewlines):
! NEWLINE = '\n'
! DATA = DATA_LF

class TestCRLFNewlines(TestGenericUnivNewlines):
! NEWLINE = '\r\n'
! DATA = DATA_CRLF

class TestMixedNewlines(TestGenericUnivNewlines):
! NEWLINE = ('\r', '\n')
! DATA = DATA_MIXED