Kaydet (Commit) ea572b21 authored tarafından Tim Peters's avatar Tim Peters

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.
üst 4a0db06e
...@@ -4,25 +4,31 @@ import test_support ...@@ -4,25 +4,31 @@ import test_support
import os import os
import sys import sys
DATA_TEMPLATE=[ 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", "line1=1",
"line2='this is a very long line designed to go past the magic " + "line2='this is a very long line designed to go past the magic " +
"hundred character limit that is inside fileobject.c and which " + "hundred character limit that is inside fileobject.c and which " +
"is meant to speed up the common case, but we also want to test " + "is meant to speed up the common case, but we also want to test " +
"the uncommon case, naturally.'", "the uncommon case, naturally.'",
"def line3():pass" "def line3():pass",
"line4 = '%s'" % FATX,
] ]
DATA_LF = "\n".join(DATA_TEMPLATE) + "\n" DATA_LF = "\n".join(DATA_TEMPLATE) + "\n"
DATA_CR = "\r".join(DATA_TEMPLATE) + "\r" DATA_CR = "\r".join(DATA_TEMPLATE) + "\r"
DATA_CRLF = "\r\n".join(DATA_TEMPLATE) + "\r\n" DATA_CRLF = "\r\n".join(DATA_TEMPLATE) + "\r\n"
# Note that DATA_MIXED also tests the ability to recognize a lone \r # Note that DATA_MIXED also tests the ability to recognize a lone \r
# before end-of-file. # before end-of-file.
DATA_MIXED = "\n".join(DATA_TEMPLATE) + "\r" DATA_MIXED = "\n".join(DATA_TEMPLATE) + "\r"
DATA_SPLIT = map(lambda x: x+"\n", DATA_TEMPLATE) DATA_SPLIT = [x + "\n" for x in DATA_TEMPLATE]
del x
if not hasattr(sys.stdin, 'newlines'):
raise test_support.TestSkipped, \
"This Python does not have universal newline support"
class TestGenericUnivNewlines(unittest.TestCase): class TestGenericUnivNewlines(unittest.TestCase):
# use a class variable DATA to define the data to write to the file # use a class variable DATA to define the data to write to the file
...@@ -74,33 +80,34 @@ class TestGenericUnivNewlines(unittest.TestCase): ...@@ -74,33 +80,34 @@ class TestGenericUnivNewlines(unittest.TestCase):
self.assertEqual(data, DATA_SPLIT[1:]) self.assertEqual(data, DATA_SPLIT[1:])
def test_execfile(self): def test_execfile(self):
dict = {} namespace = {}
execfile(test_support.TESTFN, dict) execfile(test_support.TESTFN, namespace)
func = dict['line3'] func = namespace['line3']
self.assertEqual(func.func_code.co_firstlineno, 3) self.assertEqual(func.func_code.co_firstlineno, 3)
self.assertEqual(namespace['line4'], FATX)
class TestNativeNewlines(TestGenericUnivNewlines): class TestNativeNewlines(TestGenericUnivNewlines):
NEWLINE=None NEWLINE = None
DATA=DATA_LF DATA = DATA_LF
READMODE='r' READMODE = 'r'
WRITEMODE='w' WRITEMODE = 'w'
class TestCRNewlines(TestGenericUnivNewlines): class TestCRNewlines(TestGenericUnivNewlines):
NEWLINE='\r' NEWLINE = '\r'
DATA=DATA_CR DATA = DATA_CR
class TestLFNewlines(TestGenericUnivNewlines): class TestLFNewlines(TestGenericUnivNewlines):
NEWLINE='\n' NEWLINE = '\n'
DATA=DATA_LF DATA = DATA_LF
class TestCRLFNewlines(TestGenericUnivNewlines): class TestCRLFNewlines(TestGenericUnivNewlines):
NEWLINE='\r\n' NEWLINE = '\r\n'
DATA=DATA_CRLF DATA = DATA_CRLF
class TestMixedNewlines(TestGenericUnivNewlines): class TestMixedNewlines(TestGenericUnivNewlines):
NEWLINE=('\r', '\n') NEWLINE = ('\r', '\n')
DATA=DATA_MIXED DATA = DATA_MIXED
def test_main(): def test_main():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment