Changeset 1826:72c0f9a06e12


Ignore:
Timestamp:
Jun 30, 2019, 9:06:47 PM (8 weeks ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
rebase_source:
c177ab52ebc16a798bb93466e1b1c082056086db
Message:
Use `ScriptedSession` in `TestAvailableChild`
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_file.py

    r1825 r1826  
    513513        `exception_class`.
    514514        """
    515         host = test_base.ftp_host_factory()
    516         # Implicitly create a child session.
    517         with host.open("/home/older") as _:
    518             pass
    519         assert len(host._children) == 1
    520         # Make sure reusing the previous child session will fail.
    521         host._children[0]._session.pwd = self._failing_pwd(exception_class)
    522         # Try to create a new file. Since `pwd` now raises an
    523         # exception, a new child session should be created.
    524         with host.open("home/older") as _:
    525             pass
    526         assert len(host._children) == 2
     515        host_script = [
     516          Call("__init__"),
     517          Call("pwd", result="/"),
     518          Call("close")
     519        ]
     520        first_file_script = [
     521          Call("__init__"),
     522          Call("pwd", result="/"),
     523          Call("cwd", args=('/',)),
     524          Call("voidcmd", args=('TYPE I',)),
     525          Call("transfercmd",
     526               args=('RETR dummy1', None),
     527               result=io.StringIO("")),
     528          Call("voidresp"),
     529          # This `pwd` is executed from `FTPHost._available_child`.
     530          Call("pwd", result=exception_class),
     531          Call("close")
     532        ]
     533        second_file_script = [
     534          Call("__init__"),
     535          Call("pwd", result="/"),
     536          Call("cwd", args=('/',)),
     537          Call("voidcmd", args=('TYPE I',)),
     538          Call("transfercmd",
     539               args=('RETR dummy2', None),
     540               result=io.StringIO("")),
     541          Call("voidresp"),
     542          Call("close")
     543        ]
     544        multisession_factory = scripted_session.factory(host_script,
     545                                                        first_file_script,
     546                                                        second_file_script)
     547        with test_base.ftp_host_factory(multisession_factory) as host:
     548            # Implicitly create a child session.
     549            with host.open("/dummy1") as _:
     550                pass
     551            assert len(host._children) == 1
     552            # Try to create a new file. Since `pwd` in
     553            # `FTPHost._available_child` raises an exception, a new
     554            # child session should be created.
     555            with host.open("/dummy2") as _:
     556                pass
     557            assert len(host._children) == 2
    527558
    528559    def test_pwd_with_error_temp(self):
Note: See TracChangeset for help on using the changeset viewer.