| 270 | | # |
|---|
| 271 | | # def ascii_read(self): |
|---|
| 272 | | # """Write some ASCII data to the host and use plain |
|---|
| 273 | | # read operations to get it back. |
|---|
| 274 | | # """ |
|---|
| 275 | | # host = self.host |
|---|
| 276 | | # # write some data |
|---|
| 277 | | # local_data = 'line 1\nanother line\nyet another line' |
|---|
| 278 | | # self.write_test_data(local_data, 'w') |
|---|
| 279 | | # # read with read method |
|---|
| 280 | | # input_ = host.file(self.remote_name, 'r') |
|---|
| 281 | | # data = input_.read(0) |
|---|
| 282 | | # self.assertEqual(data, '') |
|---|
| 283 | | # data = input_.read(3) |
|---|
| 284 | | # self.assertEqual(data, 'lin') |
|---|
| 285 | | # data = input_.read(7) |
|---|
| 286 | | # self.assertEqual(data, 'e 1\nano') |
|---|
| 287 | | # data = input_.read() |
|---|
| 288 | | # self.assertEqual(data, 'ther line\nyet another line') |
|---|
| 289 | | # data = input_.read() |
|---|
| 290 | | # self.assertEqual(data, '') |
|---|
| 291 | | # input_.close() |
|---|
| 292 | | # # try it again with a more "problematic" string which |
|---|
| 293 | | # # makes several reads in the read() method necessary. |
|---|
| 294 | | # local_data = '\n'.join( map( str, range(20) ) ) |
|---|
| 295 | | # output = host.file(self.remote_name, 'w') |
|---|
| 296 | | # output.writelines(local_data) |
|---|
| 297 | | # output.close() |
|---|
| 298 | | # input_ = host.file(self.remote_name, 'r') |
|---|
| 299 | | # data = input_.read( len(local_data) ) |
|---|
| 300 | | # self.assertEqual(data, local_data) |
|---|
| 301 | | # |
|---|
| | 273 | def test_ascii_read(self): |
|---|
| | 274 | """Write some ASCII data to the host and use plain |
|---|
| | 275 | read operations to get it back. |
|---|
| | 276 | """ |
|---|
| | 277 | host = ftp_host_factory(session_factory=AsciiReadMockSession1) |
|---|
| | 278 | input_ = host.file('dummy', 'r') |
|---|
| | 279 | data = input_.read(0) |
|---|
| | 280 | self.assertEqual(data, '') |
|---|
| | 281 | data = input_.read(3) |
|---|
| | 282 | self.assertEqual(data, 'lin') |
|---|
| | 283 | data = input_.read(7) |
|---|
| | 284 | self.assertEqual(data, 'e 1\nano') |
|---|
| | 285 | data = input_.read() |
|---|
| | 286 | self.assertEqual(data, 'ther line\nyet another line') |
|---|
| | 287 | data = input_.read() |
|---|
| | 288 | self.assertEqual(data, '') |
|---|
| | 289 | input_.close() |
|---|
| | 290 | # try it again with a more "problematic" string which |
|---|
| | 291 | # makes several reads in the read() method necessary. |
|---|
| | 292 | host = ftp_host_factory(session_factory=AsciiReadMockSession2) |
|---|
| | 293 | expected_data = AsciiReadMockSession2.mock_file_content.\ |
|---|
| | 294 | replace('\r\n', '\n') |
|---|
| | 295 | input_ = host.file('dummy', 'r') |
|---|
| | 296 | data = input_.read( len(expected_data) ) |
|---|
| | 297 | self.assertEqual(data, expected_data) |
|---|
| | 298 | |
|---|