1804
1809
self._preserved_lazy_hooks.clear()
1806
1811
def knownFailure(self, reason):
1807
"""This test has failed for some known reason."""
1808
raise KnownFailure(reason)
1812
"""Declare that this test fails for a known reason
1814
Tests that are known to fail should generally be using expectedFailure
1815
with an appropriate reverse assertion if a change could cause the test
1816
to start passing. Conversely if the test has no immediate prospect of
1817
succeeding then using skip is more suitable.
1819
When this method is called while an exception is being handled, that
1820
traceback will be used, otherwise a new exception will be thrown to
1821
provide one but won't be reported.
1823
self._add_reason(reason)
1825
exc_info = sys.exc_info()
1826
if exc_info != (None, None, None):
1827
self._report_traceback(exc_info)
1830
raise self.failureException(reason)
1831
except self.failureException:
1832
exc_info = sys.exc_info()
1833
# GZ 02-08-2011: Maybe cleanup this err.exc_info attribute too?
1834
raise testtools.testcase._ExpectedFailure(exc_info)
1810
1838
def _suppress_log(self):
1811
1839
"""Remove the log info from details."""
2603
2632
def make_branch(self, relpath, format=None):
2604
2633
"""Create a branch on the transport at relpath."""
2605
2634
repo = self.make_repository(relpath, format=format)
2606
return repo.bzrdir.create_branch()
2635
return repo.bzrdir.create_branch(append_revisions_only=False)
2637
def get_default_format(self):
2640
def resolve_format(self, format):
2641
"""Resolve an object to a ControlDir format object.
2643
The initial format object can either already be
2644
a ControlDirFormat, None (for the default format),
2645
or a string with the name of the control dir format.
2647
:param format: Object to resolve
2648
:return A ControlDirFormat instance
2651
format = self.get_default_format()
2652
if isinstance(format, basestring):
2653
format = bzrdir.format_registry.make_bzrdir(format)
2608
2656
def make_bzrdir(self, relpath, format=None):
2613
2661
t = _mod_transport.get_transport(maybe_a_url)
2614
2662
if len(segments) > 1 and segments[-1] not in ('', '.'):
2615
2663
t.ensure_base()
2618
if isinstance(format, basestring):
2619
format = bzrdir.format_registry.make_bzrdir(format)
2664
format = self.resolve_format(format)
2620
2665
return format.initialize_on_transport(t)
2621
2666
except errors.UninitializableFormat:
2622
2667
raise TestSkipped("Format %s is not initializable." % format)
2624
def make_repository(self, relpath, shared=False, format=None):
2669
def make_repository(self, relpath, shared=None, format=None):
2625
2670
"""Create a repository on our default transport at relpath.
2627
2672
Note that relpath must be a relative path, not a full url.
2661
2706
def setUp(self):
2662
2707
super(TestCaseWithMemoryTransport, self).setUp()
2663
2708
# Ensure that ConnectedTransport doesn't leak sockets
2664
def get_transport_with_cleanup(*args, **kwargs):
2665
t = orig_get_transport(*args, **kwargs)
2709
def get_transport_from_url_with_cleanup(*args, **kwargs):
2710
t = orig_get_transport_from_url(*args, **kwargs)
2666
2711
if isinstance(t, _mod_transport.ConnectedTransport):
2667
2712
self.addCleanup(t.disconnect)
2670
orig_get_transport = self.overrideAttr(_mod_transport, 'get_transport',
2671
get_transport_with_cleanup)
2715
orig_get_transport_from_url = self.overrideAttr(
2716
_mod_transport, 'get_transport_from_url',
2717
get_transport_from_url_with_cleanup)
2672
2718
self._make_test_root()
2673
2719
self.addCleanup(os.chdir, os.getcwdu())
2674
2720
self.makeAndChdirToTestDir()
3930
3977
'bzrlib.tests.test_email_message',
3931
3978
'bzrlib.tests.test_eol_filters',
3932
3979
'bzrlib.tests.test_errors',
3980
'bzrlib.tests.test_estimate_compressed_size',
3933
3981
'bzrlib.tests.test_export',
3934
3982
'bzrlib.tests.test_export_pot',
3935
3983
'bzrlib.tests.test_extract',
3984
'bzrlib.tests.test_features',
3936
3985
'bzrlib.tests.test_fetch',
3937
3986
'bzrlib.tests.test_fixtures',
3938
3987
'bzrlib.tests.test_fifo_cache',
3939
3988
'bzrlib.tests.test_filters',
3989
'bzrlib.tests.test_filter_tree',
3940
3990
'bzrlib.tests.test_ftp_transport',
3941
3991
'bzrlib.tests.test_foreign',
3942
3992
'bzrlib.tests.test_generate_docs',
4379
4431
% (os.path.basename(dirname), printable_e))
4382
class Feature(object):
4383
"""An operating system Feature."""
4386
self._available = None
4388
def available(self):
4389
"""Is the feature available?
4391
:return: True if the feature is available.
4393
if self._available is None:
4394
self._available = self._probe()
4395
return self._available
4398
"""Implement this method in concrete features.
4400
:return: True if the feature is available.
4402
raise NotImplementedError
4405
if getattr(self, 'feature_name', None):
4406
return self.feature_name()
4407
return self.__class__.__name__
4410
class _SymlinkFeature(Feature):
4413
return osutils.has_symlinks()
4415
def feature_name(self):
4418
SymlinkFeature = _SymlinkFeature()
4421
class _HardlinkFeature(Feature):
4424
return osutils.has_hardlinks()
4426
def feature_name(self):
4429
HardlinkFeature = _HardlinkFeature()
4432
class _OsFifoFeature(Feature):
4435
return getattr(os, 'mkfifo', None)
4437
def feature_name(self):
4438
return 'filesystem fifos'
4440
OsFifoFeature = _OsFifoFeature()
4443
class _UnicodeFilenameFeature(Feature):
4444
"""Does the filesystem support Unicode filenames?"""
4448
# Check for character combinations unlikely to be covered by any
4449
# single non-unicode encoding. We use the characters
4450
# - greek small letter alpha (U+03B1) and
4451
# - braille pattern dots-123456 (U+283F).
4452
os.stat(u'\u03b1\u283f')
4453
except UnicodeEncodeError:
4455
except (IOError, OSError):
4456
# The filesystem allows the Unicode filename but the file doesn't
4460
# The filesystem allows the Unicode filename and the file exists,
4464
UnicodeFilenameFeature = _UnicodeFilenameFeature()
4467
class _CompatabilityThunkFeature(Feature):
4468
"""This feature is just a thunk to another feature.
4470
It issues a deprecation warning if it is accessed, to let you know that you
4471
should really use a different feature.
4474
def __init__(self, dep_version, module, name,
4475
replacement_name, replacement_module=None):
4476
super(_CompatabilityThunkFeature, self).__init__()
4477
self._module = module
4478
if replacement_module is None:
4479
replacement_module = module
4480
self._replacement_module = replacement_module
4482
self._replacement_name = replacement_name
4483
self._dep_version = dep_version
4484
self._feature = None
4487
if self._feature is None:
4488
depr_msg = self._dep_version % ('%s.%s'
4489
% (self._module, self._name))
4490
use_msg = ' Use %s.%s instead.' % (self._replacement_module,
4491
self._replacement_name)
4492
symbol_versioning.warn(depr_msg + use_msg, DeprecationWarning)
4493
# Import the new feature and use it as a replacement for the
4495
self._feature = pyutils.get_named_object(
4496
self._replacement_module, self._replacement_name)
4500
return self._feature._probe()
4503
class ModuleAvailableFeature(Feature):
4504
"""This is a feature than describes a module we want to be available.
4506
Declare the name of the module in __init__(), and then after probing, the
4507
module will be available as 'self.module'.
4509
:ivar module: The module if it is available, else None.
4512
def __init__(self, module_name):
4513
super(ModuleAvailableFeature, self).__init__()
4514
self.module_name = module_name
4518
self._module = __import__(self.module_name, {}, {}, [''])
4525
if self.available(): # Make sure the probe has been done
4529
def feature_name(self):
4530
return self.module_name
4533
4434
def probe_unicode_in_user_encoding():
4534
4435
"""Try to encode several unicode strings to use in unicode-aware tests.
4535
4436
Return first successfull match.
4566
class _HTTPSServerFeature(Feature):
4567
"""Some tests want an https Server, check if one is available.
4569
Right now, the only way this is available is under python2.6 which provides
4580
def feature_name(self):
4581
return 'HTTPSServer'
4584
HTTPSServerFeature = _HTTPSServerFeature()
4587
class _UnicodeFilename(Feature):
4588
"""Does the filesystem support Unicode filenames?"""
4593
except UnicodeEncodeError:
4595
except (IOError, OSError):
4596
# The filesystem allows the Unicode filename but the file doesn't
4600
# The filesystem allows the Unicode filename and the file exists,
4604
UnicodeFilename = _UnicodeFilename()
4607
class _ByteStringNamedFilesystem(Feature):
4608
"""Is the filesystem based on bytes?"""
4611
if os.name == "posix":
4615
ByteStringNamedFilesystem = _ByteStringNamedFilesystem()
4618
class _UTF8Filesystem(Feature):
4619
"""Is the filesystem UTF-8?"""
4622
if osutils._fs_enc.upper() in ('UTF-8', 'UTF8'):
4626
UTF8Filesystem = _UTF8Filesystem()
4629
class _BreakinFeature(Feature):
4630
"""Does this platform support the breakin feature?"""
4633
from bzrlib import breakin
4634
if breakin.determine_signal() is None:
4636
if sys.platform == 'win32':
4637
# Windows doesn't have os.kill, and we catch the SIGBREAK signal.
4638
# We trigger SIGBREAK via a Console api so we need ctypes to
4639
# access the function
4646
def feature_name(self):
4647
return "SIGQUIT or SIGBREAK w/ctypes on win32"
4650
BreakinFeature = _BreakinFeature()
4653
class _CaseInsCasePresFilenameFeature(Feature):
4654
"""Is the file-system case insensitive, but case-preserving?"""
4657
fileno, name = tempfile.mkstemp(prefix='MixedCase')
4659
# first check truly case-preserving for created files, then check
4660
# case insensitive when opening existing files.
4661
name = osutils.normpath(name)
4662
base, rel = osutils.split(name)
4663
found_rel = osutils.canonical_relpath(base, name)
4664
return (found_rel == rel
4665
and os.path.isfile(name.upper())
4666
and os.path.isfile(name.lower()))
4671
def feature_name(self):
4672
return "case-insensitive case-preserving filesystem"
4674
CaseInsCasePresFilenameFeature = _CaseInsCasePresFilenameFeature()
4677
class _CaseInsensitiveFilesystemFeature(Feature):
4678
"""Check if underlying filesystem is case-insensitive but *not* case
4681
# Note that on Windows, Cygwin, MacOS etc, the file-systems are far
4682
# more likely to be case preserving, so this case is rare.
4685
if CaseInsCasePresFilenameFeature.available():
4688
if TestCaseWithMemoryTransport.TEST_ROOT is None:
4689
root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
4690
TestCaseWithMemoryTransport.TEST_ROOT = root
4692
root = TestCaseWithMemoryTransport.TEST_ROOT
4693
tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
4695
name_a = osutils.pathjoin(tdir, 'a')
4696
name_A = osutils.pathjoin(tdir, 'A')
4698
result = osutils.isdir(name_A)
4699
_rmtree_temp_dir(tdir)
4702
def feature_name(self):
4703
return 'case-insensitive filesystem'
4705
CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()
4708
class _CaseSensitiveFilesystemFeature(Feature):
4711
if CaseInsCasePresFilenameFeature.available():
4713
elif CaseInsensitiveFilesystemFeature.available():
4718
def feature_name(self):
4719
return 'case-sensitive filesystem'
4721
# new coding style is for feature instances to be lowercase
4722
case_sensitive_filesystem_feature = _CaseSensitiveFilesystemFeature()
4725
4467
# Only define SubUnitBzrRunner if subunit is available.
4727
4469
from subunit import TestProtocolClient
4745
4487
except ImportError:
4748
class _PosixPermissionsFeature(Feature):
4752
# create temporary file and check if specified perms are maintained.
4755
write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
4756
f = tempfile.mkstemp(prefix='bzr_perms_chk_')
4759
os.chmod(name, write_perms)
4761
read_perms = os.stat(name).st_mode & 0777
4763
return (write_perms == read_perms)
4765
return (os.name == 'posix') and has_perms()
4767
def feature_name(self):
4768
return 'POSIX permissions support'
4770
posix_permissions_feature = _PosixPermissionsFeature()
4491
@deprecated_function(deprecated_in((2, 5, 0)))
4492
def ModuleAvailableFeature(name):
4493
from bzrlib.tests import features
4494
return features.ModuleAvailableFeature(name)