Changeset 1816:c589604f8a4b


Ignore:
Timestamp:
Jun 18, 2019, 6:46:53 PM (4 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Use `ScriptedSession` in `TestHostContextManager`
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_with_statement.py

    r1718 r1816  
    1 # Copyright (C) 2008-2018, Stefan Schwarzer <sschwarzer@sschwarzer.net>
     1# Copyright (C) 2008-2019, Stefan Schwarzer <sschwarzer@sschwarzer.net>
    22# and ftputil contributors (see `doc/contributors.txt`)
    33# See the file LICENSE for licensing terms.
    44
     5import ftplib
    56import pytest
    67
    78import ftputil.error
    89
     10import test.scripted_session as scripted_session
    911from test import test_base
    1012from test.test_file import InaccessibleDirSession, ReadMockSession
    11 from test.test_host import FailOnLoginSession
     13
     14
     15Call = scripted_session.Call
    1216
    1317
     
    2428
    2529    def test_normal_operation(self):
    26         with test_base.ftp_host_factory() as host:
     30        script = [
     31          Call(method_name="__init__"),
     32          Call(method_name="pwd", result="/"),
     33          Call(method_name="close")
     34        ]
     35        with test_base.ftp_host_factory(scripted_session.factory(script)) as host:
    2736            assert host.closed is False
    2837        assert host.closed is True
    2938
    3039    def test_ftputil_exception(self):
     40        script = [
     41          # Since `__init__` raises an exception, `pwd` isn't called. However,
     42          # `close` is called via the context manager.
     43          Call(method_name="__init__", result=ftplib.error_perm),
     44          Call(method_name="close")
     45        ]
    3146        with pytest.raises(ftputil.error.FTPOSError):
    32             with test_base.ftp_host_factory(FailOnLoginSession) as host:
     47            with test_base.ftp_host_factory(scripted_session.factory(script)) as host:
    3348                pass
    3449        # We arrived here, that's fine. Because the `FTPHost` object
     
    3853
    3954    def test_client_code_exception(self):
     55        script = [
     56          Call(method_name="__init__"),
     57          Call(method_name="pwd", result="/"),
     58          Call(method_name="close")
     59        ]
    4060        try:
    41             with test_base.ftp_host_factory() as host:
     61            with test_base.ftp_host_factory(scripted_session.factory(script)) as host:
    4262                assert host.closed is False
    4363                raise ClientCodeException()
Note: See TracChangeset for help on using the changeset viewer.