Changeset 134

Show
Ignore:
Timestamp:
2002-03-30 21:22:24 (7 years ago)
Author:
schwa
Message:
Module: put calls to file_content_for_child after close calls.
TestFileOperations: added some methods to generate text and binary data
    files with "random" content.
Files:

Legend:

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

    r132 r134  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 
    32 # $Id: _test_ftputil.py,v 1.44 2002/03/30 18:56:56 schwa Exp $ 
     32# $Id: _test_ftputil.py,v 1.45 2002/03/30 21:22:24 schwa Exp $ 
    3333 
    3434import unittest 
     
    3737import time 
    3838import operator 
     39import random 
    3940 
    4041import ftplib 
     
    240241        output = host.file('dummy', 'wb') 
    241242        output.write(data) 
    242         # must be checked _before_ close 
     243        output.close() 
    243244        child_data = host.file_content_for_child(0) 
    244         output.close() 
    245245        expected_data = data 
    246246        self.assertEqual(child_data, expected_data) 
     
    252252        output = host.file('dummy', 'w') 
    253253        output.write(data) 
     254        output.close() 
    254255        child_data = host.file_content_for_child(0) 
    255         output.close() 
    256256        expected_data = ' \r\nline 2\r\nline 3' 
    257257        self.assertEqual(child_data, expected_data) 
     
    264264        output = host.file('dummy', 'w') 
    265265        output.writelines(data) 
     266        output.close() 
    266267        child_data = host.file_content_for_child(0) 
    267         output.close() 
    268268        expected_data = ' \r\nline 2\r\nline 3' 
    269269        self.assertEqual(child_data, expected_data) 
     
    371371                          'notthere', 'r') 
    372372 
    373 
    374 #     def test_upload_download(self): 
    375 #         """Test FTPHost.upload/download.""" 
    376 #         host = self.host 
    377 #         local_source = 'ftputil.py' 
    378 #         local_test_path = '__test.dat' 
    379 #         remote_path = host.path.join(self.testdir, 
    380 #                                      'ftputil2.py') 
     373    def random_data(self, pool, size=10000): 
     374        """ 
     375        Return a sequence of characters consisting of those from 
     376        the pool of integer numbers. 
     377        """ 
     378        character_list = [] 
     379        for i in range(size): 
     380            ordinal = random.choice(pool) 
     381            character_list.append( chr(ordinal) ) 
     382        result = ''.join(character_list) 
     383        return result 
     384         
     385    def ascii_data(self): 
     386        """Return an ASCII character string.""" 
     387        pool = range(32, 128) 
     388        pool.append( ord('\n') ) 
     389        return self.random_data(pool) 
     390         
     391    def binary_data(self): 
     392        """Return an binary character string.""" 
     393        pool = range(0, 256) 
     394        return self.random_data(pool) 
     395 
     396#     def test_ascii_upload(self): 
     397#         """Test ASCII mode upload.""" 
     398#         # generate file 
     399#         source_file = open('__test_source', 'wb') 
     400#         source_file.write( self.ascii_data() ) 
     401#         source_file.close() 
     402#         # upload 
     403#         host = ftp_host_factory() 
     404#         local_source = '__test_source' 
    381405#         # test ascii up/download 
    382 #         host.upload(local_source, remote_path) 
     406#         host.upload(local_source, 'dummy') 
     407#          
    383408#         host.download(remote_path, local_test_path) 
    384409#         # compare local data