@@ -107,16 +107,15 @@ def test_partial_reads(self):
107107 source = 'ϼўТλФЙ\r \n ' .encode ('utf-16-le' )
108108 expected = 'ϼўТλФЙ\r \n ' .encode ('utf-8' )
109109 for read_count in range (1 , 16 ):
110- stdin = open ('CONIN$' , 'rb' , buffering = 0 )
111- write_input (stdin , source )
110+ with open ('CONIN$' , 'rb' , buffering = 0 ) as stdin :
111+ write_input (stdin , source )
112112
113- actual = b''
114- while not actual .endswith (b'\n ' ):
115- b = stdin .read (read_count )
116- actual += b
113+ actual = b''
114+ while not actual .endswith (b'\n ' ):
115+ b = stdin .read (read_count )
116+ actual += b
117117
118- self .assertEqual (actual , expected , 'stdin.read({})' .format (read_count ))
119- stdin .close ()
118+ self .assertEqual (actual , expected , 'stdin.read({})' .format (read_count ))
120119
121120 def test_partial_surrogate_reads (self ):
122121 # Test that reading less than 1 full character works when stdin
@@ -125,17 +124,24 @@ def test_partial_surrogate_reads(self):
125124 source = '\U00101FFF \U00101001 \r \n ' .encode ('utf-16-le' )
126125 expected = '\U00101FFF \U00101001 \r \n ' .encode ('utf-8' )
127126 for read_count in range (1 , 16 ):
128- stdin = open ('CONIN$' , 'rb' , buffering = 0 )
129- write_input (stdin , source )
127+ with open ('CONIN$' , 'rb' , buffering = 0 ) as stdin :
128+ write_input (stdin , source )
130129
131- actual = b''
132- while not actual .endswith (b'\n ' ):
133- b = stdin .read (read_count )
134- actual += b
130+ actual = b''
131+ while not actual .endswith (b'\n ' ):
132+ b = stdin .read (read_count )
133+ actual += b
135134
136- self .assertEqual (actual , expected , 'stdin.read({})' .format (read_count ))
137- stdin .close ()
135+ self .assertEqual (actual , expected , 'stdin.read({})' .format (read_count ))
138136
137+ def test_ctrl_z (self ):
138+ with open ('CONIN$' , 'rb' , buffering = 0 ) as stdin :
139+ source = '\xC4 \x1A \r \n ' .encode ('utf-16-le' )
140+ expected = '\xC4 ' .encode ('utf-8' )
141+ write_input (stdin , source )
142+ a , b = stdin .read (1 ), stdin .readall ()
143+ self .assertEqual (expected [0 :1 ], a )
144+ self .assertEqual (expected [1 :], b )
139145
140146if __name__ == "__main__" :
141147 unittest .main ()
0 commit comments