Changeset 1807:65b79d35761d


Ignore:
Timestamp:
Jun 17, 2019, 10:09:53 PM (4 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Define `Call` on module level

Create a reference `Call` to `scripted_session.Call` on the module
level, so that not every test method has to create a local reference.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_host.py

    r1806 r1807  
    2626from test import test_base
    2727import test.scripted_session as scripted_session
     28
     29
     30Call = scripted_session.Call
    2831
    2932
     
    128131        """
    129132        script = [
    130           scripted_session.Call(method_name="__init__", result=None),
    131           scripted_session.Call(method_name="pwd", result="/"),
    132           scripted_session.Call(method_name="close")
     133          Call(method_name="__init__", result=None),
     134          Call(method_name="pwd", result="/"),
     135          Call(method_name="close")
    133136        ]
    134137        host = test_base.ftp_host_factory(scripted_session.factory(script))
     
    140143        """Login to invalid host must fail."""
    141144        script = [
    142           scripted_session.Call(method_name="__init__", result=ftplib.error_perm),
    143           scripted_session.Call(method_name="pwd", result="/"),
     145          Call(method_name="__init__", result=ftplib.error_perm),
     146          Call(method_name="pwd", result="/"),
    144147        ]
    145148        with pytest.raises(ftputil.error.FTPOSError):
     
    151154        """
    152155        script = [
    153           scripted_session.Call(method_name="__init__", result=None),
     156          Call(method_name="__init__", result=None),
    154157          # Deliberately return the current working directory with a
    155158          # trailing slash to test if it's removed when stored in the
    156159          # `FTPHost` instance.
    157           scripted_session.Call(method_name="pwd", result="/home/")
     160          Call(method_name="pwd", result="/home/")
    158161        ]
    159162        host = test_base.ftp_host_factory(scripted_session.factory(script))
     
    171174        """Assume the connection has timed out, so `keep_alive` fails."""
    172175        script = [
    173           scripted_session.Call(method_name="__init__", result=None),
    174           scripted_session.Call(method_name="pwd", result="/home"),
     176          Call(method_name="__init__", result=None),
     177          Call(method_name="pwd", result="/home"),
    175178          # Simulate failing `pwd` call after the server closed the connection
    176179          # due to a session timeout.
    177           scripted_session.Call(method_name="pwd", result=ftplib.error_temp),
     180          Call(method_name="pwd", result=ftplib.error_temp),
    178181        ]
    179182        host = test_base.ftp_host_factory(scripted_session.factory(script))
     
    205208    def test_set_parser(self):
    206209        """Test if the selected parser is used."""
    207         Call = scripted_session.Call
    208210        script = [
    209211          Call(method_name="__init__", result=None),
     
    231233        implemented by the server.
    232234        """
    233         Call = scripted_session.Call
    234235        script = [
    235236          Call(method_name="__init__"),
     
    271272        `session.dir` unmodified.
    272273        """
    273         Call = scripted_session.Call
    274274        script = [
    275275          Call(method_name="__init__"),
     
    293293        an empty string.
    294294        """
    295         Call = scripted_session.Call
    296295        dir_result = """\
    297296total 10
     
    326325    def test_download(self):
    327326        """Test mode download."""
    328         Call = scripted_session.Call
    329327        remote_file_name = "dummy_name"
    330328        remote_file_content = b"dummy_content"
     
    370368        If the target file is newer, no upload should happen.
    371369        """
    372         Call = scripted_session.Call
    373370        local_source = "_test_source_"
    374371        data = binary_data()
     
    402399        should be uploaded.
    403400        """
    404         Call = scripted_session.Call
    405401        file_content = b"dummy_content"
    406402        local_source = "_test_source_"
     
    475471        data = binary_data()
    476472        # Target does not exist, so download.
    477         Call = scripted_session.Call
    478473        #  There isn't a `dir` call to compare the datetimes of the
    479474        #  remote and the target file because the local `exists` call
     
    512507        data = binary_data()
    513508        # Target is older, so download.
    514         Call = scripted_session.Call
    515509        #  Use a date in the future. That isn't realistic, but for the
    516510        #  purpose of the test it's an easy way to make sure the source
     
    555549            pass
    556550        data = binary_data()
    557         Call = scripted_session.Call
    558551        # Use date in the past, so the target file is newer and no
    559552        # download happens.
     
    613606    def test_rounded_time_shift(self):
    614607        """Test if time shift is rounded correctly."""
    615         Call = scripted_session.Call
    616608        script = [
    617609          Call("__init__"),
     
    642634    def test_assert_valid_time_shift(self):
    643635        """Test time shift sanity checks."""
    644         Call = scripted_session.Call
    645636        script = [
    646637          Call("__init__"),
     
    670661    def test_synchronize_times(self):
    671662        """Test time synchronization with server."""
    672         Call = scripted_session.Call
    673663        host_script = [
    674664          Call("__init__"),
     
    729719    def test_synchronize_times_for_server_in_east(self):
    730720        """Test for timestamp correction (see ticket #55)."""
    731         Call = scripted_session.Call
    732721        host_script = [
    733722          Call("__init__"),
     
    783772    def test_upload(self):
    784773        """Test whether `upload` accepts either unicode or bytes."""
    785         Call = scripted_session.Call
    786774        host_script = [
    787775          Call("__init__"),
     
    814802    def test_download(self):
    815803        """Test whether `download` accepts either unicode or bytes."""
    816         Call = scripted_session.Call
    817804        host_script = [
    818805          Call("__init__"),
     
    847834    def test_rename(self):
    848835        """Test whether `rename` accepts either unicode or bytes."""
    849         Call = scripted_session.Call
    850836        script = [
    851837          Call("__init__"),
     
    867853        """Test whether `listdir` accepts either unicode or bytes."""
    868854        as_bytes = ftputil.tool.as_bytes
    869         Call = scripted_session.Call
    870855        top_level_dir_line = test_base.dir_line(mode_string="drwxr-xr-x",
    871856                                                date_=datetime.date.today(),
     
    904889    def test_chmod(self):
    905890        """Test whether `chmod` accepts either unicode or bytes."""
    906         Call = scripted_session.Call
    907891        script = [
    908892          Call("__init__"),
     
    938922    def test_chdir(self):
    939923        """Test whether `chdir` accepts either unicode or bytes."""
    940         Call = scripted_session.Call
    941924        script = [
    942925          Call("__init__"),
     
    949932    def test_mkdir(self):
    950933        """Test whether `mkdir` accepts either unicode or bytes."""
    951         Call = scripted_session.Call
    952934        script = [
    953935          Call("__init__"),
     
    963945    def test_makedirs(self):
    964946        """Test whether `makedirs` accepts either unicode or bytes."""
    965         Call = scripted_session.Call
    966947        script = [
    967948          Call("__init__"),
     
    980961    def test_rmdir(self):
    981962        """Test whether `rmdir` accepts either unicode or bytes."""
    982         Call = scripted_session.Call
    983963        dir_line = test_base.dir_line(mode_string="drwxr-xr-x",
    984964                                      date_=datetime.date.today(),
     
    10321012    def test_remove(self):
    10331013        """Test whether `remove` accepts either unicode or bytes."""
    1034         Call = scripted_session.Call
    10351014        dir_line = test_base.dir_line(mode_string="-rw-r--r--",
    10361015                                      date_=datetime.date.today(),
     
    10531032    def test_rmtree(self):
    10541033        """Test whether `rmtree` accepts either unicode or bytes."""
    1055         Call = scripted_session.Call
    10561034        dir_line = test_base.dir_line(mode_string="drwxr-xr-x",
    10571035                                      date_=datetime.date.today(),
     
    10891067    def test_lstat(self):
    10901068        """Test whether `lstat` accepts either unicode or bytes."""
    1091         Call = scripted_session.Call
    10921069        dir_line = test_base.dir_line(mode_string="-rw-r--r--",
    10931070                                      date_=datetime.date.today(),
     
    11061083    def test_stat(self):
    11071084        """Test whether `stat` accepts either unicode or bytes."""
    1108         Call = scripted_session.Call
    11091085        dir_line = test_base.dir_line(mode_string="-rw-r--r--",
    11101086                                      date_=datetime.date.today(),
     
    11231099    def test_walk(self):
    11241100        """Test whether `walk` accepts either unicode or bytes."""
    1125         Call = scripted_session.Call
    11261101        dir_line = test_base.dir_line(mode_string="-rw-r--r--",
    11271102                                      date_=datetime.date.today(),
Note: See TracChangeset for help on using the changeset viewer.