~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/features.py

  • Committer: Martin Pool
  • Date: 2011-07-11 06:47:32 UTC
  • mto: (6034.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 6043.
  • Revision ID: mbp@canonical.com-20110711064732-e4yhh3lyhfr045r2
Unify duplicated UnicodeFilename and _PosixPermissionsFeature

Show diffs side-by-side

added added

removed removed

Lines of Context:
202
202
HTTPSServerFeature = _HTTPSServerFeature()
203
203
 
204
204
 
205
 
class _UnicodeFilename(Feature):
206
 
    """Does the filesystem support Unicode filenames?"""
207
 
 
208
 
    def _probe(self):
209
 
        try:
210
 
            os.stat(u'\u03b1')
211
 
        except UnicodeEncodeError:
212
 
            return False
213
 
        except (IOError, OSError):
214
 
            # The filesystem allows the Unicode filename but the file doesn't
215
 
            # exist.
216
 
            return True
217
 
        else:
218
 
            # The filesystem allows the Unicode filename and the file exists,
219
 
            # for some reason.
220
 
            return True
221
 
 
222
 
UnicodeFilename = _UnicodeFilename()
223
 
 
224
 
 
225
205
class _ByteStringNamedFilesystem(Feature):
226
206
    """Is the filesystem based on bytes?"""
227
207
 
365
345
pywintypes = ModuleAvailableFeature('pywintypes')
366
346
sphinx = ModuleAvailableFeature('sphinx')
367
347
subunit = ModuleAvailableFeature('subunit')
368
 
testtools = tests.ModuleAvailableFeature('testtools')
 
348
testtools = ModuleAvailableFeature('testtools')
369
349
 
370
350
compiled_patiencediff_feature = ModuleAvailableFeature(
371
351
    'bzrlib._patiencediff_c')
389
369
backslashdir_feature = _BackslashDirSeparatorFeature()
390
370
 
391
371
 
392
 
class _PosixPermissionsFeature(Feature):
393
 
 
394
 
    def _probe(self):
395
 
        def has_perms():
396
 
            # create temporary file and check if specified perms are
397
 
            # maintained.
398
 
            write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
399
 
            f = tempfile.mkstemp(prefix='bzr_perms_chk_')
400
 
            fd, name = f
401
 
            os.close(fd)
402
 
            os.chmod(name, write_perms)
403
 
 
404
 
            read_perms = os.stat(name).st_mode & 0777
405
 
            os.unlink(name)
406
 
            return (write_perms == read_perms)
407
 
 
408
 
        return (os.name == 'posix') and has_perms()
409
 
 
410
 
    def feature_name(self):
411
 
        return 'POSIX permissions support'
412
 
 
413
 
 
414
 
posix_permissions_feature = _PosixPermissionsFeature()
415
 
 
416
 
 
417
372
class _ChownFeature(Feature):
418
373
    """os.chown is supported"""
419
374
 
516
471
AttribFeature = _AttribFeature()
517
472
 
518
473
 
519
 
class Win32Feature(tests.Feature):
 
474
class Win32Feature(Feature):
520
475
    """Feature testing whether we're running selftest on Windows
521
476
    or Windows-like platform.
522
477
    """