<s> import io <EOL> import _pyio as pyio <EOL> import unittest <EOL> import os <EOL> import sys <EOL> from test import support <EOL> if not hasattr ( sys . stdin , '<STR_LIT>' ) : <EOL> raise unittest . SkipTest ( <EOL> "<STR_LIT>" ) <EOL> FATX = '<STR_LIT:x>' * ( <NUM_LIT:2> ** <NUM_LIT> ) <EOL> DATA_TEMPLATE = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % FATX , <EOL> ] <EOL> DATA_LF = "<STR_LIT:\n>" . join ( DATA_TEMPLATE ) + "<STR_LIT:\n>" <EOL> DATA_CR = "<STR_LIT:\r>" . join ( DATA_TEMPLATE ) + "<STR_LIT:\r>" <EOL> DATA_CRLF = "<STR_LIT:\r\n>" . join ( DATA_TEMPLATE ) + "<STR_LIT:\r\n>" <EOL> DATA_MIXED = "<STR_LIT:\n>" . join ( DATA_TEMPLATE ) + "<STR_LIT:\r>" <EOL> DATA_SPLIT = [ x + "<STR_LIT:\n>" for x in DATA_TEMPLATE ] <EOL> class CTest : <EOL> open = io . open <EOL> class PyTest : <EOL> open = staticmethod ( pyio . open ) <EOL> class TestGenericUnivNewlines : <EOL> READMODE = '<STR_LIT:r>' <EOL> WRITEMODE = '<STR_LIT:wb>' <EOL> def setUp ( self ) : <EOL> data = self . DATA <EOL> if "<STR_LIT:b>" in self . WRITEMODE : <EOL> data = data . encode ( "<STR_LIT:ascii>" ) <EOL> with self . open ( support . TESTFN , self . WRITEMODE ) as fp : <EOL> fp . write ( data ) <EOL> def tearDown ( self ) : <EOL> try : <EOL> os . unlink ( support . TESTFN ) <EOL> except : <EOL> pass <EOL> def test_read ( self ) : <EOL> with self . open ( support . TESTFN , self . READMODE ) as fp : <EOL> data = fp . read ( ) <EOL> self . assertEqual ( data , DATA_LF ) <EOL> self . assertEqual ( repr ( fp . newlines ) , repr ( self . NEWLINE ) ) <EOL> def test_readlines ( self ) : <EOL> with self . open ( support . TESTFN , self . READMODE ) as fp : <EOL> data = fp . readlines ( ) <EOL> self . assertEqual ( data , DATA_SPLIT ) <EOL> self . assertEqual ( repr ( fp . newlines ) , repr ( self . NEWLINE ) ) <EOL> def test_readline ( self ) : <EOL> with self . open ( support . TESTFN , self . READMODE ) as fp : <EOL> data = [ ] <EOL> d = fp . readline ( ) <EOL> while d : <EOL> data . append ( d ) <EOL> d = fp . readline ( ) <EOL> self . assertEqual ( data , DATA_SPLIT ) <EOL> self . assertEqual ( repr ( fp . newlines ) , repr ( self . NEWLINE ) ) <EOL> def test_seek ( self ) : <EOL> with self . open ( support . TESTFN , self . READMODE ) as fp : <EOL> fp . readline ( ) <EOL> pos = fp . tell ( ) <EOL> data = fp . readlines ( ) <EOL> self . assertEqual ( data , DATA_SPLIT [ <NUM_LIT:1> : ] ) <EOL> fp . seek ( pos ) <EOL> data = fp . readlines ( ) <EOL> self . assertEqual ( data , DATA_SPLIT [ <NUM_LIT:1> : ] ) <EOL> class TestCRNewlines ( TestGenericUnivNewlines ) : <EOL> NEWLINE = '<STR_LIT:\r>' <EOL> DATA = DATA_CR <EOL> class CTestCRNewlines ( CTest , TestCRNewlines , unittest . TestCase ) : pass <EOL> class PyTestCRNewlines ( PyTest , TestCRNewlines , unittest . TestCase ) : pass <EOL> class TestLFNewlines ( TestGenericUnivNewlines ) : <EOL> NEWLINE = '<STR_LIT:\n>' <EOL> DATA = DATA_LF <EOL> class CTestLFNewlines ( CTest , TestLFNewlines , unittest . TestCase ) : pass <EOL> class PyTestLFNewlines ( PyTest , TestLFNewlines , unittest . TestCase ) : pass <EOL> class TestCRLFNewlines ( TestGenericUnivNewlines ) : <EOL> NEWLINE = '<STR_LIT:\r\n>' <EOL> DATA = DATA_CRLF <EOL> def test_tell ( self ) : <EOL> with self . open ( support . TESTFN , self . READMODE ) as fp : <EOL> self . assertEqual ( repr ( fp . newlines ) , repr ( None ) ) <EOL> data = fp . readline ( ) <EOL> pos = fp . tell ( ) <EOL> self . assertEqual ( repr ( fp . newlines ) , repr ( self . NEWLINE ) ) <EOL> class CTestCRLFNewlines ( CTest , TestCRLFNewlines , unittest . TestCase ) : pass <EOL> class PyTestCRLFNewlines ( PyTest , TestCRLFNewlines , unittest . TestCase ) : pass <EOL> class TestMixedNewlines ( TestGenericUnivNewlines ) : <EOL> NEWLINE = ( '<STR_LIT:\r>' , '<STR_LIT:\n>' ) <EOL> DATA = DATA_MIXED <EOL> class CTestMixedNewlines ( CTest , TestMixedNewlines , unittest . TestCase ) : pass <EOL> class PyTestMixedNewlines ( PyTest , TestMixedNewlines , unittest . TestCase ) : pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
