~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

merge bzr.dev r4171

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
"""
 
17
Facilities to use ftp test servers.
 
18
"""
 
19
 
 
20
import sys
 
21
 
 
22
from bzrlib import tests
 
23
 
 
24
 
 
25
try:
 
26
    from bzrlib.tests.ftp_server import medusa_based
 
27
    # medusa is bogus under python2.6
 
28
    medusa_available = sys.version_info < (2, 6)
 
29
except ImportError:
 
30
    medusa_available = False
 
31
 
 
32
 
 
33
try:
 
34
    from bzrlib.tests.ftp_server import pyftpdlib_based
 
35
    pyftpdlib_available = True
 
36
except ImportError:
 
37
    pyftpdlib_available = False
 
38
 
 
39
 
 
40
class _FTPServerFeature(tests.Feature):
 
41
    """Some tests want an FTP Server, check if one is available.
 
42
 
 
43
    Right now, the only way this is available is if one of the following is
 
44
    installed:
 
45
 
 
46
    - 'medusa': http://www.amk.ca/python/code/medusa.html
 
47
    - 'pyftpdlib': http://code.google.com/p/pyftpdlib/
 
48
    """
 
49
 
 
50
    def _probe(self):
 
51
        return medusa_available or pyftpdlib_available
 
52
 
 
53
    def feature_name(self):
 
54
        return 'FTPServer'
 
55
 
 
56
 
 
57
FTPServerFeature = _FTPServerFeature()
 
58
 
 
59
 
 
60
class UnavailableFTPTestServer(object):
 
61
    """Dummy ftp test server.
 
62
 
 
63
    This allows the test suite report the number of tests needing that
 
64
    feature. We raise UnavailableFeature from methods before the test server is
 
65
    being used. Doing so in the setUp method has bad side-effects (tearDown is
 
66
    never called).
 
67
    """
 
68
 
 
69
    def setUp(self, vfs_server=None):
 
70
        pass
 
71
 
 
72
    def tearDown(self):
 
73
        pass
 
74
 
 
75
    def get_url(self):
 
76
        raise tests.UnavailableFeature(FTPServerFeature)
 
77
 
 
78
    def get_bogus_url(self):
 
79
        raise tests.UnavailableFeature(FTPServerFeature)
 
80
 
 
81
 
 
82
if medusa_available:
 
83
    FTPTestServer = medusa_based.FTPTestServer
 
84
elif pyftpdlib_available:
 
85
    FTPTestServer = pyftpdlib_based.FTPTestServer
 
86
else:
 
87
    FTPTestServer = UnavailableFTPTestServer