~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Andrew Bennetts
  • Date: 2009-12-18 08:22:42 UTC
  • mfrom: (4906 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4909.
  • Revision ID: andrew.bennetts@canonical.com-20091218082242-f7wy9tlk0yxvkkju
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4248
4248
UnicodeFilenameFeature = _UnicodeFilenameFeature()
4249
4249
 
4250
4250
 
 
4251
class ModuleAvailableFeature(Feature):
 
4252
    """This is a feature than describes a module we want to be available.
 
4253
 
 
4254
    Declare the name of the module in __init__(), and then after probing, the
 
4255
    module will be available as 'self.module'.
 
4256
 
 
4257
    :ivar module: The module if it is available, else None.
 
4258
    """
 
4259
 
 
4260
    def __init__(self, module_name):
 
4261
        super(ModuleAvailableFeature, self).__init__()
 
4262
        self.module_name = module_name
 
4263
 
 
4264
    def _probe(self):
 
4265
        try:
 
4266
            self._module = __import__(self.module_name, {}, {}, [''])
 
4267
            return True
 
4268
        except ImportError:
 
4269
            return False
 
4270
 
 
4271
    @property
 
4272
    def module(self):
 
4273
        if self.available(): # Make sure the probe has been done
 
4274
            return self._module
 
4275
        return None
 
4276
    
 
4277
    def feature_name(self):
 
4278
        return self.module_name
 
4279
 
 
4280
 
 
4281
 
4251
4282
def probe_unicode_in_user_encoding():
4252
4283
    """Try to encode several unicode strings to use in unicode-aware tests.
4253
4284
    Return first successfull match.