Changeset 138

Show
Ignore:
Timestamp:
2002-03-30 22:11:59 (7 years ago)
Author:
schwa
Message:
TestFileOperations: adapted test_caching to use mock objects.
Files:

Legend:

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

    r137 r138  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 
    32 # $Id: _test_ftputil.py,v 1.47 2002/03/30 22:08:45 schwa Exp $ 
     32# $Id: _test_ftputil.py,v 1.48 2002/03/30 22:11:59 schwa Exp $ 
    3333 
    3434import unittest 
     
    6565    result = ''.join(character_list) 
    6666    return result 
    67      
     67 
    6868def ascii_data(): 
    6969    """Return an ASCII character string.""" 
     
    7171    pool.append( ord('\n') ) 
    7272    return random_data(pool) 
    73      
     73 
    7474def binary_data(): 
    7575    """Return an binary character string.""" 
     
    8080    mock_file_content = binary_data() 
    8181 
    82      
     82 
    8383def ftp_host_factory(session_factory=_mock_ftplib.MockSession, 
    8484                     ftp_host_class=ftputil.FTPHost): 
     
    198198    uploads and downloads). 
    199199    """ 
    200  
    201 #     def test_caching(self): 
    202 #         """Test if _FTPFile cache of FTPHost object works.""" 
    203 #         host = FTPHostWrapper(host_name, user, password) 
    204 #         self.assertEqual( len(host._children), 0 ) 
    205 #         path1 = host.path.join(self.testdir, '__test1.dat') 
    206 #         path2 = host.path.join(self.testdir, '__test2.dat') 
    207 #         # open one file and inspect cache 
    208 #         file1 = host.file(path1, 'w') 
    209 #         child1 = host._children[0] 
    210 #         self.assertEqual( len(host._children), 1 ) 
    211 #         self.failIf(child1._file.closed) 
    212 #         # open another file 
    213 #         file2 = host.file(path2, 'w') 
    214 #         child2 = host._children[1] 
    215 #         self.assertEqual( len(host._children), 2 ) 
    216 #         self.failIf(child2._file.closed) 
    217 #         # close first file 
    218 #         file1.close() 
    219 #         self.assertEqual( len(host._children), 2 ) 
    220 #         self.failUnless(child1._file.closed) 
    221 #         self.failIf(child2._file.closed) 
    222 #         # re-open first child's file 
    223 #         file1 = host.file(path1, 'w') 
    224 #         child1_1 = file1._host 
    225 #         # check if it's reused 
    226 #         self.failUnless(child1 is child1_1) 
    227 #         self.failIf(child1._file.closed) 
    228 #         self.failIf(child2._file.closed) 
    229 #         # close second file 
    230 #         file2.close() 
    231 #         self.failUnless(child2._file.closed) 
    232 #         # clean up 
    233 #         host.remove(path1) 
    234 #         host.remove(path2) 
    235 
     200    def test_caching(self): 
     201        """Test if _FTPFile cache of FTPHost object works.""" 
     202        host = ftp_host_factory() 
     203        self.assertEqual( len(host._children), 0 ) 
     204        path1 = 'path1' 
     205        path2 = 'path2' 
     206        # open one file and inspect cache 
     207        file1 = host.file(path1, 'w') 
     208        child1 = host._children[0] 
     209        self.assertEqual( len(host._children), 1 ) 
     210        self.failIf(child1._file.closed) 
     211        # open another file 
     212        file2 = host.file(path2, 'w') 
     213        child2 = host._children[1] 
     214        self.assertEqual( len(host._children), 2 ) 
     215        self.failIf(child2._file.closed) 
     216        # close first file 
     217        file1.close() 
     218        self.assertEqual( len(host._children), 2 ) 
     219        self.failUnless(child1._file.closed) 
     220        self.failIf(child2._file.closed) 
     221        # re-open first child's file 
     222        file1 = host.file(path1, 'w') 
     223        child1_1 = file1._host 
     224        # check if it's reused 
     225        self.failUnless(child1 is child1_1) 
     226        self.failIf(child1._file.closed) 
     227        self.failIf(child2._file.closed) 
     228        # close second file 
     229        file2.close() 
     230        self.failUnless(child2._file.closed) 
     231 
    236232    def test_write_to_directory(self): 
    237233        """Test whether attempting to write to a directory fails."""