Ignore:
Timestamp:
Mar 31, 2013, 6:49:04 PM (7 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Processed tests and `setup.py` with `2to3` and fixed a few things.

When run under Python 2.7, most tests pass. However, there are still
unicode-related error messages in `test_real_ftp.py`. Moreover,
returning the correct type (i. e. the same type as the argument) from
several functions/methods doesn't work yet. Mostly, there aren't unit
tests for this yet, so this problem might give an inappropriate
confidence.

There a still quite a few test failures when running under Python 3.2,
but I didn't expect anything else.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/mock_ftplib.py

    r1196 r1205  
    1010"""
    1111
     12from __future__ import unicode_literals
     13
     14import io
     15import collections
    1216import ftplib
    1317import posixpath
    14 import StringIO
    1518
    1619DEBUG = 0
     
    2528
    2629
    27 class MockFile(StringIO.StringIO, object):
     30class MockFile(io.BytesIO, object):
    2831    """
    2932    Mock class for the file objects _contained in_ `_FTPFile` objects
     
    3336    be queried for their contents after they have been closed.
    3437    """
    35     def __init__(self, path, content=''):
     38    def __init__(self, path, content=b''):
    3639        global mock_files
    3740        mock_files[path] = self
     
    5760    def __init__(self, path, mock_file_content=''):
    5861        if DEBUG:
    59             print "File content: *{0}*".format(mock_file_content)
     62            print("File content: *{0}*".format(mock_file_content))
    6063        self.file_path = path
    6164        self.mock_file_content = mock_file_content
     
    8992
    9093    # File content to be used (indirectly) with `transfercmd`.
    91     mock_file_content = ''
     94    mock_file_content = b''
    9295
    9396    def __init__(self, host='', user='', password=''):
     
    101104    def voidcmd(self, cmd):
    102105        if DEBUG:
    103             print cmd
     106            print(cmd)
    104107        if cmd == 'STAT':
    105108            return 'MockSession server awaiting your commands ;-)'
     
    129132        a directory listing. Return nothing.
    130133        """
    131         if callable(args[-1]):
     134        if isinstance(args[-1], collections.Callable):
    132135            callback = args[-1]
    133136            args = args[:-1]
     
    137140        path = args[-1]
    138141        if DEBUG:
    139             print "dir: {0}".format(path)
     142            print("dir: {0}".format(path))
    140143        path = self._transform_path(path)
    141         if not self.dir_contents.has_key(path):
     144        if path not in self.dir_contents:
    142145            raise ftplib.error_perm
    143146        dir_lines = self.dir_contents[path].split('\n')
    144147        for line in dir_lines:
    145148            if callback is None:
    146                 print line
     149                print(line)
    147150            else:
    148151                callback(line)
     
    159162        """
    160163        if DEBUG:
    161             print cmd
     164            print(cmd)
    162165        # Fail if attempting to read from/write to a directory
    163166        cmd, path = cmd.split()
    164167        path = self._remove_trailing_slash(path)
    165         if self.dir_contents.has_key(path):
     168        if path in self.dir_contents:
    166169            raise ftplib.error_perm
    167170        # Fail if path isn't available (this name is hard-coded here
Note: See TracChangeset for help on using the changeset viewer.