Changeset 1805:afdbffb32f8d


Ignore:
Timestamp:
Jun 17, 2019, 5:29:14 PM (4 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Use `ScriptedSession` in `test_synchronize_times_for_server_in_east`
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_host.py

    r1804 r1805  
    729729    def test_synchronize_times_for_server_in_east(self):
    730730        """Test for timestamp correction (see ticket #55)."""
    731         host = test_base.ftp_host_factory(ftp_host_class=TimeShiftFTPHost,
    732                                           session_factory=TimeShiftMockSession)
    733         # Set this explicitly to emphasize the problem.
    734         host.set_time_shift(0.0)
    735         hour = 60 * 60
    736         # This could be any negative time shift.
    737         presumed_time_shift = -6 * hour
    738         # Set `mtime` to simulate a server east of us.
    739         # In case the `time_shift` value for this host instance is 0.0
    740         # (as is to be expected before the time shift is determined),
    741         # the directory parser (more specifically
    742         # `ftputil.stat.Parser.parse_unix_time`) will return a time which
    743         # is a year too far in the past. The `synchronize_times`
    744         # method needs to deal with this and add the year "back".
    745         # I don't think it's a bug in `parse_unix_time` because the
    746         # method should work once the time shift is set correctly.
    747         local_time = time.localtime()
    748         local_time_with_wrong_year = (local_time.tm_year-1,) + local_time[1:]
    749         presumed_server_time = \
    750           time.mktime(local_time_with_wrong_year) + presumed_time_shift
    751         host.path.set_mtime(presumed_server_time)
    752         host.synchronize_times()
    753         assert host.time_shift() == presumed_time_shift
     731        Call = scripted_session.Call
     732        host_script = [
     733          Call("__init__"),
     734          Call(method_name="pwd", result="/"),
     735          Call(method_name="cwd", result=None, args=("/",)),
     736          Call(method_name="cwd", result=None, args=("/",)),
     737          Call(method_name="delete", result=None, args=("_ftputil_sync_",)),
     738          Call(method_name="cwd", result=None, args=("/",)),
     739          Call(method_name="close"),
     740        ]
     741        file_script = [
     742          Call("__init__"),
     743          Call(method_name="pwd", result="/"),
     744          Call(method_name="cwd", result=None, args=("/",)),
     745          Call(method_name="voidcmd", result=None, args=("TYPE I",)),
     746          Call(method_name="transfercmd", result=io.BytesIO(),
     747               args=("STOR _ftputil_sync_", None)),
     748          Call(method_name="voidresp", result=None, args=()),
     749          Call(method_name="close"),
     750        ]
     751        multisession_factory = scripted_session.factory(host_script, file_script)
     752        with test_base.ftp_host_factory(session_factory=multisession_factory) as host:
     753            host.path = self._Path()
     754            # Set this explicitly to emphasize the problem.
     755            host.set_time_shift(0.0)
     756            hour = 60 * 60
     757            # This could be any negative time shift.
     758            presumed_time_shift = -6 * hour
     759            # Set `mtime` to simulate a server east of us.
     760            # In case the `time_shift` value for this host instance is 0.0
     761            # (as is to be expected before the time shift is determined),
     762            # the directory parser (more specifically
     763            # `ftputil.stat.Parser.parse_unix_time`) will return a time which
     764            # is a year too far in the past. The `synchronize_times`
     765            # method needs to deal with this and add the year "back".
     766            # I don't think it's a bug in `parse_unix_time` because the
     767            # method should work once the time shift is set correctly.
     768            local_time = time.localtime()
     769            local_time_with_wrong_year = (local_time.tm_year-1,) + local_time[1:]
     770            presumed_server_time = \
     771              time.mktime(local_time_with_wrong_year) + presumed_time_shift
     772            host.path.set_mtime(presumed_server_time)
     773            host.synchronize_times()
     774            assert host.time_shift() == presumed_time_shift
    754775
    755776
Note: See TracChangeset for help on using the changeset viewer.