/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/features.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""A collection of commonly used 'Features' to optionally run tests.
18
18
"""
19
19
 
20
 
from __future__ import absolute_import
21
 
 
22
 
import importlib
23
20
import os
24
21
import subprocess
25
22
import stat
26
23
import sys
27
24
import tempfile
28
 
import warnings
29
25
 
30
 
from .. import (
 
26
from bzrlib import (
31
27
    osutils,
32
28
    symbol_versioning,
33
29
    )
139
135
 
140
136
    def _ensure(self):
141
137
        if self._feature is None:
142
 
            from breezy import pyutils
 
138
            from bzrlib import pyutils
143
139
            depr_msg = self._dep_version % ('%s.%s'
144
140
                                            % (self._module, self._name))
145
141
            use_msg = ' Use %s.%s instead.' % (self._replacement_module,
165
161
    :ivar module: The module if it is available, else None.
166
162
    """
167
163
 
168
 
    def __init__(self, module_name, ignore_warnings=None):
 
164
    def __init__(self, module_name):
169
165
        super(ModuleAvailableFeature, self).__init__()
170
166
        self.module_name = module_name
171
 
        if ignore_warnings is None:
172
 
            ignore_warnings = ()
173
 
        self.ignore_warnings = ignore_warnings
174
167
 
175
168
    def _probe(self):
176
169
        sentinel = object()
177
170
        module = sys.modules.get(self.module_name, sentinel)
178
171
        if module is sentinel:
179
 
            with warnings.catch_warnings():
180
 
                for warning_category in self.ignore_warnings:
181
 
                    warnings.simplefilter('ignore', warning_category)
182
 
                try:
183
 
                    self._module = importlib.import_module(self.module_name)
184
 
                except ImportError:
185
 
                    return False
 
172
            try:
 
173
                self._module = __import__(self.module_name, {}, {}, [''])
186
174
                return True
 
175
            except ImportError:
 
176
                return False
187
177
        else:
188
178
            self._module = module
189
179
            return True
198
188
        return self.module_name
199
189
 
200
190
 
201
 
class PluginLoadedFeature(Feature):
202
 
    """Check whether a plugin with specific name is loaded.
203
 
 
204
 
    This is different from ModuleAvailableFeature, because
205
 
    plugins can be available but explicitly disabled
206
 
    (e.g. through BRZ_DISABLE_PLUGINS=blah).
207
 
 
208
 
    :ivar plugin_name: The name of the plugin
209
 
    """
210
 
 
211
 
    def __init__(self, plugin_name):
212
 
        super(PluginLoadedFeature, self).__init__()
213
 
        self.plugin_name = plugin_name
214
 
 
215
 
    def _probe(self):
216
 
        from breezy.plugin import get_loaded_plugin
217
 
        return (get_loaded_plugin(self.plugin_name) is not None)
218
 
 
219
 
    @property
220
 
    def plugin(self):
221
 
        from breezy.plugin import get_loaded_plugin
222
 
        return get_loaded_plugin(self.plugin_name)
223
 
 
224
 
    def feature_name(self):
225
 
        return '%s plugin' % self.plugin_name
226
 
 
227
 
 
228
191
class _HTTPSServerFeature(Feature):
229
192
    """Some tests want an https Server, check if one is available.
230
193
 
272
235
    """Does this platform support the breakin feature?"""
273
236
 
274
237
    def _probe(self):
275
 
        from breezy import breakin
 
238
        from bzrlib import breakin
276
239
        if breakin.determine_signal() is None:
277
240
            return False
278
241
        if sys.platform == 'win32':
327
290
        if CaseInsCasePresFilenameFeature.available():
328
291
            return False
329
292
 
330
 
        from breezy import tests
 
293
        from bzrlib import tests
331
294
 
332
295
        if tests.TestCaseWithMemoryTransport.TEST_ROOT is None:
333
296
            root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
382
345
 
383
346
not_running_as_root = _NotRunningAsRoot()
384
347
 
385
 
# Apport uses deprecated imp module on python3.
386
 
apport = ModuleAvailableFeature(
387
 
    'apport.report',
388
 
    ignore_warnings=[DeprecationWarning, PendingDeprecationWarning])
389
 
gpg = ModuleAvailableFeature('gpg')
 
348
apport = ModuleAvailableFeature('apport')
 
349
gpgme = ModuleAvailableFeature('gpgme')
390
350
lzma = ModuleAvailableFeature('lzma')
391
351
meliae = ModuleAvailableFeature('meliae.scanner')
392
352
paramiko = ModuleAvailableFeature('paramiko')
 
353
pycurl = ModuleAvailableFeature('pycurl')
393
354
pywintypes = ModuleAvailableFeature('pywintypes')
394
355
subunit = ModuleAvailableFeature('subunit')
395
356
testtools = ModuleAvailableFeature('testtools')
396
357
 
397
358
compiled_patiencediff_feature = ModuleAvailableFeature(
398
 
    'breezy._patiencediff_c')
399
 
lsprof_feature = ModuleAvailableFeature('breezy.lsprof')
 
359
    'bzrlib._patiencediff_c')
 
360
lsprof_feature = ModuleAvailableFeature('bzrlib.lsprof')
400
361
 
401
362
 
402
363
class _BackslashDirSeparatorFeature(Feature):
464
425
            os.close(fd)
465
426
            osutils.chmod_if_possible(name, write_perms)
466
427
 
467
 
            read_perms = os.stat(name).st_mode & 0o777
 
428
            read_perms = os.stat(name).st_mode & 0777
468
429
            os.unlink(name)
469
430
            return (write_perms == read_perms)
470
431
 
486
447
                stdout=subprocess.PIPE)
487
448
            proc.communicate()
488
449
            return True
489
 
        except OSError as e:
 
450
        except OSError, e:
490
451
            if e.errno == errno.ENOENT:
491
452
                # strace is not installed
492
453
                return False
507
468
            return False
508
469
        try:
509
470
            proc = subprocess.Popen(['attrib', '.'], stdout=subprocess.PIPE)
510
 
        except OSError as e:
 
471
        except OSError, e:
511
472
            return False
512
473
        return (0 == proc.wait())
513
474
 
533
494
win32_feature = Win32Feature()
534
495
 
535
496
 
536
 
class _BackslashFilenameFeature(Feature):
537
 
    """Does the filesystem support backslashes in filenames?"""
538
 
 
539
 
    def _probe(self):
540
 
 
541
 
        try:
542
 
            fileno, name = tempfile.mkstemp(prefix='bzr\\prefix')
543
 
        except (IOError, OSError):
544
 
            return False
545
 
        else:
546
 
            try:
547
 
                os.stat(name)
548
 
            except (IOError, OSError):
549
 
                # mkstemp succeeded but the file wasn't actually created
550
 
                return False
551
 
            os.close(fileno)
552
 
            os.remove(name)
553
 
            return True
554
 
 
555
 
 
556
 
BackslashFilenameFeature = _BackslashFilenameFeature()
557
 
 
558
 
 
559
497
class _ColorFeature(Feature):
560
498
 
561
499
    def _probe(self):
562
 
        from breezy._termcolor import allow_color
 
500
        from bzrlib._termcolor import allow_color
563
501
        return allow_color()
564
502
 
565
503
    def feature_name(self):