Changeset 113

Show
Ignore:
Timestamp:
2002-03-30 15:10:27 (7 years ago)
Author:
schwa
Message:
TestPath.test_isdir_isfile_islink: modified to work with mock session.
TestPath: removed methods test_getmtime and test_getsize because they are
    sematically contained in TestStat.test_lstat .
Files:

Legend:

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

    r110 r113  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 
    32 # $Id: _test_ftputil.py,v 1.27 2002/03/29 23:18:10 schwa Exp $ 
    33  
    34 # Ideas for future development: 
    35 #   - Rewrite tests to use mock FTP sessions 
    36 #     (see http://www.mockobjects.com) 
     32# $Id: _test_ftputil.py,v 1.28 2002/03/30 15:10:27 schwa Exp $ 
    3733 
    3834import unittest 
    39 import ftputil 
    40 import getpass 
    4135import stat 
    4236import os 
    4337import time 
    4438import operator 
     39 
     40import ftputil 
    4541import _mock_ftplib 
     42 
    4643 
    4744class FTPHostWrapper(ftputil.FTPHost): 
     
    6663        """Test FTPHost.lstat.""" 
    6764        # check if stat results are correct 
    68         host = FTPHostWrapper(_mock_ftplib.StatTest
    69         stat_result = host.lstat('/absolute/path/index.html') 
     65        host = FTPHostWrapper(_mock_ftplib.MockSession
     66        stat_result = host.lstat('/home/sschwarzer/index.html') 
    7067        self.assertEqual( oct(stat_result.st_mode), '0100644' ) 
    7168        self.assertEqual(stat_result.st_size, 4604) 
    72         host = FTPHostWrapper(_mock_ftplib.StatTest
    73         stat_result = host.lstat('/absolute/path/scios2') 
     69        host = FTPHostWrapper(_mock_ftplib.MockSession
     70        stat_result = host.lstat('/home/sschwarzer/scios2') 
    7471        self.assertEqual( oct(stat_result.st_mode), '042755' ) 
    7572        self.assertEqual(stat_result.st_size, 512) 
    7673        self.assertEqual(stat_result.st_mtime, 937785600.0) 
    7774        # test status indirectly via stat module 
    78         host = FTPHostWrapper(_mock_ftplib.StatTest
    79         stat_result = host.lstat('/absolute/path') 
     75        host = FTPHostWrapper(_mock_ftplib.MockSession
     76        stat_result = host.lstat('/home/sschwarzer/') 
    8077        self.failUnless( stat.S_ISDIR(stat_result.st_mode) ) 
    8178 
     
    8380        """Test FTPHost.listdir.""" 
    8481        # try to list a path which isn't there 
    85         host = FTPHostWrapper(_mock_ftplib.StatTest
     82        host = FTPHostWrapper(_mock_ftplib.MockSession
    8683        self.assertRaises(ftputil.PermanentError, 
    8784                          host.listdir, 'notthere') 
    8885        # do we have all expected "files"? 
    89         host = FTPHostWrapper(_mock_ftplib.StatTest
     86        host = FTPHostWrapper(_mock_ftplib.MockSession
    9087        self.assertEqual( len(host.listdir(host.curdir)), 9 ) 
    9188        # have they the expected names? 
    92         host = FTPHostWrapper(_mock_ftplib.StatTest
     89        host = FTPHostWrapper(_mock_ftplib.MockSession
    9390        expected = ('chemeng download image index.html os2 ' 
    9491                    'osup publications python scios2').split() 
     
    9895 
    9996 
    100 # class TestPath(Base): 
    101 #     """Test operations in FTPHost.path.""" 
    102 
    103 #     def test_isdir_isfile_islink(self): 
    104 #         """Test FTPHost._Path.isdir/isfile/islink.""" 
    105 #         host = self.host 
    106 #         host.chdir(self.testdir) 
    107 #         # test a path which isn't there 
    108 #         self.failIf( host.path.isdir('notthere') ) 
    109 #         self.failIf( host.path.isfile('notthere') ) 
    110 #         self.failIf( host.path.islink('notthere') ) 
    111 #         # test a directory 
    112 #         self.failUnless( host.path.isdir(self.testdir) ) 
    113 #         self.failIf( host.path.isfile(self.testdir) ) 
    114 #         self.failIf( host.path.islink(self.testdir) ) 
    115 #         # test a file 
    116 #         host.upload('ftputil.py', 'ftputil2.py', 'b') 
    117 #         self.failIf( host.path.isdir('ftputil2.py') ) 
    118 #         self.failUnless( host.path.isfile('ftputil2.py') ) 
    119 #         self.failIf( host.path.islink(self.testdir) ) 
    120 #         # clean up 
    121 #         host.remove('ftputil2.py') 
    122 #         host.chdir(self.rootdir) 
    123 
    124 #     def test_getmtime(self): 
    125 #         """Test FTPHost._Path.getmtime.""" 
    126 #         host = self.host 
    127 #         host.chdir(self.testdir) 
    128 #         # test a directory 
    129 #         local_time = time.time() 
    130 #         host.mkdir('__test2') 
    131 #         remote_mtime = host.path.getmtime('__test2') 
    132 #         #  accept a difference of up to 30 seconds 
    133 #         self.failIf(remote_mtime - local_time >= 30) 
    134 #         # test a file 
    135 #         local_time = time.time() 
    136 #         host.upload('ftputil.py', 'ftputil2.py', 'b') 
    137 #         remote_mtime = host.path.getmtime('ftputil2.py') 
    138 #         #  accept a difference of up to 30 seconds 
    139 #         self.failIf(remote_mtime - local_time >= 30) 
    140 #         # clean up 
    141 #         host.rmdir('__test2') 
    142 #         host.remove('ftputil2.py') 
    143 #         host.chdir(self.rootdir) 
    144 
    145 #     def test_getsize(self): 
    146 #         """Test FTPHost._Path.getsize.""" 
    147 #         host = self.host 
    148 #         host.chdir(self.testdir) 
    149 #         # test a directory 
    150 #         host.mkdir('__test2') 
    151 #         remote_size = host.path.getsize('__test2') 
    152 #         empty_dir_size = 512 
    153 #         self.assertEqual(remote_size, empty_dir_size) 
    154 #         # test a file 
    155 #         host.upload('ftputil.py', 'ftputil2.py', 'b') 
    156 #         local_size = os.path.getsize('ftputil.py') 
    157 #         remote_size = host.path.getsize('ftputil2.py') 
    158 #         self.assertEqual(local_size, remote_size) 
    159 #         # clean up 
    160 #         host.rmdir('__test2') 
    161 #         host.remove('ftputil2.py') 
    162 #         host.chdir(self.rootdir) 
    163 
    164 
     97class TestPath(unittest.TestCase): 
     98    """Test operations in FTPHost.path.""" 
     99 
     100    def test_isdir_isfile_islink(self): 
     101        """Test FTPHost._Path.isdir/isfile/islink.""" 
     102        testdir = '/home/sschwarzer' 
     103        host = FTPHostWrapper(_mock_ftplib.MockSession) 
     104        host.chdir(testdir) 
     105        # test a path which isn't there 
     106        self.failIf( host.path.isdir('notthere') ) 
     107        self.failIf( host.path.isfile('notthere') ) 
     108        self.failIf( host.path.islink('notthere') ) 
     109        # test a directory 
     110        self.failUnless( host.path.isdir(testdir) ) 
     111        self.failIf( host.path.isfile(testdir) ) 
     112        self.failIf( host.path.islink(testdir) ) 
     113        # test a file 
     114        testfile = '/home/sschwarzer/index.html' 
     115        self.failIf( host.path.isdir(testfile) ) 
     116        self.failUnless( host.path.isfile(testfile) ) 
     117        self.failIf( host.path.islink(testfile) ) 
     118        # test a link 
     119        testlink = '/home/sschwarzer/osup' 
     120        # uncomment these two when following links is implemented 
     121        #self.failIf( host.path.isdir(testlink) ) 
     122        #self.failIf( host.path.isfile(testlink) ) 
     123        self.failUnless( host.path.islink(testlink) ) 
     124 
     125 
    165126# class TestFileOperations(Base): 
    166127#     """