/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 breezy/tests/features.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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
import importlib
20
21
import os
21
22
import subprocess
22
23
import stat
23
24
import sys
24
25
import tempfile
 
26
import warnings
25
27
 
26
 
from bzrlib import (
 
28
from .. import (
27
29
    osutils,
28
30
    symbol_versioning,
29
31
    )
65
67
    def feature_name(self):
66
68
        return 'symlinks'
67
69
 
 
70
 
68
71
SymlinkFeature = _SymlinkFeature()
69
72
 
70
73
 
76
79
    def feature_name(self):
77
80
        return 'hardlinks'
78
81
 
 
82
 
79
83
HardlinkFeature = _HardlinkFeature()
80
84
 
81
85
 
87
91
    def feature_name(self):
88
92
        return 'filesystem fifos'
89
93
 
 
94
 
90
95
OsFifoFeature = _OsFifoFeature()
91
96
 
92
97
 
111
116
            # for some reason.
112
117
            return True
113
118
 
 
119
 
114
120
UnicodeFilenameFeature = _UnicodeFilenameFeature()
115
121
 
116
122
 
135
141
 
136
142
    def _ensure(self):
137
143
        if self._feature is None:
138
 
            from bzrlib import pyutils
 
144
            from breezy import pyutils
139
145
            depr_msg = self._dep_version % ('%s.%s'
140
146
                                            % (self._module, self._name))
141
147
            use_msg = ' Use %s.%s instead.' % (self._replacement_module,
161
167
    :ivar module: The module if it is available, else None.
162
168
    """
163
169
 
164
 
    def __init__(self, module_name):
 
170
    def __init__(self, module_name, ignore_warnings=None):
165
171
        super(ModuleAvailableFeature, self).__init__()
166
172
        self.module_name = module_name
 
173
        if ignore_warnings is None:
 
174
            ignore_warnings = ()
 
175
        self.ignore_warnings = ignore_warnings
167
176
 
168
177
    def _probe(self):
169
178
        sentinel = object()
170
179
        module = sys.modules.get(self.module_name, sentinel)
171
180
        if module is sentinel:
172
 
            try:
173
 
                self._module = __import__(self.module_name, {}, {}, [''])
 
181
            with warnings.catch_warnings():
 
182
                for warning_category in self.ignore_warnings:
 
183
                    warnings.simplefilter('ignore', warning_category)
 
184
                try:
 
185
                    self._module = importlib.import_module(self.module_name)
 
186
                except ImportError:
 
187
                    return False
174
188
                return True
175
 
            except ImportError:
176
 
                return False
177
189
        else:
178
190
            self._module = module
179
191
            return True
188
200
        return self.module_name
189
201
 
190
202
 
 
203
class PluginLoadedFeature(Feature):
 
204
    """Check whether a plugin with specific name is loaded.
 
205
 
 
206
    This is different from ModuleAvailableFeature, because
 
207
    plugins can be available but explicitly disabled
 
208
    (e.g. through BRZ_DISABLE_PLUGINS=blah).
 
209
 
 
210
    :ivar plugin_name: The name of the plugin
 
211
    """
 
212
 
 
213
    def __init__(self, plugin_name):
 
214
        super(PluginLoadedFeature, self).__init__()
 
215
        self.plugin_name = plugin_name
 
216
 
 
217
    def _probe(self):
 
218
        from breezy.plugin import get_loaded_plugin
 
219
        return (get_loaded_plugin(self.plugin_name) is not None)
 
220
 
 
221
    @property
 
222
    def plugin(self):
 
223
        from breezy.plugin import get_loaded_plugin
 
224
        return get_loaded_plugin(self.plugin_name)
 
225
 
 
226
    def feature_name(self):
 
227
        return '%s plugin' % self.plugin_name
 
228
 
 
229
 
191
230
class _HTTPSServerFeature(Feature):
192
231
    """Some tests want an https Server, check if one is available.
193
232
 
197
236
 
198
237
    def _probe(self):
199
238
        try:
200
 
            import ssl
 
239
            import ssl  # noqa: F401
201
240
            return True
202
241
        except ImportError:
203
242
            return False
217
256
            return True
218
257
        return False
219
258
 
 
259
 
220
260
ByteStringNamedFilesystem = _ByteStringNamedFilesystem()
221
261
 
222
262
 
228
268
            return True
229
269
        return False
230
270
 
 
271
 
231
272
UTF8Filesystem = _UTF8Filesystem()
232
273
 
233
274
 
235
276
    """Does this platform support the breakin feature?"""
236
277
 
237
278
    def _probe(self):
238
 
        from bzrlib import breakin
 
279
        from breezy import breakin
239
280
        if breakin.determine_signal() is None:
240
281
            return False
241
282
        if sys.platform == 'win32':
243
284
            # We trigger SIGBREAK via a Console api so we need ctypes to
244
285
            # access the function
245
286
            try:
246
 
                import ctypes
 
287
                import ctypes  # noqa: F401
247
288
            except OSError:
248
289
                return False
249
290
        return True
266
307
            name = osutils.normpath(name)
267
308
            base, rel = osutils.split(name)
268
309
            found_rel = osutils.canonical_relpath(base, name)
269
 
            return (found_rel == rel
270
 
                    and os.path.isfile(name.upper())
271
 
                    and os.path.isfile(name.lower()))
 
310
            return (found_rel == rel and
 
311
                    os.path.isfile(name.upper()) and
 
312
                    os.path.isfile(name.lower()))
272
313
        finally:
273
314
            os.close(fileno)
274
315
            os.remove(name)
276
317
    def feature_name(self):
277
318
        return "case-insensitive case-preserving filesystem"
278
319
 
 
320
 
279
321
CaseInsCasePresFilenameFeature = _CaseInsCasePresFilenameFeature()
280
322
 
281
323
 
290
332
        if CaseInsCasePresFilenameFeature.available():
291
333
            return False
292
334
 
293
 
        from bzrlib import tests
 
335
        from breezy import tests
294
336
 
295
337
        if tests.TestCaseWithMemoryTransport.TEST_ROOT is None:
296
338
            root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
298
340
        else:
299
341
            root = tests.TestCaseWithMemoryTransport.TEST_ROOT
300
342
        tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
301
 
            dir=root)
 
343
                               dir=root)
