Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea572b2

Browse files
committed
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.
1 parent 4a0db06 commit ea572b2

1 file changed

Lines changed: 33 additions & 26 deletions

File tree

Lib/test/test_univnewlines.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,31 @@
44
import os
55
import sys
66

7-
DATA_TEMPLATE=[
7+
if not hasattr(sys.stdin, 'newlines'):
8+
raise test_support.TestSkipped, \
9+
"This Python does not have universal newline support"
10+
11+
FATX = 'x' * (2**14)
12+
13+
DATA_TEMPLATE = [
814
"line1=1",
9-
"line2='this is a very long line designed to go past the magic " +
10-
"hundred character limit that is inside fileobject.c and which " +
11-
"is meant to speed up the common case, but we also want to test " +
12-
"the uncommon case, naturally.'",
13-
"def line3():pass"
15+
"line2='this is a very long line designed to go past the magic " +
16+
"hundred character limit that is inside fileobject.c and which " +
17+
"is meant to speed up the common case, but we also want to test " +
18+
"the uncommon case, naturally.'",
19+
"def line3():pass",
20+
"line4 = '%s'" % FATX,
1421
]
22+
1523
DATA_LF = "\n".join(DATA_TEMPLATE) + "\n"
1624
DATA_CR = "\r".join(DATA_TEMPLATE) + "\r"
1725
DATA_CRLF = "\r\n".join(DATA_TEMPLATE) + "\r\n"
26+
1827
# Note that DATA_MIXED also tests the ability to recognize a lone \r
1928
# before end-of-file.
2029
DATA_MIXED = "\n".join(DATA_TEMPLATE) + "\r"
21-
DATA_SPLIT = map(lambda x: x+"\n", DATA_TEMPLATE)
22-
23-
if not hasattr(sys.stdin, 'newlines'):
24-
raise test_support.TestSkipped, \
25-
"This Python does not have universal newline support"
30+
DATA_SPLIT = [x + "\n" for x in DATA_TEMPLATE]
31+
del x
2632

2733
class TestGenericUnivNewlines(unittest.TestCase):
2834
# use a class variable DATA to define the data to write to the file
@@ -74,33 +80,34 @@ def test_seek(self):
7480
self.assertEqual(data, DATA_SPLIT[1:])
7581

7682
def test_execfile(self):
77-
dict = {}
78-
execfile(test_support.TESTFN, dict)
79-
func = dict['line3']
83+
namespace = {}
84+
execfile(test_support.TESTFN, namespace)
85+
func = namespace['line3']
8086
self.assertEqual(func.func_code.co_firstlineno, 3)
87+
self.assertEqual(namespace['line4'], FATX)
8188

8289

8390
class TestNativeNewlines(TestGenericUnivNewlines):
84-
NEWLINE=None
85-
DATA=DATA_LF
86-
READMODE='r'
87-
WRITEMODE='w'
91+
NEWLINE = None
92+
DATA = DATA_LF
93+
READMODE = 'r'
94+
WRITEMODE = 'w'
8895

8996
class TestCRNewlines(TestGenericUnivNewlines):
90-
NEWLINE='\r'
91-
DATA=DATA_CR
97+
NEWLINE = '\r'
98+
DATA = DATA_CR
9299

93100
class TestLFNewlines(TestGenericUnivNewlines):
94-
NEWLINE='\n'
95-
DATA=DATA_LF
101+
NEWLINE = '\n'
102+
DATA = DATA_LF
96103

97104
class TestCRLFNewlines(TestGenericUnivNewlines):
98-
NEWLINE='\r\n'
99-
DATA=DATA_CRLF
105+
NEWLINE = '\r\n'
106+
DATA = DATA_CRLF
100107

101108
class TestMixedNewlines(TestGenericUnivNewlines):
102-
NEWLINE=('\r', '\n')
103-
DATA=DATA_MIXED
109+
NEWLINE = ('\r', '\n')
110+
DATA = DATA_MIXED
104111

105112

106113
def test_main():

0 commit comments

Comments
 (0)