Changeset 1599:4dd8b4d6aba7


Ignore:
Timestamp:
Nov 1, 2015, 9:46:44 PM (6 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Add `FTPHost.listdir` tests for ticket #100

Other methods that take directory or file names have the same issues
as described in the ticket, but at the moment only `listdir` calls
are tested.

There's already a test for non-ASCII file names in `test.test_host`,
but that didn't catch the problem because the mock code in
`test.mock_ftplib` hid the problem.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_real_ftp.py

    r1564 r1599  
    11# encoding: UTF-8
    22
    3 # Copyright (C) 2003-2013, Stefan Schwarzer <sschwarzer@sschwarzer.net>
     3# Copyright (C) 2003-2015, Stefan Schwarzer <sschwarzer@sschwarzer.net>
    44# and ftputil contributors (see `doc/contributors.txt`)
    55# See the file LICENSE for licensing terms.
     
    785785
    786786    def test_subsequent_reading(self):
    787         # Opening a file for reading
     787        # Open a file for reading.
    788788        with self.host.open("debian-keyring.tar.gz", "rb") as file1:
    789789            pass
     
    828828        bytes_file_name = FILE_NAME.encode("UTF-8")
    829829        self.cleaner.add_file(bytes_file_name)
    830         # Write under name `bytes_file_name`
     830        # Write under name `bytes_file_name`. The content is rather
     831        # irrelevant.
    831832        with host.open(bytes_file_name, "w", encoding="UTF-8") as fobj:
    832833            fobj.write(FILE_NAME)
     
    846847        self.assertEqual(data, FILE_NAME)
    847848
     849    def test_listdir_with_non_ascii_byte_string(self):
     850        """
     851        `listdir` should accept byte strings with non-ASCII
     852        characters and return non-ASCII characters in directory or
     853        file names.
     854        """
     855        host = self.host
     856        path = "äbc".encode("UTF-8")
     857        names = host.listdir(path)
     858        self.assertEqual(names[0], b"file1")
     859        self.assertEqual(names[1], "file1_ö".encode("UTF-8"))
     860
     861    def test_listdir_with_non_ascii_unicode_string(self):
     862        """
     863        `listdir` should accept unicode strings with non-ASCII
     864        characters and return non-ASCII characters in directory or
     865        file names.
     866        """
     867        host = self.host
     868        # `ftplib` under Python 3 only works correctly if the unicode
     869        # strings are decoded from latin1. Under Python 2, ftputil
     870        # is supposed to provide a compatible interface.
     871        path = "äbc".encode("UTF-8").decode("latin1")
     872        names = host.listdir(path)
     873        self.assertEqual(names[0], "file1")
     874        self.assertEqual(names[1], "file1_ö".encode("UTF-8").decode("latin1"))
     875
    848876    def test_list_a_option(self):
    849877        # For this test to pass, the server must _not_ list "hidden"
Note: See TracChangeset for help on using the changeset viewer.