Changeset 1804:88d20a857d6d


Ignore:
Timestamp:
Jun 17, 2019, 5:14:06 PM (2 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Move helper class `_Path`

Move helper mock class `_Path` to class level of `TestTimeShift` to
make `_Path` usable for multiple test methods.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_host.py

    r1803 r1804  
    590590class TestTimeShift:
    591591
     592    # Helper mock class that frees us from setting up complicated
     593    # session scripts for the remote calls.
     594    class _Path:
     595        def split(self, path):
     596            return posixpath.split(path)
     597        def set_mtime(self, mtime):
     598            self._mtime = mtime
     599        def getmtime(self, file_name):
     600            return self._mtime
     601        def join(self, *args):
     602            return posixpath.join(*args)
     603        def normpath(self, path):
     604            return posixpath.normpath(path)
     605        def isabs(self, path):
     606            return posixpath.isabs(path)
     607        def abspath(self, path):
     608            return "/_ftputil_sync_"
     609        # Needed for `isdir` in `FTPHost.remove`
     610        def isfile(self, path):
     611            return True
     612
    592613    def test_rounded_time_shift(self):
    593614        """Test if time shift is rounded correctly."""
     
    649670    def test_synchronize_times(self):
    650671        """Test time synchronization with server."""
    651         # Helper mock class that frees us from setting up complicated
    652         # session scripts for the remote calls.
    653         class _Path:
    654             def split(self, path):
    655                 return posixpath.split(path)
    656             def set_mtime(self, mtime):
    657                 self._mtime = mtime
    658             def getmtime(self, file_name):
    659                 return self._mtime
    660             def join(self, *args):
    661                 return posixpath.join(*args)
    662             def normpath(self, path):
    663                 return posixpath.normpath(path)
    664             def isabs(self, path):
    665                 return posixpath.isabs(path)
    666             def abspath(self, path):
    667                 return "/_ftputil_sync_"
    668             # Needed for `isdir` in `FTPHost.remove`
    669             def isfile(self, path):
    670                 return True
    671         #
    672672        Call = scripted_session.Call
    673673        host_script = [
     
    707707                                                            file_script)
    708708            with test_base.ftp_host_factory(multisession_factory) as host:
    709                 host.path = _Path()
     709                host.path = self._Path()
    710710                host.path.set_mtime(time.time() + measured_time_shift)
    711711                host.synchronize_times()
     
    722722                                                            file_script)
    723723            with test_base.ftp_host_factory(multisession_factory) as host:
    724                 host.path = _Path()
     724                host.path = self._Path()
    725725                host.path.set_mtime(time.time() + measured_time_shift)
    726726                with pytest.raises(ftputil.error.TimeShiftError):
Note: See TracChangeset for help on using the changeset viewer.