~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/ftp_server/__init__.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""
18
 
Facilities to use ftp test servers.
19
 
"""
20
 
 
21
 
import sys
22
 
 
23
 
from bzrlib import tests
24
 
from bzrlib.tests import (
25
 
    features,
26
 
    )
27
 
 
28
 
 
29
 
try:
30
 
    from bzrlib.tests.ftp_server import medusa_based
31
 
    # medusa is bogus starting with python2.6, since we don't support earlier
32
 
    # pythons anymore, it's currently useless. There is hope though that the
33
 
    # unicode bugs get fixed in the future so we leave it disabled until
34
 
    # then. Keeping the framework in place means that only the following line
35
 
    # will need to be changed.  The last tests were conducted with medusa-2.0
36
 
    # -- vila 20110607
37
 
    medusa_available = False
38
 
except ImportError:
39
 
    medusa_available = False
40
 
 
41
 
 
42
 
try:
43
 
    from bzrlib.tests.ftp_server import pyftpdlib_based
44
 
    if pyftpdlib_based.pyftplib_version >= (0, 7, 0):
45
 
        pyftpdlib_available = True
46
 
    else:
47
 
        # 0.6.0 breaks SITE CHMOD
48
 
        pyftpdlib_available = False
49
 
except ImportError:
50
 
    pyftpdlib_available = False
51
 
 
52
 
 
53
 
class _FTPServerFeature(features.Feature):
54
 
    """Some tests want an FTP Server, check if one is available.
55
 
 
56
 
    Right now, the only way this is available is if one of the following is
57
 
    installed:
58
 
 
59
 
    - 'medusa': http://www.amk.ca/python/code/medusa.html
60
 
    - 'pyftpdlib': http://code.google.com/p/pyftpdlib/
61
 
    """
62
 
 
63
 
    def _probe(self):
64
 
        return medusa_available or pyftpdlib_available
65
 
 
66
 
    def feature_name(self):
67
 
        return 'FTPServer'
68
 
 
69
 
 
70
 
FTPServerFeature = _FTPServerFeature()
71
 
 
72
 
 
73
 
class UnavailableFTPTestServer(object):
74
 
    """Dummy ftp test server.
75
 
 
76
 
    This allows the test suite report the number of tests needing that
77
 
    feature. We raise UnavailableFeature from methods before the test server is
78
 
    being used. Doing so in the setUp method has bad side-effects (tearDown is
79
 
    never called).
80
 
    """
81
 
 
82
 
    def start_server(self, vfs_server=None):
83
 
        pass
84
 
 
85
 
    def stop_server(self):
86
 
        pass
87
 
 
88
 
    def get_url(self):
89
 
        raise tests.UnavailableFeature(FTPServerFeature)
90
 
 
91
 
    def get_bogus_url(self):
92
 
        raise tests.UnavailableFeature(FTPServerFeature)
93
 
 
94
 
 
95
 
if medusa_available:
96
 
    FTPTestServer = medusa_based.FTPTestServer
97
 
elif pyftpdlib_available:
98
 
    FTPTestServer = pyftpdlib_based.FTPTestServer
99
 
else:
100
 
    FTPTestServer = UnavailableFTPTestServer