Changeset 1809:03b28a125c97


Ignore:
Timestamp:
Jun 17, 2019, 10:18:01 PM (2 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Remove uses of `mock_ftplib`

With all the test cases in `test_host.py` switched to the
`scripted_session` module, `mock_ftplib` is no longer needed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_host.py

    r1808 r1809  
    2323import ftputil.stat
    2424
    25 from test import mock_ftplib
    2625from test import test_base
    2726import test.scripted_session as scripted_session
     
    5958    return random_data(pool)
    6059
    61 
    62 #
    63 # Several customized `MockSession` classes
    64 #
    65 class FailOnLoginSession(mock_ftplib.MockSession):
    66 
    67     def __init__(self, host="", user="", password=""):
    68         raise ftplib.error_perm
    69 
    70 
    71 class BinaryDownloadMockSession(mock_ftplib.MockUnixFormatSession):
    72 
    73     mock_file_content = binary_data()
    74 
    75 
    76 class TimeShiftMockSession(mock_ftplib.MockSession):
    77 
    78     def delete(self, file_name):
    79         pass
    80 
    81 #
    82 # Customized `FTPHost` class for conditional upload/download tests
    83 # and time shift tests
    84 #
    85 class FailingUploadAndDownloadFTPHost(ftputil.FTPHost):
    86 
    87     def upload(self, source, target, mode=""):
    88         pytest.fail("`FTPHost.upload` should not have been called")
    89 
    90     def download(self, source, target, mode=""):
    91         pytest.fail("`FTPHost.download` should not have been called")
    92 
    93 
    94 class TimeShiftFTPHost(ftputil.FTPHost):
    95 
    96     class _Path:
    97         def split(self, path):
    98             return posixpath.split(path)
    99         def set_mtime(self, mtime):
    100             self._mtime = mtime
    101         def getmtime(self, file_name):
    102             return self._mtime
    103         def join(self, *args):
    104             return posixpath.join(*args)
    105         def normpath(self, path):
    106             return posixpath.normpath(path)
    107         def isabs(self, path):
    108             return posixpath.isabs(path)
    109         def abspath(self, path):
    110             return "/home/sschwarzer/_ftputil_sync_"
    111         # Needed for `isdir` in `FTPHost.remove`
    112         def isfile(self, path):
    113             return True
    114 
    115     def __init__(self, *args, **kwargs):
    116         ftputil.FTPHost.__init__(self, *args, **kwargs)
    117         self.path = self._Path()
    11860
    11961#
Note: See TracChangeset for help on using the changeset viewer.