|
4 | 4 | import os |
5 | 5 | import sys |
6 | 6 |
|
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 = [ |
8 | 14 | "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, |
14 | 21 | ] |
| 22 | + |
15 | 23 | DATA_LF = "\n".join(DATA_TEMPLATE) + "\n" |
16 | 24 | DATA_CR = "\r".join(DATA_TEMPLATE) + "\r" |
17 | 25 | DATA_CRLF = "\r\n".join(DATA_TEMPLATE) + "\r\n" |
| 26 | + |
18 | 27 | # Note that DATA_MIXED also tests the ability to recognize a lone \r |
19 | 28 | # before end-of-file. |
20 | 29 | 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 |
26 | 32 |
|
27 | 33 | class TestGenericUnivNewlines(unittest.TestCase): |
28 | 34 | # use a class variable DATA to define the data to write to the file |
@@ -74,33 +80,34 @@ def test_seek(self): |
74 | 80 | self.assertEqual(data, DATA_SPLIT[1:]) |
75 | 81 |
|
76 | 82 | 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'] |
80 | 86 | self.assertEqual(func.func_code.co_firstlineno, 3) |
| 87 | + self.assertEqual(namespace['line4'], FATX) |
81 | 88 |
|
82 | 89 |
|
83 | 90 | 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' |
88 | 95 |
|
89 | 96 | class TestCRNewlines(TestGenericUnivNewlines): |
90 | | - NEWLINE='\r' |
91 | | - DATA=DATA_CR |
| 97 | + NEWLINE = '\r' |
| 98 | + DATA = DATA_CR |
92 | 99 |
|
93 | 100 | class TestLFNewlines(TestGenericUnivNewlines): |
94 | | - NEWLINE='\n' |
95 | | - DATA=DATA_LF |
| 101 | + NEWLINE = '\n' |
| 102 | + DATA = DATA_LF |
96 | 103 |
|
97 | 104 | class TestCRLFNewlines(TestGenericUnivNewlines): |
98 | | - NEWLINE='\r\n' |
99 | | - DATA=DATA_CRLF |
| 105 | + NEWLINE = '\r\n' |
| 106 | + DATA = DATA_CRLF |
100 | 107 |
|
101 | 108 | class TestMixedNewlines(TestGenericUnivNewlines): |
102 | | - NEWLINE=('\r', '\n') |
103 | | - DATA=DATA_MIXED |
| 109 | + NEWLINE = ('\r', '\n') |
| 110 | + DATA = DATA_MIXED |
104 | 111 |
|
105 | 112 |
|
106 | 113 | def test_main(): |
|
0 commit comments