Changeset 1927:81bbc72efc93


Ignore:
Timestamp:
Apr 11, 2020, 7:49:06 PM (16 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
histedit_source:
ded381d3fb8264772be91d5ed46a566dde9c0b24
Message:
Adapt test to new definition of time shift

The time shift is still server time minus client time, but the client
time is expressed in UTC. A time shift of 0.0 means that the
timestamps returned by the server are also in UTC.

ticket: 134
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_real_ftp.py

    r1911 r1927  
    1 # Copyright (C) 2003-2018, Stefan Schwarzer <sschwarzer@sschwarzer.net>
     1# Copyright (C) 2003-2020, Stefan Schwarzer <sschwarzer@sschwarzer.net>
    22# and ftputil contributors (see `doc/contributors.txt`)
    33# See the file LICENSE for licensing terms.
    44
    5 # Execute tests on a real FTP server (other tests use a mock server).
     5# Execute tests on a real FTP server (other tests use mock code).
    66#
    77# This test writes some files and directories on the local client and
     
    1010# timezone calculation.
    1111
     12import datetime
    1213import ftplib
    1314import functools
     
    452453        assert not host.path.islink(file_name)
    453454        assert host.path.getsize(file_name) == 9
    454         # - file's modification time; allow up to two minutes difference
     455        # - file's modification time
    455456        host.synchronize_times()
     457        #  The returned server mtime is supposed to be converted to UTC, so
     458        #  there should be only a small difference between server and client
     459        #  time. Arbitrarily allow two minutes here to account for limited time
     460        #  precision from parsing the directory.
    456461        server_mtime = host.path.getmtime(file_name)
    457         client_mtime = time.mktime(time.localtime())
    458         calculated_time_shift = server_mtime - client_mtime
    459         assert not abs(calculated_time_shift - host.time_shift()) > 120
     462        client_mtime = (
     463            datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp()
     464        )
     465        assert not (client_mtime - server_mtime > 120)
    460466
    461467    def test_issomething_for_nonexistent_directory(self):
Note: See TracChangeset for help on using the changeset viewer.