Changeset 1749:a72b82f6aeaa


Ignore:
Timestamp:
Jan 1, 2019, 2:05:23 PM (3 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Convert more tests to use `ScriptedSession`
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_host.py

    r1746 r1749  
    6060    def __init__(self, host="", user="", password=""):
    6161        raise ftplib.error_perm
    62 
    63 
    64 class FailOnKeepAliveSession(mock_ftplib.MockSession):
    65 
    66     def pwd(self):
    67         # Raise exception on second call to let the constructor work.
    68         if not hasattr(self, "pwd_called"):
    69             self.pwd_called = True
    70             return "/home"
    71         else:
    72             raise ftplib.error_temp
    7362
    7463
     
    210199    def test_failing_keep_alive(self):
    211200        """Assume the connection has timed out, so `keep_alive` fails."""
    212         host = test_base.ftp_host_factory(
    213                  session_factory=FailOnKeepAliveSession)
     201        script = [
     202          scripted_session.Call(method_name="__init__", result=None),
     203          scripted_session.Call(method_name="pwd", result="/home"),
     204          # Simulate failing `pwd` call after the server closed the connection
     205          # due to a session timeout.
     206          scripted_session.Call(method_name="pwd", result=ftplib.error_temp),
     207        ]
     208        host = test_base.ftp_host_factory(scripted_session.factory(script))
    214209        with pytest.raises(ftputil.error.TemporaryError):
    215210            host.keep_alive()
     
    239234    def test_set_parser(self):
    240235        """Test if the selected parser is used."""
    241         host = test_base.ftp_host_factory()
     236        script = [
     237          scripted_session.Call(method_name="__init__", result=None),
     238          scripted_session.Call(method_name="pwd", result="/"),
     239          scripted_session.Call(method_name="cwd", result=None, expected_args=("/",)),
     240          scripted_session.Call(method_name="cwd", result=None, expected_args=("/",)),
     241          scripted_session.Call(
     242            method_name="dir",
     243            result="drwxr-xr-x   2 45854    200           512 May  4  2000 home"),
     244          scripted_session.Call(method_name="cwd", result=None, expected_args=("/",))
     245        ]
     246        host = test_base.ftp_host_factory(scripted_session.factory(script))
    242247        assert host._stat._allow_parser_switching is True
    243248        trivial_parser = TestSetParser.TrivialParser()
Note: See TracChangeset for help on using the changeset viewer.