Changeset 135:8b964abba1db


Ignore:
Timestamp:
Mar 30, 2002, 10:54:38 PM (18 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Convert:
svn:778c30c8-61e0-0310-89d4-fe2f97a467b2/trunk@136
Message:
Module: instead of using the class InspectableFTPHost with its quite
    implementation-dependent method file_content_for_child, file
    content is now accessible via the _mock_file.content_of function.
    Any tests which used file_content_for_child now use
    _mock_file.content_of instead.
Module: deleted InspectableFTPHost and made ftputil.FTPHost the default
    FTP host class in ftp_host_factory.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • _test_ftputil.py

    r133 r135  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3131
    32 # $Id: _test_ftputil.py,v 1.45 2002/03/30 21:22:24 schwa Exp $
     32# $Id: _test_ftputil.py,v 1.46 2002/03/30 21:54:38 schwa Exp $
    3333
    3434import unittest
     
    5555
    5656
    57 class InspectableFTPHost(ftputil.FTPHost):
    58     def file_content_for_child(self, child_index):
    59         """
    60         Return content for the associated file object of a child
    61         FTPHost object.
    62 
    63         Usage of the getvalue() method implies that the file object
    64         really is a StringIO.StringIO object. In fact, this kind of
    65         file object is established by the MockSocket class which in
    66         turn is used by the MockSession class.
    67 
    68         Unfortunately, this method requires deep knowledge of the
    69         internal implementation of the FTPHost and _FTPFile classes.
    70         """
    71         child = self._children[child_index]
    72         ftp_file = child._file
    73         file_object = ftp_file._fo
    74         file_content = file_object.getvalue()
    75         return file_content
    76 
    77 
    7857def ftp_host_factory(session_factory=_mock_ftplib.MockSession,
    79                      ftp_host_class=InspectableFTPHost):
     58                     ftp_host_class=ftputil.FTPHost):
    8059    return ftp_host_class('dummy_host', 'dummy_user', 'dummy_password',
    8160                          session_factory=session_factory)
     
    242221        output.write(data)
    243222        output.close()
    244         child_data = host.file_content_for_child(0)
     223        child_data = _mock_ftplib.content_of('dummy')
    245224        expected_data = data
    246225        self.assertEqual(child_data, expected_data)
     
    253232        output.write(data)
    254233        output.close()
    255         child_data = host.file_content_for_child(0)
     234        child_data = _mock_ftplib.content_of('dummy')
    256235        expected_data = ' \r\nline 2\r\nline 3'
    257236        self.assertEqual(child_data, expected_data)
     
    265244        output.writelines(data)
    266245        output.close()
    267         child_data = host.file_content_for_child(0)
     246        child_data = _mock_ftplib.content_of('dummy')
    268247        expected_data = ' \r\nline 2\r\nline 3'
    269248        self.assertEqual(child_data, expected_data)
     
    394373        return self.random_data(pool)
    395374
    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'
    405 #         # test ascii up/download
    406 #         host.upload(local_source, 'dummy')
    407 #         
     375    def test_ascii_upload(self):
     376        """Test ASCII mode upload."""
     377        local_source = '__test_source'
     378        # generate file
     379        data = self.ascii_data()
     380        source_file = open(local_source, 'w')
     381        source_file.write(data)
     382        source_file.close()
     383        # upload
     384        host = ftp_host_factory()
     385        host.upload(local_source, 'dummy')
     386        # check uploaded content
     387        data = data.replace('\n', '\r\n')
     388        file_content = _mock_ftplib.content_of('dummy')
     389        self.assertEqual(data, file_content)
     390
    408391#         host.download(remote_path, local_test_path)
    409392#         # compare local data
Note: See TracChangeset for help on using the changeset viewer.