Changeset 265

Show
Ignore:
Timestamp:
2003-06-09 19:17:15 (6 years ago)
Author:
schwa
Message:
Moved tests for `lstat` and `stat` from `_test_ftputil.py` to
    `_test_ftp_stat.py`.
Files:

Legend:

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

    r258 r265  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 
    32 # $Id: _test_ftp_stat.py,v 1.3 2003/06/09 18:16:45 schwa Exp $ 
     32# $Id: _test_ftp_stat.py,v 1.4 2003/06/09 19:17:15 schwa Exp $ 
    3333 
     34import stat 
    3435import unittest 
    3536 
     37import _test_base 
    3638import ftp_error 
    3739import ftp_stat 
     40import ftputil 
    3841 
    3942 
     
    103106 
    104107 
     108class TestLstatAndStat(unittest.TestCase): 
     109    """ 
     110    Test `FTPHost.lstat` and `FTPHost.stat` (test currently only 
     111    implemented for Unix server format). 
     112    """ 
     113 
     114    def test_failing_lstat(self): 
     115        """Test whether lstat fails for a nonexistent path.""" 
     116        host = _test_base.ftp_host_factory() 
     117        self.assertRaises(ftputil.PermanentError, host.lstat, 
     118                          '/home/sschw/notthere') 
     119        self.assertRaises(ftputil.PermanentError, host.lstat, 
     120                          '/home/sschwarzer/notthere') 
     121 
     122    def test_lstat_for_root(self): 
     123        """Test `lstat` for `/` . 
     124        Note: `(l)stat` works by going one directory up and parsing 
     125        the output of an FTP `DIR` command. Unfortunately, it is not 
     126        possible to to this for the root directory `/`. 
     127        """ 
     128        host = _test_base.ftp_host_factory() 
     129        self.assertRaises(ftputil.RootDirError, host.lstat, '/') 
     130        try: 
     131            host.lstat('/') 
     132        except ftputil.RootDirError, exc_obj: 
     133            self.failIf( isinstance(exc_obj, ftputil.FTPOSError) ) 
     134 
     135    def test_lstat_one_file(self): 
     136        """Test `lstat` for a file.""" 
     137        host = _test_base.ftp_host_factory() 
     138        stat_result = host.lstat('/home/sschwarzer/index.html') 
     139        self.assertEqual( oct(stat_result.st_mode), '0100644' ) 
     140        self.assertEqual(stat_result.st_size, 4604) 
     141 
     142    def test_lstat_one_dir(self): 
     143        """Test `lstat` for a directory.""" 
     144        host = _test_base.ftp_host_factory() 
     145        stat_result = host.lstat('/home/sschwarzer/scios2') 
     146        self.assertEqual( oct(stat_result.st_mode), '042755' ) 
     147        self.assertEqual(stat_result.st_ino, None) 
     148        self.assertEqual(stat_result.st_dev, None) 
     149        self.assertEqual(stat_result.st_nlink, 6) 
     150        self.assertEqual(stat_result.st_uid, '45854') 
     151        self.assertEqual(stat_result.st_gid, '200') 
     152        self.assertEqual(stat_result.st_size, 512) 
     153        self.assertEqual(stat_result.st_atime, None) 
     154        # The comparison with the value 937785600.0 may fail in 
     155        #  some Python environments. It seems that this depends on 
     156        #  how `time.mktime` interprets the dst flag. 
     157        self.failUnless(stat_result.st_mtime == 937785600.0 or 
     158                        stat_result.st_mtime == 937778400.0) 
     159        self.assertEqual(stat_result.st_ctime, None) 
     160        # same here (or similarly) 
     161        self.failUnless( stat_result == (17901, None, None, 6, '45854', '200', 
     162                                         512, None, 937785600.0, None) or 
     163                         stat_result == (17901, None, None, 6, '45854', '200', 
     164                                         512, None, 937778400.0, None) ) 
     165 
     166    def test_lstat_via_stat_module(self): 
     167        """Test `lstat` indirectly via `stat` module.""" 
     168        host = _test_base.ftp_host_factory() 
     169        stat_result = host.lstat('/home/sschwarzer/') 
     170        self.failUnless( stat.S_ISDIR(stat_result.st_mode) ) 
     171 
     172    def test_stat_following_link(self): 
     173        """Test `stat` when invoked on a link.""" 
     174        host = _test_base.ftp_host_factory() 
     175        # simple link 
     176        stat_result = host.stat('/home/link') 
     177        self.assertEqual(stat_result.st_size, 4604) 
     178        # link pointing to a link 
     179        stat_result = host.stat('/home/python/link_link') 
     180        self.assertEqual(stat_result.st_size, 4604) 
     181        stat_result = host.stat('../python/link_link') 
     182        self.assertEqual(stat_result.st_size, 4604) 
     183        # recursive link structures 
     184        self.assertRaises(ftputil.PermanentError, host.stat, 
     185                          '../python/bad_link') 
     186        self.assertRaises(ftputil.PermanentError, host.stat, 
     187                          '/home/bad_link') 
     188 
     189 
    105190if __name__ == '__main__': 
    106191    unittest.main() 
  • trunk/_test_ftputil.py

    r264 r265  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 
    32 # $Id: _test_ftputil.py,v 1.69 2003/06/09 19:14:10 schwa Exp $ 
     32# $Id: _test_ftputil.py,v 1.70 2003/06/09 19:17:15 schwa Exp $ 
    3333 
    3434import operator 
     
    139139        self.assertRaises(ftputil.FTPOSError, _test_base.ftp_host_factory, 
    140140                          FailOnLoginSession) 
    141  
    142  
    143 class TestStat(unittest.TestCase): 
    144     """ 
    145     Test `FTPHost.lstat` and `FTPHost.stat` (test currently only 
    146     implemented for Unix server format). 
    147     """ 
    148  
    149     def test_failing_lstat(self): 
    150         """Test whether lstat fails for a nonexistent path.""" 
    151         host = _test_base.ftp_host_factory() 
    152         self.assertRaises(ftputil.PermanentError, host.lstat, 
    153                           '/home/sschw/notthere') 
    154         self.assertRaises(ftputil.PermanentError, host.lstat, 
    155                           '/home/sschwarzer/notthere') 
    156  
    157     def test_lstat_for_root(self): 
    158         """Test `lstat` for `/` . 
    159         Note: `(l)stat` works by going one directory up and parsing 
    160         the output of an FTP `DIR` command. Unfortunately, it is not 
    161         possible to to this for the root directory `/`. 
    162         """ 
    163         host = _test_base.ftp_host_factory() 
    164         self.assertRaises(ftputil.RootDirError, host.lstat, '/') 
    165         try: 
    166             host.lstat('/') 
    167         except ftputil.RootDirError, exc_obj: 
    168             self.failIf( isinstance(exc_obj, ftputil.FTPOSError) ) 
    169  
    170     def test_lstat_one_file(self): 
    171         """Test `lstat` for a file.""" 
    172         host = _test_base.ftp_host_factory() 
    173         stat_result = host.lstat('/home/sschwarzer/index.html') 
    174         self.assertEqual( oct(stat_result.st_mode), '0100644' ) 
    175         self.assertEqual(stat_result.st_size, 4604) 
    176  
    177     def test_lstat_one_dir(self): 
    178         """Test `lstat` for a directory.""" 
    179         host = _test_base.ftp_host_factory() 
    180         stat_result = host.lstat('/home/sschwarzer/scios2') 
    181         self.assertEqual( oct(stat_result.st_mode), '042755' ) 
    182         self.assertEqual(stat_result.st_ino, None) 
    183         self.assertEqual(stat_result.st_dev, None) 
    184         self.assertEqual(stat_result.st_nlink, 6) 
    185         self.assertEqual(stat_result.st_uid, '45854') 
    186         self.assertEqual(stat_result.st_gid, '200') 
    187         self.assertEqual(stat_result.st_size, 512) 
    188         self.assertEqual(stat_result.st_atime, None) 
    189         # The comparison with the value 937785600.0 may fail in 
    190         #  some Python environments. It seems that this depends on 
    191         #  how `time.mktime` interprets the dst flag. 
    192         self.failUnless(stat_result.st_mtime == 937785600.0 or 
    193                         stat_result.st_mtime == 937778400.0) 
    194         self.assertEqual(stat_result.st_ctime, None) 
    195         # same here (or similarly) 
    196         self.failUnless( stat_result == (17901, None, None, 6, '45854', '200', 
    197                                          512, None, 937785600.0, None) or 
    198                          stat_result == (17901, None, None, 6, '45854', '200', 
    199                                          512, None, 937778400.0, None) ) 
    200  
    201     def test_lstat_via_stat_module(self): 
    202         """Test `lstat` indirectly via `stat` module.""" 
    203         host = _test_base.ftp_host_factory() 
    204         stat_result = host.lstat('/home/sschwarzer/') 
    205         self.failUnless( stat.S_ISDIR(stat_result.st_mode) ) 
    206  
    207     def test_stat_following_link(self): 
    208         """Test `stat` when invoked on a link.""" 
    209         host = _test_base.ftp_host_factory() 
    210         # simple link 
    211         stat_result = host.stat('/home/link') 
    212         self.assertEqual(stat_result.st_size, 4604) 
    213         # link pointing to a link 
    214         stat_result = host.stat('/home/python/link_link') 
    215         self.assertEqual(stat_result.st_size, 4604) 
    216         stat_result = host.stat('../python/link_link') 
    217         self.assertEqual(stat_result.st_size, 4604) 
    218         # recursive link structures 
    219         self.assertRaises(ftputil.PermanentError, host.stat, 
    220                           '../python/bad_link') 
    221         self.assertRaises(ftputil.PermanentError, host.stat, 
    222                           '/home/bad_link') 
    223141 
    224142