diff options
Diffstat (limited to 'Lib/test/test_univnewlines.py')
-rw-r--r-- | Lib/test/test_univnewlines.py | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_univnewlines.py index c4e4a3f..a6b9909 100644 --- a/Lib/test/test_univnewlines.py +++ b/Lib/test/test_univnewlines.py @@ -1,4 +1,6 @@ # Tests universal newline support for both reading and parsing files. +import io +import _pyio as pyio import unittest import os import sys @@ -35,7 +37,7 @@ class TestGenericUnivNewlines(unittest.TestCase): WRITEMODE = 'wb' def setUp(self): - fp = open(support.TESTFN, self.WRITEMODE) + fp = self.open(support.TESTFN, self.WRITEMODE) data = self.DATA if "b" in self.WRITEMODE: data = data.encode("ascii") @@ -49,19 +51,19 @@ class TestGenericUnivNewlines(unittest.TestCase): pass def test_read(self): - fp = open(support.TESTFN, self.READMODE) + fp = self.open(support.TESTFN, self.READMODE) data = fp.read() self.assertEqual(data, DATA_LF) self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_readlines(self): - fp = open(support.TESTFN, self.READMODE) + fp = self.open(support.TESTFN, self.READMODE) data = fp.readlines() self.assertEqual(data, DATA_SPLIT) self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_readline(self): - fp = open(support.TESTFN, self.READMODE) + fp = self.open(support.TESTFN, self.READMODE) data = [] d = fp.readline() while d: @@ -71,7 +73,7 @@ class TestGenericUnivNewlines(unittest.TestCase): self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_seek(self): - fp = open(support.TESTFN, self.READMODE) + fp = self.open(support.TESTFN, self.READMODE) fp.readline() pos = fp.tell() data = fp.readlines() @@ -94,7 +96,7 @@ class TestCRLFNewlines(TestGenericUnivNewlines): DATA = DATA_CRLF def test_tell(self): - fp = open(support.TESTFN, self.READMODE) + fp = self.open(support.TESTFN, self.READMODE) self.assertEqual(repr(fp.newlines), repr(None)) data = fp.readline() pos = fp.tell() @@ -106,12 +108,22 @@ class TestMixedNewlines(TestGenericUnivNewlines): def test_main(): - support.run_unittest( - TestCRNewlines, - TestLFNewlines, - TestCRLFNewlines, - TestMixedNewlines - ) + base_tests = (TestCRNewlines, + TestLFNewlines, + TestCRLFNewlines, + TestMixedNewlines) + tests = [] + # Test the C and Python implementations. + for test in base_tests: + class CTest(test): + open = io.open + CTest.__name__ = "C" + test.__name__ + class PyTest(test): + open = staticmethod(pyio.open) + PyTest.__name__ = "Py" + test.__name__ + tests.append(CTest) + tests.append(PyTest) + support.run_unittest(*tests) if __name__ == '__main__': test_main() |