/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
4584.3.21 by Martin Pool
Start adding tests for apport
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
5241.2.1 by Robert Collins
Merge up from 2.0/2.1:
17
"""A collection of commonly used 'Features' which bzrlib uses to skip tests."""
18
5036.3.8 by Parth Malwankar
closed review comments from vila
19
import os
20
import stat
4584.3.21 by Martin Pool
Start adding tests for apport
21
4913.2.11 by John Arbash Meinel
Convert a bunch more features over to ModuleAvailableFeature
22
from bzrlib import tests
4913.2.19 by John Arbash Meinel
Compatibly rename ApportFeature to features.apport.
23
24
4797.70.1 by Vincent Ladeuil
Skip chmodbits dependent tests when running as root
25
class _NotRunningAsRoot(tests.Feature):
26
27
    def _probe(self):
28
        try:
29
            uid = os.getuid()
30
        except AttributeError:
31
            # If there is no uid, chances are there is no root either
32
            return True
33
        return uid != 0
34
35
    def feature_name(self):
36
        return 'Not running as root'
37
38
39
not_running_as_root = _NotRunningAsRoot()
5448.5.9 by Vincent Ladeuil
Make the test depends on a feature so it's skipped if meliae is not installed
40
4913.2.19 by John Arbash Meinel
Compatibly rename ApportFeature to features.apport.
41
apport = tests.ModuleAvailableFeature('apport')
5448.5.9 by Vincent Ladeuil
Make the test depends on a feature so it's skipped if meliae is not installed
42
meliae = tests.ModuleAvailableFeature('meliae')
4913.2.18 by John Arbash Meinel
Add a _CompatibilityThunkFeature.
43
paramiko = tests.ModuleAvailableFeature('paramiko')
4913.2.11 by John Arbash Meinel
Convert a bunch more features over to ModuleAvailableFeature
44
pycurl = tests.ModuleAvailableFeature('pycurl')
5200.4.5 by Martin
Move pywintypes ModuleAvailableFeature to bzrlib.tests.features
45
pywintypes = tests.ModuleAvailableFeature('pywintypes')
5448.5.9 by Vincent Ladeuil
Make the test depends on a feature so it's skipped if meliae is not installed
46
sphinx = tests.ModuleAvailableFeature('sphinx')
4913.2.18 by John Arbash Meinel
Add a _CompatibilityThunkFeature.
47
subunit = tests.ModuleAvailableFeature('subunit')
5036.3.8 by Parth Malwankar
closed review comments from vila
48
5094.3.1 by Martin Pool
``.bazaar``, ``.bazaar/bazaar.conf`` and ``.bzr.log`` inherit user and group ownership from the containing directory. This allow bzr to work better with sudo.
49
5241.2.1 by Robert Collins
Merge up from 2.0/2.1:
50
class _BackslashDirSeparatorFeature(tests.Feature):
51
52
    def _probe(self):
53
        try:
54
            os.lstat(os.getcwd() + '\\')
55
        except OSError:
56
            return False
57
        else:
58
            return True
59
60
    def feature_name(self):
61
        return "Filesystem treats '\\' as a directory separator."
62
63
backslashdir_feature = _BackslashDirSeparatorFeature()
64
65
5036.3.8 by Parth Malwankar
closed review comments from vila
66
class _PosixPermissionsFeature(tests.Feature):
67
68
    def _probe(self):
69
        def has_perms():
70
            # create temporary file and check if specified perms are maintained.
71
            import tempfile
72
73
            write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
74
            f = tempfile.mkstemp(prefix='bzr_perms_chk_')
75
            fd, name = f
76
            os.close(fd)
77
            os.chmod(name, write_perms)
78
79
            read_perms = os.stat(name).st_mode & 0777
80
            os.unlink(name)
81
            return (write_perms == read_perms)
82
83
        return (os.name == 'posix') and has_perms()
84
85
    def feature_name(self):
86
        return 'POSIX permissions support'
87
5094.3.1 by Martin Pool
``.bazaar``, ``.bazaar/bazaar.conf`` and ``.bzr.log`` inherit user and group ownership from the containing directory. This allow bzr to work better with sudo.
88
89
posix_permissions_feature = _PosixPermissionsFeature()
90
91
5051.4.10 by Parth Malwankar
moved ChownFeature to tests/features.py
92
class _ChownFeature(tests.Feature):
93
    """os.chown is supported"""
94
95
    def _probe(self):
96
        return os.name == 'posix' and hasattr(os, 'chown')
97
5051.4.11 by Parth Malwankar
closed Martins review comments.
98
chown_feature = _ChownFeature()
5051.4.10 by Parth Malwankar
moved ChownFeature to tests/features.py
99
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
100
101
class ExecutableFeature(tests.Feature):
102
    """Feature testing whether an executable of a given name is on the PATH."""
103
104
    def __init__(self, name):
105
        super(ExecutableFeature, self).__init__()
106
        self.name = name
5147.5.23 by Martin von Gagern
Have ExecutableFeature implement and use _probe.
107
        self._path = None
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
108
109
    @property
110
    def path(self):
5147.5.23 by Martin von Gagern
Have ExecutableFeature implement and use _probe.
111
        # This is a property, so accessing path ensures _probe was called
112
        self.available()
113
        return self._path
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
114
5147.5.23 by Martin von Gagern
Have ExecutableFeature implement and use _probe.
115
    def _probe(self):
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
116
        path = os.environ.get('PATH')
117
        if path is None:
5147.5.23 by Martin von Gagern
Have ExecutableFeature implement and use _probe.
118
            return False
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
119
        for d in path.split(os.pathsep):
5147.5.22 by Martin von Gagern
Handle empty PATH elements in ExecutableFeature.
120
            if d:
121
                f = os.path.join(d, self.name)
122
                if os.access(f, os.X_OK):
5147.5.23 by Martin von Gagern
Have ExecutableFeature implement and use _probe.
123
                    self._path = f
124
                    return True
125
        return False
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
126
127
    def feature_name(self):
128
        return '%s executable' % self.name
5147.5.24 by Martin von Gagern
Move ExecutableFeature instances to tests.features module.
129
130
131
bash_feature = ExecutableFeature('bash')
132
sed_feature = ExecutableFeature('sed')
5349.1.5 by Matthäus G. Chajdas
Fix issues raised by Vincent Ladeuil.
133
diff_feature = ExecutableFeature('diff')