/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
5609.47.1 by Alexander Belchenko
Win32Feature
21
import sys
4584.3.21 by Martin Pool
Start adding tests for apport
22
5321.2.1 by Vincent Ladeuil
Fix style issues, including vertical spaces, lines too long and multi lines imports.
23
from bzrlib import (
24
    osutils,
25
    tests,
26
    )
4913.2.19 by John Arbash Meinel
Compatibly rename ApportFeature to features.apport.
27
28
4797.70.1 by Vincent Ladeuil
Skip chmodbits dependent tests when running as root
29
class _NotRunningAsRoot(tests.Feature):
30
31
    def _probe(self):
32
        try:
33
            uid = os.getuid()
34
        except AttributeError:
35
            # If there is no uid, chances are there is no root either
36
            return True
37
        return uid != 0
38
39
    def feature_name(self):
40
        return 'Not running as root'
41
42
43
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
44
4913.2.19 by John Arbash Meinel
Compatibly rename ApportFeature to features.apport.
45
apport = tests.ModuleAvailableFeature('apport')
5718.5.19 by Jelmer Vernooij
Use features.
46
lzma = tests.ModuleAvailableFeature('lzma')
5448.5.9 by Vincent Ladeuil
Make the test depends on a feature so it's skipped if meliae is not installed
47
meliae = tests.ModuleAvailableFeature('meliae')
4913.2.18 by John Arbash Meinel
Add a _CompatibilityThunkFeature.
48
paramiko = tests.ModuleAvailableFeature('paramiko')
4913.2.11 by John Arbash Meinel
Convert a bunch more features over to ModuleAvailableFeature
49
pycurl = tests.ModuleAvailableFeature('pycurl')
5200.4.5 by Martin
Move pywintypes ModuleAvailableFeature to bzrlib.tests.features
50
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
51
sphinx = tests.ModuleAvailableFeature('sphinx')
4913.2.18 by John Arbash Meinel
Add a _CompatibilityThunkFeature.
52
subunit = tests.ModuleAvailableFeature('subunit')
5036.3.8 by Parth Malwankar
closed review comments from vila
53
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.
54
5241.2.1 by Robert Collins
Merge up from 2.0/2.1:
55
class _BackslashDirSeparatorFeature(tests.Feature):
56
57
    def _probe(self):
58
        try:
59
            os.lstat(os.getcwd() + '\\')
60
        except OSError:
61
            return False
62
        else:
63
            return True
64
65
    def feature_name(self):
66
        return "Filesystem treats '\\' as a directory separator."
67
68
backslashdir_feature = _BackslashDirSeparatorFeature()
69
70
5036.3.8 by Parth Malwankar
closed review comments from vila
71
class _PosixPermissionsFeature(tests.Feature):
72
73
    def _probe(self):
74
        def has_perms():
75
            # create temporary file and check if specified perms are maintained.
76
            import tempfile
77
78
            write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
79
            f = tempfile.mkstemp(prefix='bzr_perms_chk_')
80
            fd, name = f
81
            os.close(fd)
82
            os.chmod(name, write_perms)
83
84
            read_perms = os.stat(name).st_mode & 0777
85
            os.unlink(name)
86
            return (write_perms == read_perms)
87
88
        return (os.name == 'posix') and has_perms()
89
90
    def feature_name(self):
91
        return 'POSIX permissions support'
92
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.
93
94
posix_permissions_feature = _PosixPermissionsFeature()
95
96
5051.4.10 by Parth Malwankar
moved ChownFeature to tests/features.py
97
class _ChownFeature(tests.Feature):
98
    """os.chown is supported"""
99
100
    def _probe(self):
101
        return os.name == 'posix' and hasattr(os, 'chown')
102
5051.4.11 by Parth Malwankar
closed Martins review comments.
103
chown_feature = _ChownFeature()
5051.4.10 by Parth Malwankar
moved ChownFeature to tests/features.py
104
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
105
106
class ExecutableFeature(tests.Feature):
107
    """Feature testing whether an executable of a given name is on the PATH."""
108
109
    def __init__(self, name):
110
        super(ExecutableFeature, self).__init__()
111
        self.name = name
5147.5.23 by Martin von Gagern
Have ExecutableFeature implement and use _probe.
112
        self._path = None
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
113
114
    @property
115
    def path(self):
5147.5.23 by Martin von Gagern
Have ExecutableFeature implement and use _probe.
116
        # This is a property, so accessing path ensures _probe was called
117
        self.available()
118
        return self._path
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
119
5147.5.23 by Martin von Gagern
Have ExecutableFeature implement and use _probe.
120
    def _probe(self):
5321.1.82 by Gordon Tyler
Changed ExecutableFeature to use osutils.find_executable_on_path.
121
        self._path = osutils.find_executable_on_path(self.name)
122
        return self._path is not None
5147.5.20 by Martin von Gagern
Move ExecutableFeature class from bash_completion plugin to bzrlib tests.
123
124
    def feature_name(self):
125
        return '%s executable' % self.name
5147.5.24 by Martin von Gagern
Move ExecutableFeature instances to tests.features module.
126
127
128
bash_feature = ExecutableFeature('bash')
129
sed_feature = ExecutableFeature('sed')
5349.1.5 by Matthäus G. Chajdas
Fix issues raised by Vincent Ladeuil.
130
diff_feature = ExecutableFeature('diff')
5609.47.1 by Alexander Belchenko
Win32Feature
131
132
133
class Win32Feature(tests.Feature):
134
    """Feature testing whether we're running selftest on Windows
5609.47.4 by Alexander Belchenko
fixed typo
135
    or Windows-like platform.
5609.47.1 by Alexander Belchenko
Win32Feature
136
    """
137
138
    def _probe(self):
139
        return sys.platform == 'win32'
140
141
    def feature_name(self):
142
        return "win32 platform"
143
144
win32_feature = Win32Feature()