302
344
        name_a = osutils.pathjoin(tdir, 'a')
303
345
        name_A = osutils.pathjoin(tdir, 'A')
304
346
        os.mkdir(name_a)
309
351
    def feature_name(self):
310
352
        return 'case-insensitive filesystem'
311
353
 
 
354
 
312
355
CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()
313
356
 
314
357
 
325
368
    def feature_name(self):
326
369
        return 'case-sensitive filesystem'
327
370
 
 
371
 
328
372
# new coding style is for feature instances to be lowercase
329
373
case_sensitive_filesystem_feature = _CaseSensitiveFilesystemFeature()
330
374
 
345
389
 
346
390
not_running_as_root = _NotRunningAsRoot()
347
391
 
348
 
apport = ModuleAvailableFeature('apport')
349
 
gpgme = ModuleAvailableFeature('gpgme')
 
392
# Apport uses deprecated imp module on python3.
 
393
apport = ModuleAvailableFeature(
 
394
    'apport.report',
 
395
    ignore_warnings=[DeprecationWarning, PendingDeprecationWarning])
 
396
gpg = ModuleAvailableFeature('gpg')
350
397
lzma = ModuleAvailableFeature('lzma')
351
398
meliae = ModuleAvailableFeature('meliae.scanner')
352
399
paramiko = ModuleAvailableFeature('paramiko')
353
 
pycurl = ModuleAvailableFeature('pycurl')
354
400
pywintypes = ModuleAvailableFeature('pywintypes')
355
401
subunit = ModuleAvailableFeature('subunit')
356
402
testtools = ModuleAvailableFeature('testtools')
357
 
 
358
 
