1804
1802
self._preserved_lazy_hooks.clear()
1806
1804
def knownFailure(self, reason):
1807
"""This test has failed for some known reason."""
1808
raise KnownFailure(reason)
1805
"""Declare that this test fails for a known reason
1807
Tests that are known to fail should generally be using expectedFailure
1808
with an appropriate reverse assertion if a change could cause the test
1809
to start passing. Conversely if the test has no immediate prospect of
1810
succeeding then using skip is more suitable.
1812
When this method is called while an exception is being handled, that
1813
traceback will be used, otherwise a new exception will be thrown to
1814
provide one but won't be reported.
1816
self._add_reason(reason)
1818
exc_info = sys.exc_info()
1819
if exc_info != (None, None, None):
1820
self._report_traceback(exc_info)
1823
raise self.failureException(reason)
1824
except self.failureException:
1825
exc_info = sys.exc_info()
1826
# GZ 02-08-2011: Maybe cleanup this err.exc_info attribute too?
1827
raise testtools.testcase._ExpectedFailure(exc_info)
1810
1831
def _suppress_log(self):
1811
1832
"""Remove the log info from details."""
2652
2673
def setUp(self):
2653
2674
super(TestCaseWithMemoryTransport, self).setUp()
2654
2675
# Ensure that ConnectedTransport doesn't leak sockets
2655
def get_transport_with_cleanup(*args, **kwargs):
2656
t = orig_get_transport(*args, **kwargs)
2676
def get_transport_from_url_with_cleanup(*args, **kwargs):
2677
t = orig_get_transport_from_url(*args, **kwargs)
2657
2678
if isinstance(t, _mod_transport.ConnectedTransport):
2658
2679
self.addCleanup(t.disconnect)
2661
orig_get_transport = self.overrideAttr(_mod_transport, 'get_transport',
2662
get_transport_with_cleanup)
2682
orig_get_transport_from_url = self.overrideAttr(
2683
_mod_transport, 'get_transport_from_url',
2684
get_transport_from_url_with_cleanup)
2663
2685
self._make_test_root()
2664
2686
self.addCleanup(os.chdir, os.getcwdu())
2665
2687
self.makeAndChdirToTestDir()
3924
3946
'bzrlib.tests.test_export',
3925
3947
'bzrlib.tests.test_export_pot',
3926
3948
'bzrlib.tests.test_extract',
3949
'bzrlib.tests.test_features',
3927
3950
'bzrlib.tests.test_fetch',
3928
3951
'bzrlib.tests.test_fixtures',
3929
3952
'bzrlib.tests.test_fifo_cache',
3930
3953
'bzrlib.tests.test_filters',
3954
'bzrlib.tests.test_filter_tree',
3931
3955
'bzrlib.tests.test_ftp_transport',
3932
3956
'bzrlib.tests.test_foreign',
3933
3957
'bzrlib.tests.test_generate_docs',
4370
4395
% (os.path.basename(dirname), printable_e))
4373
class Feature(object):
4374
"""An operating system Feature."""
4377
self._available = None
4379
def available(self):
4380
"""Is the feature available?
4382
:return: True if the feature is available.
4384
if self._available is None:
4385
self._available = self._probe()
4386
return self._available
4389
"""Implement this method in concrete features.
4391
:return: True if the feature is available.
4393
raise NotImplementedError
4396
if getattr(self, 'feature_name', None):
4397
return self.feature_name()
4398
return self.__class__.__name__
4401
class _SymlinkFeature(Feature):
4404
return osutils.has_symlinks()
4406
def feature_name(self):
4409
SymlinkFeature = _SymlinkFeature()
4412
class _HardlinkFeature(Feature):
4415
return osutils.has_hardlinks()
4417
def feature_name(self):
4420
HardlinkFeature = _HardlinkFeature()
4423
class _OsFifoFeature(Feature):
4426
return getattr(os, 'mkfifo', None)
4428
def feature_name(self):
4429
return 'filesystem fifos'
4431
OsFifoFeature = _OsFifoFeature()
4434
class _UnicodeFilenameFeature(Feature):
4435
"""Does the filesystem support Unicode filenames?"""
4439
# Check for character combinations unlikely to be covered by any
4440
# single non-unicode encoding. We use the characters
4441
# - greek small letter alpha (U+03B1) and
4442
# - braille pattern dots-123456 (U+283F).
4443
os.stat(u'\u03b1\u283f')
4444
except UnicodeEncodeError:
4446
except (IOError, OSError):
4447
# The filesystem allows the Unicode filename but the file doesn't
4451
# The filesystem allows the Unicode filename and the file exists,
4455
UnicodeFilenameFeature = _UnicodeFilenameFeature()
4458
class _CompatabilityThunkFeature(Feature):
4459
"""This feature is just a thunk to another feature.
4461
It issues a deprecation warning if it is accessed, to let you know that you
4462
should really use a different feature.
4465
def __init__(self, dep_version, module, name,
4466
replacement_name, replacement_module=None):
4467
super(_CompatabilityThunkFeature, self).__init__()
4468
self._module = module
4469
if replacement_module is None:
4470
replacement_module = module
4471
self._replacement_module = replacement_module
4473
self._replacement_name = replacement_name
4474
self._dep_version = dep_version
4475
self._feature = None
4478
if self._feature is None:
4479
depr_msg = self._dep_version % ('%s.%s'
4480
% (self._module, self._name))
4481
use_msg = ' Use %s.%s instead.' % (self._replacement_module,
4482
self._replacement_name)
4483
symbol_versioning.warn(depr_msg + use_msg, DeprecationWarning)
4484
# Import the new feature and use it as a replacement for the
4486
self._feature = pyutils.get_named_object(
4487
self._replacement_module, self._replacement_name)
4491
return self._feature._probe()
4494
class ModuleAvailableFeature(Feature):
4495
"""This is a feature than describes a module we want to be available.
4497
Declare the name of the module in __init__(), and then after probing, the
4498
module will be available as 'self.module'.
4500
:ivar module: The module if it is available, else None.
4503
def __init__(self, module_name):
4504
super(ModuleAvailableFeature, self).__init__()
4505
self.module_name = module_name
4509
self._module = __import__(self.module_name, {}, {}, [''])
4516
if self.available(): # Make sure the probe has been done
4520
def feature_name(self):
4521
return self.module_name
4524
4398
def probe_unicode_in_user_encoding():
4525
4399
"""Try to encode several unicode strings to use in unicode-aware tests.
4526
4400
Return first successfull match.
4557
class _HTTPSServerFeature(Feature):
4558
"""Some tests want an https Server, check if one is available.
4560
Right now, the only way this is available is under python2.6 which provides
4571
def feature_name(self):
4572
return 'HTTPSServer'
4575
HTTPSServerFeature = _HTTPSServerFeature()
4578
class _UnicodeFilename(Feature):
4579
"""Does the filesystem support Unicode filenames?"""
4584
except UnicodeEncodeError:
4586
except (IOError, OSError):
4587
# The filesystem allows the Unicode filename but the file doesn't
4591
# The filesystem allows the Unicode filename and the file exists,
4595
UnicodeFilename = _UnicodeFilename()
4598
class _ByteStringNamedFilesystem(Feature):
4599
"""Is the filesystem based on bytes?"""
4602
if os.name == "posix":
4606
ByteStringNamedFilesystem = _ByteStringNamedFilesystem()
4609
class _UTF8Filesystem(Feature):
4610
"""Is the filesystem UTF-8?"""
4613
if osutils._fs_enc.upper() in ('UTF-8', 'UTF8'):
4617
UTF8Filesystem = _UTF8Filesystem()
4620
class _BreakinFeature(Feature):
4621
"""Does this platform support the breakin feature?"""
4624
from bzrlib import breakin
4625
if breakin.determine_signal() is None:
4627
if sys.platform == 'win32':
4628
# Windows doesn't have os.kill, and we catch the SIGBREAK signal.
4629
# We trigger SIGBREAK via a Console api so we need ctypes to
4630
# access the function
4637
def feature_name(self):
4638
return "SIGQUIT or SIGBREAK w/ctypes on win32"
4641
BreakinFeature = _BreakinFeature()
4644
class _CaseInsCasePresFilenameFeature(Feature):
4645
"""Is the file-system case insensitive, but case-preserving?"""
4648
fileno, name = tempfile.mkstemp(prefix='MixedCase')
4650
# first check truly case-preserving for created files, then check
4651
# case insensitive when opening existing files.
4652
name = osutils.normpath(name)
4653
base, rel = osutils.split(name)
4654
found_rel = osutils.canonical_relpath(base, name)
4655
return (found_rel == rel
4656
and os.path.isfile(name.upper())
4657
and os.path.isfile(name.lower()))
4662
def feature_name(self):
4663
return "case-insensitive case-preserving filesystem"
4665
CaseInsCasePresFilenameFeature = _CaseInsCasePresFilenameFeature()
4668
class _CaseInsensitiveFilesystemFeature(Feature):
4669
"""Check if underlying filesystem is case-insensitive but *not* case
4672
# Note that on Windows, Cygwin, MacOS etc, the file-systems are far
4673
# more likely to be case preserving, so this case is rare.
4676
if CaseInsCasePresFilenameFeature.available():
4679
if TestCaseWithMemoryTransport.TEST_ROOT is None:
4680
root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
4681
TestCaseWithMemoryTransport.TEST_ROOT = root
4683
root = TestCaseWithMemoryTransport.TEST_ROOT
4684
tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
4686
name_a = osutils.pathjoin(tdir, 'a')
4687
name_A = osutils.pathjoin(tdir, 'A')
4689
result = osutils.isdir(name_A)
4690
_rmtree_temp_dir(tdir)
4693
def feature_name(self):
4694
return 'case-insensitive filesystem'
4696
CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()
4699
class _CaseSensitiveFilesystemFeature(Feature):
4702
if CaseInsCasePresFilenameFeature.available():
4704
elif CaseInsensitiveFilesystemFeature.available():
4709
def feature_name(self):
4710
return 'case-sensitive filesystem'
4712
# new coding style is for feature instances to be lowercase
4713
case_sensitive_filesystem_feature = _CaseSensitiveFilesystemFeature()
4716
4431
# Only define SubUnitBzrRunner if subunit is available.
4718
4433
from subunit import TestProtocolClient
4736
4451
except ImportError:
4739
class _PosixPermissionsFeature(Feature):
4743
# create temporary file and check if specified perms are maintained.
4746
write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
4747
f = tempfile.mkstemp(prefix='bzr_perms_chk_')
4750
os.chmod(name, write_perms)
4752
read_perms = os.stat(name).st_mode & 0777
4754
return (write_perms == read_perms)
4756
return (os.name == 'posix') and has_perms()
4758
def feature_name(self):
4759
return 'POSIX permissions support'
4761
posix_permissions_feature = _PosixPermissionsFeature()
4455
@deprecated_function(deprecated_in((2, 5, 0)))
4456
def ModuleAvailableFeature(name):
4457
from bzrlib.tests import features
4458
return features.ModuleAvailableFeature(name)