Changeset 1839:08106f3051f1


Ignore:
Timestamp:
Jul 11, 2019, 9:58:46 PM (3 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Use `ScriptedSession` in `TestListdir`
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_stat.py

    r1838 r1839  
    779779    """Test `FTPHost.listdir`."""
    780780
    781     def setup_method(self, method):
    782         self.stat = \
    783           _test_stat(session_factory=mock_ftplib.MockUnixFormatSession)
    784 
    785781    def test_failing_listdir(self):
    786782        """Test failing `FTPHost.listdir`."""
    787         with pytest.raises(ftputil.error.PermanentError):
    788             self.stat._listdir("notthere")
     783        script = [
     784          Call("__init__"),
     785          Call("pwd", result="/"),
     786          Call("cwd", args=("/",)),
     787          Call("cwd", args=("/",)),
     788          Call("dir", args=("",), result=""),
     789          Call("cwd", args=("/",)),
     790          Call("close")
     791        ]
     792        with test_base.ftp_host_factory(scripted_session.factory(script)) as host:
     793            host.stat_cache.disable()
     794            with pytest.raises(ftputil.error.PermanentError):
     795                host.listdir("notthere")
    789796
    790797    def test_succeeding_listdir(self):
    791798        """Test succeeding `FTPHost.listdir`."""
    792         # Do we have all expected "files"?
    793         assert len(self.stat._listdir(".")) == 9
    794         # Have they the expected names?
    795         expected = ("chemeng download image index.html os2 "
    796                     "osup publications python scios2").split()
    797         remote_file_list = self.stat._listdir(".")
    798         for file in expected:
    799             assert file in remote_file_list
     799        script = [
     800          Call("__init__"),
     801          Call("pwd", result="/"),
     802          Call("cwd", args=("/",)),
     803          Call("cwd", args=("/",)),
     804          Call("dir",
     805               args=("",),
     806               result=
     807                 "drwxr-sr-x   2 45854   200    512 Jan  3 17:17 download\n"
     808                 "drwxr-sr-x   2 45854   200    512 Jul 30 17:14 dir with spaces\n"
     809                 "lrwxrwxrwx   2 45854   200      6 May 29  2000 link -> ../link_target\n"
     810                 "-rw-r--r--   1 45854   200   4604 Jan 19 23:11 index.html"),
     811          Call("cwd", args=("/",)),
     812          Call("close")
     813        ]
     814        with test_base.ftp_host_factory(scripted_session.factory(script)) as host:
     815            host.stat_cache.disable()
     816            remote_file_list = host.listdir(".")
     817            # Do we have all expected "files"?
     818            assert len(remote_file_list) == 4
     819            expected_names = ["download", "dir with spaces", "link", "index.html"]
     820            for name in expected_names:
     821                assert name in remote_file_list
Note: See TracChangeset for help on using the changeset viewer.