Changeset 1677:b4c9b089b6b8


Ignore:
Timestamp:
Oct 28, 2017, 7:17:42 PM (14 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Apply `normpath` when getting the working directory

When getting the current working directory of the FTP session, apply
`normpath`. This makes sure that an initial `FTPHost.getcwd` call
returns the current working without a trailing slash (with the
exception of the current directory being `/`).

ticket: 113
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ftputil/host.py

    r1676 r1677  
    7878        with ftputil.error.ftplib_error_to_ftp_os_error:
    7979            self._cached_current_dir = \
    80               ftputil.tool.as_unicode(self._session.pwd())
     80              self.path.normpath(ftputil.tool.as_unicode(self._session.pwd()))
    8181        # Associated `FTPHost` objects for data transfer.
    8282        self._children = []
  • test/test_host.py

    r1663 r1677  
    7171        if not hasattr(self, "pwd_called"):
    7272            self.pwd_called = True
     73            return "/home"
    7374        else:
    7475            raise ftplib.error_temp
     76
     77
     78class UnnormalizedCurrentWorkingDirectory(mock_ftplib.MockSession):
     79
     80    def pwd(self):
     81        # Deliberately return the current working directory with a
     82        # trailing slash to test if it's removed when stored in the
     83        # `FTPHost` instance.
     84        return "/home/"
    7585
    7686
     
    159169# Test cases
    160170#
    161 class TestInitAndClose(object):
    162     """Test initialization and closure of `FTPHost` objects."""
     171class TestConstructor(object):
     172    """
     173    Test initialization of `FTPHost` objects.
     174    """
    163175
    164176    def test_open_and_close(self):
     177        """
     178        Test if opening and closing an `FTPHost` object works as
     179        expected.
     180        """
    165181        host = test_base.ftp_host_factory()
    166182        host.close()
     
    168184        assert host._children == []
    169185
    170 
    171 class TestLogin(object):
    172 
    173186    def test_invalid_login(self):
    174187        """Login to invalid host must fail."""
    175188        with pytest.raises(ftputil.error.FTPOSError):
    176189            test_base.ftp_host_factory(FailOnLoginSession)
     190
     191    def test_pwd_normalization(self):
     192        """
     193        Test if the stored current directory is normalized.
     194        """
     195        host = test_base.ftp_host_factory(UnnormalizedCurrentWorkingDirectory)
     196        assert host.getcwd() == "/home"
    177197
    178198
Note: See TracChangeset for help on using the changeset viewer.