Ignore:
Timestamp:
Jul 27, 2013, 2:32:08 PM (6 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Cleaned up `mock_ftplib.py`.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/mock_ftplib.py

    r1224 r1246  
    66`ftplib.py` module. Some code is taken from there.
    77
    8 Not all functionality is implemented, only that what is used to
    9 run the unit tests.
     8Not all functionality is implemented, only what is needed to run the
     9unit tests.
    1010"""
    1111
     
    1919DEBUG = 0
    2020
    21 # Use a global dictionary of the form `{path: mock_file, ...}` to
    22 # make "volatile" mock files accessible. This is used for testing
    23 # the contents of a file after an `FTPHost.upload` call.
     21# Use a global dictionary of the form `{path: `MockFile` object, ...}`
     22# to make "remote" mock files that were generated during a test
     23# accessible. For example, this is used for testing the contents of a
     24# file after an `FTPHost.upload` call.
    2425mock_files = {}
    2526
    2627def content_of(path):
     28    """
     29    Return the data stored in a mock remote file identified by `path`.
     30    """
    2731    return mock_files[path].getvalue()
    2832
     
    3943        global mock_files
    4044        mock_files[path] = self
    41         super(MockFile, self).__init__(content)
     45        self._super = super(MockFile, self)
     46        self._super.__init__(content)
    4247
    4348    def getvalue(self):
    4449        if not self.closed:
    45             return super(MockFile, self).getvalue()
     50            return self._super.getvalue()
    4651        else:
    4752            return self._value_after_close
     
    4954    def close(self):
    5055        if not self.closed:
    51             self._value_after_close = super(MockFile, self).getvalue()
    52         super(MockFile, self).close()
     56            self._value_after_close = self._super.getvalue()
     57        self._super.close()
    5358
    5459
     
    7176        pass
    7277
     78    # Timeout-related methods are used in `FTPFile.close`.
    7379    def gettimeout(self):
    7480        return self._timeout
     
    129135
    130136    def dir(self, *args):
    131         """Provide a callback function for processing each line of
    132         a directory listing. Return nothing.
    133         """
     137        """
     138        Provide a callback function for processing each line of a
     139        directory listing. Return nothing.
     140        """
     141        # The callback comes last in `ftplib.FTP.dir`.
    134142        if isinstance(args[-1], collections.Callable):
     143            # Get `args[-1]` _before_ removing it in the line after.
    135144            callback = args[-1]
    136145            args = args[:-1]
     
    163172        if DEBUG:
    164173            print(cmd)
    165         # Fail if attempting to read from/write to a directory
     174        # Fail if attempting to read from/write to a directory.
    166175        cmd, path = cmd.split()
     176        #  Normalize path for lookup.
    167177        path = self._remove_trailing_slash(path)
    168178        if path in self.dir_contents:
Note: See TracChangeset for help on using the changeset viewer.