Changeset 125

Show
Ignore:
Timestamp:
2002-03-30 18:13:47 (7 years ago)
Author:
schwa
Message:
TestFileOperations: converted ascii_read to test_ascii_read using
    mock objects.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/_test_ftputil.py

    r124 r125  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 
    32 # $Id: _test_ftputil.py,v 1.37 2002/03/30 17:51:53 schwa Exp $ 
     32# $Id: _test_ftputil.py,v 1.38 2002/03/30 18:13:47 schwa Exp $ 
    3333 
    3434import unittest 
     
    4747        raise ftplib.error_perm 
    4848 
    49 class BinaryReadMockSession(_mock_ftplib.MockSession): 
    50         file_content = '\000a\001b\r\n\002c\003\n\004\r\005' 
     49class AsciiReadMockSession1(_mock_ftplib.MockSession): 
     50    mock_file_content = 'line 1\r\nanother line\r\nyet another line' 
     51 
     52class AsciiReadMockSession2(_mock_ftplib.MockSession): 
     53    mock_file_content = '\r\n'.join( map( str, range(20) ) ) 
    5154 
    5255 
     
    5659        Return content for the associated file object of a child 
    5760        FTPHost object. 
    58          
     61 
    5962        Usage of the getvalue() method implies that the file object 
    6063        really is a StringIO.StringIO object. In fact, this kind of 
     
    268271        self.assertEqual(data, backup_data) 
    269272 
    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 
    302299#     def ascii_readline(self): 
    303300#         """Write some ASCII data to the host and use readline