Changeset 1284:25228b207849


Ignore:
Timestamp:
Jul 28, 2013, 4:06:29 PM (6 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Added tests for string type handling for `chdir` and `listdir`.

TODO: A bytes argument for `listdir` doesn't work yet.

TODO: String type tests for `path.join` and `path.split*`.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ftputil/host.py

    r1278 r1284  
    576576    def chdir(self, path):
    577577        """Change the directory on the host."""
    578         # Fail early if we get a unicode path which can't be encoded.
    579         path = str(path)
     578        path = ftputil.tool.as_bytes(path)
    580579        with ftputil.error.ftplib_error_to_ftp_os_error:
    581580            self._session.cwd(path)
  • test/mock_ftplib.py

    r1274 r1284  
    1717import ftplib
    1818import posixpath
     19
     20import ftputil.tool
     21
    1922
    2023DEBUG = 0
     
    133136
    134137    def cwd(self, path):
     138        path = ftputil.tool.as_unicode(path)
    135139        self.current_dir = self._transform_path(path)
    136140
     
    232236lrwxrwxrwx   2 45854    200             6 May 29  2000 ü -> ä""",
    233237
     238      '/home/file_name_test/ä': """\
     239-rw-r--r--   1 45854    200          4604 Jan 19 23:11 ö
     240-rw-r--r--   1 45854    200          4604 Jan 19 23:11 o""",
     241
    234242      # Fail when trying to write to this directory (the content isn't
    235243      # relevant).
  • test/test_ftputil.py

    r1270 r1284  
     1# encoding: utf-8
    12# Copyright (C) 2002-2013, Stefan Schwarzer <sschwarzer@sschwarzer.net>
    23# See the file LICENSE for licensing terms.
     
    467468
    468469
     470class TestAcceptEitherBytesOrUnicode(unittest.TestCase):
     471
     472    def setUp(self):
     473        self.host = test_base.ftp_host_factory()
     474
     475    def test_string_types_for_chdir(self):
     476        self.host.chdir("/home/file_name_test/ö")
     477        self.host.chdir(ftputil.tool.as_bytes("/home/file_name_test/ö"))
     478
     479    def test_string_types_for_listdir(self):
     480        host = self.host
     481        as_bytes = ftputil.tool.as_bytes
     482        host.chdir("/home/file_name_test")
     483        # Unicode
     484        items = host.listdir("ä")
     485        self.assertEqual(items, ["ö", "o"])
     486        #  Need explicit type check for Python 2
     487        for item in items:
     488            self.assertTrue(isinstance(item, ftputil.compat.unicode_type))
     489#         # Bytes
     490#         items = host.listdir(as_bytes("ä"))
     491#         self.assertEqual(items, [as_bytes("ö"), as_bytes("o")])
     492#         #  Need explicit type check for Python 2
     493#         for item in items:
     494#             self.assertTrue(isinstance(item, ftputil.compat.bytes_type))
     495
     496
    469497if __name__ == '__main__':
    470498    unittest.main()
  • test/test_real_ftp.py

    r1278 r1284  
    773773        self.assert_unicode_error(self.host.download_if_newer, "ä", "ok")
    774774
    775     def test_chdir(self):
    776         # Unicode strings are ok if they can be encoded to ASCII.
    777         host = self.host
    778         host.chdir(".")
    779         self.assert_non_unicode(host.getcwd())
    780         host.chdir(".")
    781         self.assert_non_unicode(host.getcwd())
    782         # Fail early if string can't be encoded to ASCII.
    783         self.assert_unicode_error(host.chdir, "ä")
     775#     def test_chdir(self):
     776#         # Unicode strings are ok if they can be encoded to ASCII.
     777#         host = self.host
     778#         host.chdir(".")
     779#         self.assert_non_unicode(host.getcwd())
     780#         host.chdir(".")
     781#         self.assert_non_unicode(host.getcwd())
     782#         # Fail early if string can't be encoded to ASCII.
     783#         self.assert_unicode_error(host.chdir, "ä")
    784784
    785785    def test_rename(self):
Note: See TracChangeset for help on using the changeset viewer.