compiled_patiencediff_feature = ModuleAvailableFeature(
359
 
    'bzrlib._patiencediff_c')
360
 
lsprof_feature = ModuleAvailableFeature('bzrlib.lsprof')
 
403
flake8 = ModuleAvailableFeature('flake8.api.legacy')
 
404
 
 
405
lsprof_feature = ModuleAvailableFeature('breezy.lsprof')
 
406
pkg_resources_feature = ModuleAvailableFeature('pkg_resources')
 
407
 
 
408
pyinotify = ModuleAvailableFeature('pyinotify')
361
409
 
362
410
 
363
411
class _BackslashDirSeparatorFeature(Feature):
373
421
    def feature_name(self):
374
422
        return "Filesystem treats '\\' as a directory separator."
375
423
 
 
424
 
376
425
backslashdir_feature = _BackslashDirSeparatorFeature()
377
426
 
378
427
 
382
431
    def _probe(self):
383
432
        return os.name == 'posix' and hasattr(os, 'chown')
384
433
 
 
434
 
385
435
chown_feature = _ChownFeature()
386
436
 
387
437
 
425
475
            os.close(fd)
426
476
            osutils.chmod_if_possible(name, write_perms)
427
477
 
428
 
            read_perms = os.stat(name).st_mode & 0777
 
478
            read_perms = os.stat(name).st_mode & 0o777
429
479
            os.unlink(name)
430
480
            return (write_perms == read_perms)
431
481
 
443
493
    def _probe(self):
444
494
        try:
445
495
            proc = subprocess.Popen(['strace'],
446
 
                stderr=subprocess.PIPE,
447
 
                stdout=subprocess.PIPE)
 
496
                                    stderr=subprocess.PIPE,
 
497
                                    stdout=subprocess.PIPE)
448
498
            proc.communicate()
449
499
            return True
450
 
        except OSError, e:
 
500
        except OSError as e:
 
501
            import errno
451
502
            if e.errno == errno.ENOENT:
452
503
                # strace is not installed
453
504
                return False
468
519
            return False
469
520
        try:
470
521
            proc = subprocess.Popen(['attrib', '.'], stdout=subprocess.PIPE)
471
 
        except OSError, e:
 
522
        except OSError:
472
523
            return False
473
524
        return (0 == proc.wait())
474
525
 
494
545
win32_feature = Win32Feature()
495
546
 
496
547
 
497
 
class _ColorFeature(Feature):
498
 
 
499
 
    def _probe(self):
500
 
        from bzrlib._termcolor import allow_color
501
 
        return allow_color()
 
548
class _BackslashFilenameFeature(Feature):
 
549
    """Does the filesystem support backslashes in filenames?"""
 
550
 
 
551
    def _probe(self):
 
552
 
 
553
        try:
 
554
            fileno, name = tempfile.mkstemp(prefix='bzr\\prefix')
 
555
        except (IOError, OSError):
 
556
            return False
 
557
        else:
 
558
            try:
 
559
                os.stat(name)
 
560
            except (IOError, OSError):
 
561
                # mkstemp succeeded but the file wasn't actually created
 
562
                return False
 
563
            os.close(fileno)
 
564
            os.remove(name)
 
565
            return True
 
566
 
 
567
 
 
568
BackslashFilenameFeature = _BackslashFilenameFeature()
 
569
 
 
570
 
 
571
class PathFeature(Feature):
 
572
    """Feature testing whether a particular path exists."""
 
573
 
 
574
    def __init__(self, path):
 
575
        super(PathFeature, self).__init__()
 
576
        self.path = path
 
577
 
 
578
    def _probe(self):
 
579
        return os.path.exists(self.path)
502
580
 
503
581
    def feature_name(self):
504
 
        return "Terminal supports color."
505
 
 
506
 
ColorFeature = _ColorFeature()
 
582
        return "%s exists" % self.path