Changeset 713

Show
Ignore:
Timestamp:
2007-07-22 12:39:10 (1 year ago)
Author:
schwa
Message:
Added test code and applied a fix for a failing `makedirs` called from
a non-root directory. Issue and fix suggestion are by Julian (ticket
#22, http://ftputil.sschwarzer.net/trac/ticket/22 ).
Files:

Legend:

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

    r704 r713  
    127127    def test_makedirs_without_existing_dirs(self): 
    128128        host = self.host 
    129         # no `dir1` yet 
     129        # no `_dir1_` yet 
    130130        self.failIf('_dir1_' in host.listdir(host.curdir)) 
    131131        # vanilla case, all should go well 
     
    141141        host.rmdir('_dir1_/dir2') 
    142142        host.rmdir('_dir1_') 
     143 
     144    def test_makedirs_from_not_root_directory(self): 
     145        # this is a testcase for issue #22, see 
     146        #  http://ftputil.sschwarzer.net/trac/ticket/22 
     147        host = self.host 
     148        # no `_dir1_` and `_dir2_` yet 
     149        self.failIf('_dir1_' in host.listdir(host.curdir)) 
     150        self.failIf('_dir2_' in host.listdir(host.curdir)) 
     151        # part 1: try to make directories starting from `_dir1_` 
     152        # make and change to non-root directory 
     153        host.mkdir('_dir1_') 
     154        host.chdir('_dir1_') 
     155        host.makedirs('_dir2_/_dir3_') 
     156        # test for expected directory hierarchy 
     157        self.failUnless(host.path.isdir('/_dir1_')) 
     158        self.failUnless(host.path.isdir('/_dir1_/_dir2_')) 
     159        self.failUnless(host.path.isdir('/_dir1_/_dir2_/_dir3_')) 
     160        self.failIf(host.path.isdir('/_dir1_/_dir1_')) 
     161        # remove all but the directory were in 
     162        host.rmdir('/_dir1_/_dir2_/_dir3_') 
     163        host.rmdir('/_dir1_/_dir2_') 
     164        # part 2: try to make directories starting from root 
     165        host.makedirs('/_dir2_/_dir3_') 
     166        # test for expected directory hierarchy 
     167        self.failUnless(host.path.isdir('/_dir2_')) 
     168        self.failUnless(host.path.isdir('/_dir2_/_dir3_')) 
     169        self.failIf(host.path.isdir('/_dir1_/_dir2_')) 
     170        # clean up 
     171        host.rmdir('/_dir2_/_dir3_') 
     172        host.rmdir('/_dir2_') 
     173        host.chdir(host.pardir) 
     174        host.rmdir('/_dir1_') 
    143175 
    144176    def test_makedirs_of_existing_directory(self): 
  • trunk/ftputil.py

    r698 r713  
    413413        """ 
    414414        Copy a file from source to target. Which of both is a local 
    415         or a remote file, repectively, is determined by the arguments. 
     415        or a remote file, respectively, is determined by the arguments. 
    416416        """ 
    417417        source_mode, target_mode = self.__get_modes(mode) 
     
    609609        #  the "lowermost" directory 
    610610        for index in range(1, len(directories)): 
    611             next_directory = self.path.join(*directories[:index+1]) 
     611            # re-insert the separator which got lost by using `path.split` 
     612            next_directory = os.sep + self.path.join(*directories[:index+1]) 
    612613            try: 
    613614                self.mkdir(next_directory)