~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-22 18:18:20 UTC
  • mfrom: (4913.2.26 2.1.0rc1-module-available)
  • Revision ID: pqm@pqm.ubuntu.com-20091222181820-qfolh2sy2nevoxxj
(jam) Switch many test features over to ModuleAvailable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
from bzrlib.symbol_versioning import (
89
89
    DEPRECATED_PARAMETER,
90
90
    deprecated_function,
 
91
    deprecated_in,
91
92
    deprecated_method,
92
93
    deprecated_passed,
93
94
    )
4248
4249
UnicodeFilenameFeature = _UnicodeFilenameFeature()
4249
4250
 
4250
4251
 
 
4252
class _CompatabilityThunkFeature(Feature):
 
4253
    """This feature is just a thunk to another feature.
 
4254
 
 
4255
    It issues a deprecation warning if it is accessed, to let you know that you
 
4256
    should really use a different feature.
 
4257
    """
 
4258
 
 
4259
    def __init__(self, module, name, this_name, dep_version):
 
4260
        super(_CompatabilityThunkFeature, self).__init__()
 
4261
        self._module = module
 
4262
        self._name = name
 
4263
        self._this_name = this_name
 
4264
        self._dep_version = dep_version
 
4265
        self._feature = None
 
4266
 
 
4267
    def _ensure(self):
 
4268
        if self._feature is None:
 
4269
            msg = (self._dep_version % self._this_name) + (
 
4270
                   ' Use %s.%s instead.' % (self._module, self._name))
 
4271
            symbol_versioning.warn(msg, DeprecationWarning)
 
4272
            mod = __import__(self._module, {}, {}, [self._name])
 
4273
            self._feature = getattr(mod, self._name)
 
4274
 
 
4275
    def _probe(self):
 
4276
        self._ensure()
 
4277
        return self._feature._probe()
 
4278
 
 
4279
 
4251
4280
class ModuleAvailableFeature(Feature):
4252
4281
    """This is a feature than describes a module we want to be available.
4253
4282
 
4278
4307
        return self.module_name
4279
4308
 
4280
4309
 
 
4310
# This is kept here for compatibility, it is recommended to use
 
4311
# 'bzrlib.tests.feature.paramiko' instead
 
4312
ParamikoFeature = _CompatabilityThunkFeature('bzrlib.tests.features',
 
4313
    'paramiko', 'bzrlib.tests.ParamikoFeature', deprecated_in((2,1,0)))
 
4314
 
4281
4315
 
4282
4316
def probe_unicode_in_user_encoding():
4283
4317
    """Try to encode several unicode strings to use in unicode-aware tests.
4333
4367
HTTPSServerFeature = _HTTPSServerFeature()
4334
4368
 
4335
4369
 
4336
 
class _ParamikoFeature(Feature):
4337
 
    """Is paramiko available?"""
4338
 
 
4339
 
    def _probe(self):
4340
 
        try:
4341
 
            from bzrlib.transport.sftp import SFTPAbsoluteServer
4342
 
            return True
4343
 
        except errors.ParamikoNotPresent:
4344
 
            return False
4345
 
 
4346
 
    def feature_name(self):
4347
 
        return "Paramiko"
4348
 
 
4349
 
 
4350
 
ParamikoFeature = _ParamikoFeature()
4351
 
 
4352
 
 
4353
4370
class _UnicodeFilename(Feature):
4354
4371
    """Does the filesystem support Unicode filenames?"""
4355
4372
 
4460
4477
CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()
4461
4478
 
4462
4479
 
4463
 
class _SubUnitFeature(Feature):
4464
 
    """Check if subunit is available."""
4465
 
 
4466
 
    def _probe(self):
4467
 
        try:
4468
 
            import subunit
4469
 
            return True
4470
 
        except ImportError:
4471
 
            return False
4472
 
 
4473
 
    def feature_name(self):
4474
 
        return 'subunit'
4475
 
 
4476
 
SubUnitFeature = _SubUnitFeature()
 
4480
# Kept for compatibility, use bzrlib.tests.features.subunit instead
 
4481
SubUnitFeature = _CompatabilityThunkFeature('bzrlib.tests.features', 'subunit',
 
4482
    'bzrlib.tests.SubUnitFeature', deprecated_in((2,1,0)))
4477
4483
# Only define SubUnitBzrRunner if subunit is available.
4478
4484
try:
4479
4485
    from subunit import TestProtocolClient