1507
1741
:returns: The actual attr value.
1509
value = getattr(obj, attr_name)
1510
1743
# The actual value is captured by the call below
1511
self.addCleanup(setattr, obj, attr_name, value)
1744
value = getattr(obj, attr_name, _unitialized_attr)
1745
if value is _unitialized_attr:
1746
# When the test completes, the attribute should not exist, but if
1747
# we aren't setting a value, we don't need to do anything.
1748
if new is not _unitialized_attr:
1749
self.addCleanup(delattr, obj, attr_name)
1751
self.addCleanup(setattr, obj, attr_name, value)
1512
1752
if new is not _unitialized_attr:
1513
1753
setattr(obj, attr_name, new)
1756
def overrideEnv(self, name, new):
1757
"""Set an environment variable, and reset it after the test.
1759
:param name: The environment variable name.
1761
:param new: The value to set the variable to. If None, the
1762
variable is deleted from the environment.
1764
:returns: The actual variable value.
1766
value = osutils.set_or_unset_env(name, new)
1767
self.addCleanup(osutils.set_or_unset_env, name, value)
1770
def recordCalls(self, obj, attr_name):
1771
"""Monkeypatch in a wrapper that will record calls.
1773
The monkeypatch is automatically removed when the test concludes.
1775
:param obj: The namespace holding the reference to be replaced;
1776
typically a module, class, or object.
1777
:param attr_name: A string for the name of the attribute to patch.
1778
:returns: A list that will be extended with one item every time the
1779
function is called, with a tuple of (args, kwargs).
1783
def decorator(*args, **kwargs):
1784
calls.append((args, kwargs))
1785
return orig(*args, **kwargs)
1786
orig = self.overrideAttr(obj, attr_name, decorator)
1516
1789
def _cleanEnvironment(self):
1518
'BZR_HOME': None, # Don't inherit BZR_HOME to all the tests.
1519
'HOME': os.getcwd(),
1520
# bzr now uses the Win32 API and doesn't rely on APPDATA, but the
1521
# tests do check our impls match APPDATA
1522
'BZR_EDITOR': None, # test_msgeditor manipulates this variable
1526
'BZREMAIL': None, # may still be present in the environment
1528
'BZR_PROGRESS_BAR': None,
1530
'BZR_PLUGIN_PATH': None,
1531
'BZR_DISABLE_PLUGINS': None,
1532
'BZR_PLUGINS_AT': None,
1533
'BZR_CONCURRENCY': None,
1534
# Make sure that any text ui tests are consistent regardless of
1535
# the environment the test case is run in; you may want tests that
1536
# test other combinations. 'dumb' is a reasonable guess for tests
1537
# going to a pipe or a StringIO.
1541
'BZR_COLUMNS': '80',
1543
'SSH_AUTH_SOCK': None,
1547
'https_proxy': None,
1548
'HTTPS_PROXY': None,
1553
# Nobody cares about ftp_proxy, FTP_PROXY AFAIK. So far at
1554
# least. If you do (care), please update this comment
1558
'BZR_REMOTE_PATH': None,
1559
# Generally speaking, we don't want apport reporting on crashes in
1560
# the test envirnoment unless we're specifically testing apport,
1561
# so that it doesn't leak into the real system environment. We
1562
# use an env var so it propagates to subprocesses.
1563
'APPORT_DISABLE': '1',
1566
self.addCleanup(self._restoreEnvironment)
1567
for name, value in new_env.iteritems():
1568
self._captureVar(name, value)
1570
def _captureVar(self, name, newvalue):
1571
"""Set an environment variable, and reset it when finished."""
1572
self._old_env[name] = osutils.set_or_unset_env(name, newvalue)
1574
def _restoreEnvironment(self):
1575
for name, value in self._old_env.iteritems():
1576
osutils.set_or_unset_env(name, value)
1790
for name, value in isolated_environ.items():
1791
self.overrideEnv(name, value)
1578
1793
def _restoreHooks(self):
1579
1794
for klass, (name, hooks) in self._preserved_hooks.items():
1580
1795
setattr(klass, name, hooks)
1796
self._preserved_hooks.clear()
1797
breezy.hooks._lazy_hooks = self._preserved_lazy_hooks
1798
self._preserved_lazy_hooks.clear()
1582
1800
def knownFailure(self, reason):
1583
"""This test has failed for some known reason."""
1584
raise KnownFailure(reason)
1801
"""Declare that this test fails for a known reason
1803
Tests that are known to fail should generally be using expectedFailure
1804
with an appropriate reverse assertion if a change could cause the test
1805
to start passing. Conversely if the test has no immediate prospect of
1806
succeeding then using skip is more suitable.
1808
When this method is called while an exception is being handled, that
1809
traceback will be used, otherwise a new exception will be thrown to
1810
provide one but won't be reported.
1812
self._add_reason(reason)
1814
exc_info = sys.exc_info()
1815
if exc_info != (None, None, None):
1816
self._report_traceback(exc_info)
1819
raise self.failureException(reason)
1820
except self.failureException:
1821
exc_info = sys.exc_info()
1822
# GZ 02-08-2011: Maybe cleanup this err.exc_info attribute too?
1823
raise testtools.testcase._ExpectedFailure(exc_info)
1827
def _suppress_log(self):
1828
"""Remove the log info from details."""
1829
self.discardDetail('log')
1586
1831
def _do_skip(self, result, reason):
1832
self._suppress_log()
1587
1833
addSkip = getattr(result, 'addSkip', None)
1588
1834
if not callable(addSkip):
1589
1835
result.addSuccess(result)
1591
addSkip(self, reason)
1837
addSkip(self, str(reason))
1594
1840
def _do_known_failure(self, result, e):
1841
self._suppress_log()
1595
1842
err = sys.exc_info()
1596
1843
addExpectedFailure = getattr(result, 'addExpectedFailure', None)
1597
1844
if addExpectedFailure is not None:
1779
1959
os.chdir(working_dir)
1783
result = self.apply_redirected(ui.ui_factory.stdin,
1963
result = self.apply_redirected(
1964
ui.ui_factory.stdin,
1784
1965
stdout, stderr,
1785
bzrlib.commands.run_bzr_catch_user_errors,
1966
_mod_commands.run_bzr_catch_user_errors,
1787
except KeyboardInterrupt:
1788
# Reraise KeyboardInterrupt with contents of redirected stdout
1789
# and stderr as arguments, for tests which are interested in
1790
# stdout and stderr and are expecting the exception.
1791
out = stdout.getvalue()
1792
err = stderr.getvalue()
1794
self.log('output:\n%r', out)
1796
self.log('errors:\n%r', err)
1797
raise KeyboardInterrupt(out, err)
1799
logger.removeHandler(handler)
1800
1969
ui.ui_factory = old_ui_factory
1801
1970
if cwd is not None:
1804
out = stdout.getvalue()
1805
err = stderr.getvalue()
1807
self.log('output:\n%r', out)
1809
self.log('errors:\n%r', err)
1810
if retcode is not None:
1811
self.assertEquals(retcode, result,
1812
message='Unexpected return code')
1813
return result, out, err
1815
def run_bzr(self, args, retcode=0, encoding=None, stdin=None,
1816
working_dir=None, error_regexes=[], output_encoding=None):
1817
"""Invoke bzr, as if it were run from the command line.
1819
The argument list should not include the bzr program name - the
1820
first argument is normally the bzr command. Arguments may be
1821
passed in three ways:
1823
1- A list of strings, eg ["commit", "a"]. This is recommended
1824
when the command contains whitespace or metacharacters, or
1825
is built up at run time.
1827
2- A single string, eg "add a". This is the most convenient
1828
for hardcoded commands.
1830
This runs bzr through the interface that catches and reports
1831
errors, and with logging set to something approximating the
1832
default, so that error reporting can be checked.
1834
This should be the main method for tests that want to exercise the
1835
overall behavior of the bzr application (rather than a unit test
1836
or a functional test of the library.)
1838
This sends the stdout/stderr results into the test's log,
1839
where it may be useful for debugging. See also run_captured.
1841
:keyword stdin: A string to be used as stdin for the command.
1842
:keyword retcode: The status code the command should return;
1844
:keyword working_dir: The directory to run the command in
1845
:keyword error_regexes: A list of expected error messages. If
1846
specified they must be seen in the error output of the command.
1848
retcode, out, err = self._run_bzr_autosplit(
1853
working_dir=working_dir,
1975
def run_bzr_raw(self, args, retcode=0, stdin=None, encoding=None,
1976
working_dir=None, error_regexes=[]):
1977
"""Invoke brz, as if it were run from the command line.
1979
The argument list should not include the brz program name - the
1980
first argument is normally the brz command. Arguments may be
1981
passed in three ways:
1983
1- A list of strings, eg ["commit", "a"]. This is recommended
1984
when the command contains whitespace or metacharacters, or
1985
is built up at run time.
1987
2- A single string, eg "add a". This is the most convenient
1988
for hardcoded commands.
1990
This runs brz through the interface that catches and reports
1991
errors, and with logging set to something approximating the
1992
default, so that error reporting can be checked.
1994
This should be the main method for tests that want to exercise the
1995
overall behavior of the brz application (rather than a unit test
1996
or a functional test of the library.)
1998
This sends the stdout/stderr results into the test's log,
1999
where it may be useful for debugging. See also run_captured.
2001
:keyword stdin: A string to be used as stdin for the command.
2002
:keyword retcode: The status code the command should return;
2004
:keyword working_dir: The directory to run the command in
2005
:keyword error_regexes: A list of expected error messages. If
2006
specified they must be seen in the error output of the command.
2008
if isinstance(args, string_types):
2009
args = shlex.split(args)
2011
if encoding is None:
2012
encoding = osutils.get_user_encoding()
2014
if sys.version_info[0] == 2:
2015
wrapped_stdout = stdout = ui_testing.BytesIOWithEncoding()
2016
wrapped_stderr = stderr = ui_testing.BytesIOWithEncoding()
2017
stdout.encoding = stderr.encoding = encoding
2019
# FIXME: don't call into logging here
2020
handler = trace.EncodedStreamHandler(
2021
stderr, errors="replace")
2025
wrapped_stdout = TextIOWrapper(stdout, encoding)
2026
wrapped_stderr = TextIOWrapper(stderr, encoding)
2027
handler = logging.StreamHandler(wrapped_stderr)
2028
handler.setLevel(logging.INFO)
2030
logger = logging.getLogger('')
2031
logger.addHandler(handler)
2033
result = self._run_bzr_core(
2034
args, encoding=encoding, stdin=stdin, stdout=wrapped_stdout,
2035
stderr=wrapped_stderr, working_dir=working_dir,
2038
logger.removeHandler(handler)
2041
wrapped_stdout.flush()
2042
wrapped_stderr.flush()
2044
out = stdout.getvalue()
2045
err = stderr.getvalue()
2047
self.log('output:\n%r', out)
2049
self.log('errors:\n%r', err)
2050
if retcode is not None:
2051
self.assertEqual(retcode, result,
2052
message='Unexpected return code')
2053
self.assertIsInstance(error_regexes, (list, tuple))
2054
for regex in error_regexes:
2055
self.assertContainsRe(err, regex)
2058
def run_bzr(self, args, retcode=0, stdin=None, encoding=None,
2059
working_dir=None, error_regexes=[]):
2060
"""Invoke brz, as if it were run from the command line.
2062
The argument list should not include the brz program name - the
2063
first argument is normally the brz command. Arguments may be
2064
passed in three ways:
2066
1- A list of strings, eg ["commit", "a"]. This is recommended
2067
when the command contains whitespace or metacharacters, or
2068
is built up at run time.
2070
2- A single string, eg "add a". This is the most convenient
2071
for hardcoded commands.
2073
This runs brz through the interface that catches and reports
2074
errors, and with logging set to something approximating the
2075
default, so that error reporting can be checked.
2077
This should be the main method for tests that want to exercise the
2078
overall behavior of the brz application (rather than a unit test
2079
or a functional test of the library.)
2081
This sends the stdout/stderr results into the test's log,
2082
where it may be useful for debugging. See also run_captured.
2084
:keyword stdin: A string to be used as stdin for the command.
2085
:keyword retcode: The status code the command should return;
2087
:keyword working_dir: The directory to run the command in
2088
:keyword error_regexes: A list of expected error messages. If
2089
specified they must be seen in the error output of the command.
2091
if isinstance(args, string_types):
2092
args = shlex.split(args)
2094
if encoding is None:
2095
encoding = osutils.get_user_encoding()
2097
if sys.version_info[0] == 2:
2098
stdout = ui_testing.BytesIOWithEncoding()
2099
stderr = ui_testing.BytesIOWithEncoding()
2100
stdout.encoding = stderr.encoding = encoding
2101
# FIXME: don't call into logging here
2102
handler = trace.EncodedStreamHandler(
2103
stderr, errors="replace")
2105
stdout = ui_testing.StringIOWithEncoding()
2106
stderr = ui_testing.StringIOWithEncoding()
2107
stdout.encoding = stderr.encoding = encoding
2108
handler = logging.StreamHandler(stream=stderr)
2109
handler.setLevel(logging.INFO)
2111
logger = logging.getLogger('')
2112
logger.addHandler(handler)
2115
result = self._run_bzr_core(
2116
args, encoding=encoding, stdin=stdin, stdout=stdout,
2117
stderr=stderr, working_dir=working_dir)
2119
logger.removeHandler(handler)
2121
out = stdout.getvalue()
2122
err = stderr.getvalue()
2124
self.log('output:\n%r', out)
2126
self.log('errors:\n%r', err)
2127
if retcode is not None:
2128
self.assertEqual(retcode, result,
2129
message='Unexpected return code')
1855
2130
self.assertIsInstance(error_regexes, (list, tuple))
1856
2131
for regex in error_regexes:
1857
2132
self.assertContainsRe(err, regex)
1858
2133
return out, err
1860
2135
def run_bzr_error(self, error_regexes, *args, **kwargs):
1861
"""Run bzr, and check that stderr contains the supplied regexes
2136
"""Run brz, and check that stderr contains the supplied regexes
1863
2138
:param error_regexes: Sequence of regular expressions which
1864
2139
must each be found in the error output. The relative ordering
1865
2140
is not enforced.
1866
:param args: command-line arguments for bzr
1867
:param kwargs: Keyword arguments which are interpreted by run_bzr
2141
:param args: command-line arguments for brz
2142
:param kwargs: Keyword arguments which are interpreted by run_brz
1868
2143
This function changes the default value of retcode to be 3,
1869
since in most cases this is run when you expect bzr to fail.
2144
since in most cases this is run when you expect brz to fail.
1871
2146
:return: (out, err) The actual output of running the command (in case
1872
2147
you want to do more inspection)
3617
3989
# This alias allows to detect typos ('bzrlin.') by making all valid test ids
3618
# appear prefixed ('bzrlib.' is "replaced" by 'bzrlib.').
3619
test_prefix_alias_registry.register('bzrlib', 'bzrlib')
3990
# appear prefixed ('breezy.' is "replaced" by 'breezy.').
3991
test_prefix_alias_registry.register('breezy', 'breezy')
3621
3993
# Obvious highest levels prefixes, feel free to add your own via a plugin
3622
test_prefix_alias_registry.register('bd', 'bzrlib.doc')
3623
test_prefix_alias_registry.register('bu', 'bzrlib.utils')
3624
test_prefix_alias_registry.register('bt', 'bzrlib.tests')
3625
test_prefix_alias_registry.register('bb', 'bzrlib.tests.blackbox')
3626
test_prefix_alias_registry.register('bp', 'bzrlib.plugins')
3994
test_prefix_alias_registry.register('bd', 'breezy.doc')
3995
test_prefix_alias_registry.register('bu', 'breezy.utils')
3996
test_prefix_alias_registry.register('bt', 'breezy.tests')
3997
test_prefix_alias_registry.register('bgt', 'breezy.git.tests')
3998
test_prefix_alias_registry.register('bbt', 'breezy.bzr.tests')
3999
test_prefix_alias_registry.register('bb', 'breezy.tests.blackbox')
4000
test_prefix_alias_registry.register('bp', 'breezy.plugins')
3629
4003
def _test_suite_testmod_names():
3630
4004
"""Return the standard list of test module names to test."""
3633
'bzrlib.tests.blackbox',
3634
'bzrlib.tests.commands',
3635
'bzrlib.tests.per_branch',
3636
'bzrlib.tests.per_bzrdir',
3637
'bzrlib.tests.per_bzrdir_colo',
3638
'bzrlib.tests.per_foreign_vcs',
3639
'bzrlib.tests.per_interrepository',
3640
'bzrlib.tests.per_intertree',
3641
'bzrlib.tests.per_inventory',
3642
'bzrlib.tests.per_interbranch',
3643
'bzrlib.tests.per_lock',
3644
'bzrlib.tests.per_merger',
3645
'bzrlib.tests.per_transport',
3646
'bzrlib.tests.per_tree',
3647
'bzrlib.tests.per_pack_repository',
3648
'bzrlib.tests.per_repository',
3649
'bzrlib.tests.per_repository_chk',
3650
'bzrlib.tests.per_repository_reference',
3651
'bzrlib.tests.per_uifactory',
3652
'bzrlib.tests.per_versionedfile',
3653
'bzrlib.tests.per_workingtree',
3654
'bzrlib.tests.test__annotator',
3655
'bzrlib.tests.test__bencode',
3656
'bzrlib.tests.test__chk_map',
3657
'bzrlib.tests.test__dirstate_helpers',
3658
'bzrlib.tests.test__groupcompress',
3659
'bzrlib.tests.test__known_graph',
3660
'bzrlib.tests.test__rio',
3661
'bzrlib.tests.test__simple_set',
3662
'bzrlib.tests.test__static_tuple',
3663
'bzrlib.tests.test__walkdirs_win32',
3664
'bzrlib.tests.test_ancestry',
3665
'bzrlib.tests.test_annotate',
3666
'bzrlib.tests.test_api',
3667
'bzrlib.tests.test_atomicfile',
3668
'bzrlib.tests.test_bad_files',
3669
'bzrlib.tests.test_bisect_multi',
3670
'bzrlib.tests.test_branch',
3671
'bzrlib.tests.test_branchbuilder',
3672
'bzrlib.tests.test_btree_index',
3673
'bzrlib.tests.test_bugtracker',
3674
'bzrlib.tests.test_bundle',
3675
'bzrlib.tests.test_bzrdir',
3676
'bzrlib.tests.test__chunks_to_lines',
3677
'bzrlib.tests.test_cache_utf8',
3678
'bzrlib.tests.test_chk_map',
3679
'bzrlib.tests.test_chk_serializer',
3680
'bzrlib.tests.test_chunk_writer',
3681
'bzrlib.tests.test_clean_tree',
3682
'bzrlib.tests.test_cleanup',
3683
'bzrlib.tests.test_cmdline',
3684
'bzrlib.tests.test_commands',
3685
'bzrlib.tests.test_commit',
3686
'bzrlib.tests.test_commit_merge',
3687
'bzrlib.tests.test_config',
3688
'bzrlib.tests.test_conflicts',
3689
'bzrlib.tests.test_counted_lock',
3690
'bzrlib.tests.test_crash',
3691
'bzrlib.tests.test_decorators',
3692
'bzrlib.tests.test_delta',
3693
'bzrlib.tests.test_debug',
3694
'bzrlib.tests.test_deprecated_graph',
3695
'bzrlib.tests.test_diff',
3696
'bzrlib.tests.test_directory_service',
3697
'bzrlib.tests.test_dirstate',
3698
'bzrlib.tests.test_email_message',
3699
'bzrlib.tests.test_eol_filters',
3700
'bzrlib.tests.test_errors',
3701
'bzrlib.tests.test_export',
3702
'bzrlib.tests.test_extract',
3703
'bzrlib.tests.test_fetch',
3704
'bzrlib.tests.test_fifo_cache',
3705
'bzrlib.tests.test_filters',
3706
'bzrlib.tests.test_ftp_transport',
3707
'bzrlib.tests.test_foreign',
3708
'bzrlib.tests.test_generate_docs',
3709
'bzrlib.tests.test_generate_ids',
3710
'bzrlib.tests.test_globbing',
3711
'bzrlib.tests.test_gpg',
3712
'bzrlib.tests.test_graph',
3713
'bzrlib.tests.test_groupcompress',
3714
'bzrlib.tests.test_hashcache',
3715
'bzrlib.tests.test_help',
3716
'bzrlib.tests.test_hooks',
3717
'bzrlib.tests.test_http',
3718
'bzrlib.tests.test_http_response',
3719
'bzrlib.tests.test_https_ca_bundle',
3720
'bzrlib.tests.test_identitymap',
3721
'bzrlib.tests.test_ignores',
3722
'bzrlib.tests.test_index',
3723
'bzrlib.tests.test_import_tariff',
3724
'bzrlib.tests.test_info',
3725
'bzrlib.tests.test_inv',
3726
'bzrlib.tests.test_inventory_delta',
3727
'bzrlib.tests.test_knit',
3728
'bzrlib.tests.test_lazy_import',
3729
'bzrlib.tests.test_lazy_regex',
3730
'bzrlib.tests.test_lock',
3731
'bzrlib.tests.test_lockable_files',
3732
'bzrlib.tests.test_lockdir',
3733
'bzrlib.tests.test_log',
3734
'bzrlib.tests.test_lru_cache',
3735
'bzrlib.tests.test_lsprof',
3736
'bzrlib.tests.test_mail_client',
3737
'bzrlib.tests.test_matchers',
3738
'bzrlib.tests.test_memorytree',
3739
'bzrlib.tests.test_merge',
3740
'bzrlib.tests.test_merge3',
3741
'bzrlib.tests.test_merge_core',
3742
'bzrlib.tests.test_merge_directive',
3743
'bzrlib.tests.test_missing',
3744
'bzrlib.tests.test_msgeditor',
3745
'bzrlib.tests.test_multiparent',
3746
'bzrlib.tests.test_mutabletree',
3747
'bzrlib.tests.test_nonascii',
3748
'bzrlib.tests.test_options',
3749
'bzrlib.tests.test_osutils',
3750
'bzrlib.tests.test_osutils_encodings',
3751
'bzrlib.tests.test_pack',
3752
'bzrlib.tests.test_patch',
3753
'bzrlib.tests.test_patches',
3754
'bzrlib.tests.test_permissions',
3755
'bzrlib.tests.test_plugins',
3756
'bzrlib.tests.test_progress',
3757
'bzrlib.tests.test_read_bundle',
3758
'bzrlib.tests.test_reconcile',
3759
'bzrlib.tests.test_reconfigure',
3760
'bzrlib.tests.test_registry',
3761
'bzrlib.tests.test_remote',
3762
'bzrlib.tests.test_rename_map',
3763
'bzrlib.tests.test_repository',
3764
'bzrlib.tests.test_revert',
3765
'bzrlib.tests.test_revision',
3766
'bzrlib.tests.test_revisionspec',
3767
'bzrlib.tests.test_revisiontree',
3768
'bzrlib.tests.test_rio',
3769
'bzrlib.tests.test_rules',
3770
'bzrlib.tests.test_sampler',
3771
'bzrlib.tests.test_script',
3772
'bzrlib.tests.test_selftest',
3773
'bzrlib.tests.test_serializer',
3774
'bzrlib.tests.test_setup',
3775
'bzrlib.tests.test_sftp_transport',
3776
'bzrlib.tests.test_shelf',
3777
'bzrlib.tests.test_shelf_ui',
3778
'bzrlib.tests.test_smart',
3779
'bzrlib.tests.test_smart_add',
3780
'bzrlib.tests.test_smart_request',
3781
'bzrlib.tests.test_smart_transport',
3782
'bzrlib.tests.test_smtp_connection',
3783
'bzrlib.tests.test_source',
3784
'bzrlib.tests.test_ssh_transport',
3785
'bzrlib.tests.test_status',
3786
'bzrlib.tests.test_store',
3787
'bzrlib.tests.test_strace',
3788
'bzrlib.tests.test_subsume',
3789
'bzrlib.tests.test_switch',
3790
'bzrlib.tests.test_symbol_versioning',
3791
'bzrlib.tests.test_tag',
3792
'bzrlib.tests.test_testament',
3793
'bzrlib.tests.test_textfile',
3794
'bzrlib.tests.test_textmerge',
3795
'bzrlib.tests.test_timestamp',
3796
'bzrlib.tests.test_trace',
3797
'bzrlib.tests.test_transactions',
3798
'bzrlib.tests.test_transform',
3799
'bzrlib.tests.test_transport',
3800
'bzrlib.tests.test_transport_log',
3801
'bzrlib.tests.test_tree',
3802
'bzrlib.tests.test_treebuilder',
3803
'bzrlib.tests.test_tsort',
3804
'bzrlib.tests.test_tuned_gzip',
3805
'bzrlib.tests.test_ui',
3806
'bzrlib.tests.test_uncommit',
3807
'bzrlib.tests.test_upgrade',
3808
'bzrlib.tests.test_upgrade_stacked',
3809
'bzrlib.tests.test_urlutils',
3810
'bzrlib.tests.test_version',
3811
'bzrlib.tests.test_version_info',
3812
'bzrlib.tests.test_weave',
3813
'bzrlib.tests.test_whitebox',
3814
'bzrlib.tests.test_win32utils',
3815
'bzrlib.tests.test_workingtree',
3816
'bzrlib.tests.test_workingtree_4',
3817
'bzrlib.tests.test_wsgi',
3818
'bzrlib.tests.test_xml',
4008
'breezy.tests.blackbox',
4009
'breezy.tests.commands',
4010
'breezy.tests.per_branch',
4011
'breezy.tests.per_controldir',
4012
'breezy.tests.per_controldir_colo',
4013
'breezy.tests.per_foreign_vcs',
4014
'breezy.tests.per_interrepository',
4015
'breezy.tests.per_intertree',
4016
'breezy.tests.per_interbranch',
4017
'breezy.tests.per_lock',
4018
'breezy.tests.per_merger',
4019
'breezy.tests.per_transport',
4020
'breezy.tests.per_tree',
4021
'breezy.tests.per_repository',
4022
'breezy.tests.per_repository_reference',
4023
'breezy.tests.per_uifactory',
4024
'breezy.tests.per_workingtree',
4025
'breezy.tests.test__annotator',
4026
'breezy.tests.test__bencode',
4027
'breezy.tests.test__known_graph',
4028
'breezy.tests.test__simple_set',
4029
'breezy.tests.test__static_tuple',
4030
'breezy.tests.test__walkdirs_win32',
4031
'breezy.tests.test_ancestry',
4032
'breezy.tests.test_annotate',
4033
'breezy.tests.test_atomicfile',
4034
'breezy.tests.test_bad_files',
4035
'breezy.tests.test_bisect',
4036
'breezy.tests.test_bisect_multi',
4037
'breezy.tests.test_branch',
4038
'breezy.tests.test_branchbuilder',
4039
'breezy.tests.test_bugtracker',
4040
'breezy.tests.test__chunks_to_lines',
4041
'breezy.tests.test_cache_utf8',
4042
'breezy.tests.test_chunk_writer',
4043
'breezy.tests.test_clean_tree',
4044
'breezy.tests.test_cleanup',
4045
'breezy.tests.test_cmdline',
4046
'breezy.tests.test_commands',
4047
'breezy.tests.test_commit',
4048
'breezy.tests.test_commit_merge',
4049
'breezy.tests.test_config',
4050
'breezy.tests.test_bedding',
4051
'breezy.tests.test_conflicts',
4052
'breezy.tests.test_controldir',
4053
'breezy.tests.test_counted_lock',
4054
'breezy.tests.test_crash',
4055
'breezy.tests.test_decorators',
4056
'breezy.tests.test_delta',
4057
'breezy.tests.test_debug',
4058
'breezy.tests.test_diff',
4059
'breezy.tests.test_directory_service',
4060
'breezy.tests.test_dirty_tracker',
4061
'breezy.tests.test_email_message',
4062
'breezy.tests.test_eol_filters',
4063
'breezy.tests.test_errors',
4064
'breezy.tests.test_estimate_compressed_size',
4065
'breezy.tests.test_export',
4066
'breezy.tests.test_export_pot',
4067
'breezy.tests.test_extract',
4068
'breezy.tests.test_features',
4069
'breezy.tests.test_fetch',
4070
'breezy.tests.test_fetch_ghosts',
4071
'breezy.tests.test_fixtures',
4072
'breezy.tests.test_fifo_cache',
4073
'breezy.tests.test_filters',
4074
'breezy.tests.test_filter_tree',
4075
'breezy.tests.test_foreign',
4076
'breezy.tests.test_generate_docs',
4077
'breezy.tests.test_globbing',
4078
'breezy.tests.test_gpg',
4079
'breezy.tests.test_graph',
4080
'breezy.tests.test_grep',
4081
'breezy.tests.test_hashcache',
4082
'breezy.tests.test_help',
4083
'breezy.tests.test_hooks',
4084
'breezy.tests.test_http',
4085
'breezy.tests.test_http_response',
4086
'breezy.tests.test_https_ca_bundle',
4087
'breezy.tests.test_https_urllib',
4088
'breezy.tests.test_i18n',
4089
'breezy.tests.test_identitymap',
4090
'breezy.tests.test_ignores',
4091
'breezy.tests.test_import_tariff',
4092
'breezy.tests.test_info',
4093
'breezy.tests.test_lazy_import',
4094
'breezy.tests.test_lazy_regex',
4095
'breezy.tests.test_library_state',
4096
'breezy.tests.test_location',
4097
'breezy.tests.test_lock',
4098
'breezy.tests.test_lockable_files',
4099
'breezy.tests.test_lockdir',
4100
'breezy.tests.test_log',
4101
'breezy.tests.test_lru_cache',
4102
'breezy.tests.test_lsprof',
4103
'breezy.tests.test_mail_client',
4104
'breezy.tests.test_matchers',
4105
'breezy.tests.test_memorybranch',
4106
'breezy.tests.test_memorytree',
4107
'breezy.tests.test_merge',
4108
'breezy.tests.test_merge3',
4109
'breezy.tests.test_mergeable',
4110
'breezy.tests.test_merge_core',
4111
'breezy.tests.test_merge_directive',
4112
'breezy.tests.test_mergetools',
4113
'breezy.tests.test_missing',
4114
'breezy.tests.test_msgeditor',
4115
'breezy.tests.test_multiparent',
4116
'breezy.tests.test_multiwalker',
4117
'breezy.tests.test_mutabletree',
4118
'breezy.tests.test_nonascii',
4119
'breezy.tests.test_options',
4120
'breezy.tests.test_osutils',
4121
'breezy.tests.test_osutils_encodings',
4122
'breezy.tests.test_patch',
4123
'breezy.tests.test_patches',
4124
'breezy.tests.test_permissions',
4125
'breezy.tests.test_plugins',
4126
'breezy.tests.test_progress',
4127
'breezy.tests.test_propose',
4128
'breezy.tests.test_pyutils',
4129
'breezy.tests.test_reconcile',
4130
'breezy.tests.test_reconfigure',
4131
'breezy.tests.test_registry',
4132
'breezy.tests.test_rename_map',
4133
'breezy.tests.test_revert',
4134
'breezy.tests.test_revision',
4135
'breezy.tests.test_revisionspec',
4136
'breezy.tests.test_revisiontree',
4137
'breezy.tests.test_rio',
4138
'breezy.tests.test__rio',
4139
'breezy.tests.test_rules',
4140
'breezy.tests.test_url_policy_open',
4141
'breezy.tests.test_sampler',
4142
'breezy.tests.test_scenarios',
4143
'breezy.tests.test_script',
4144
'breezy.tests.test_selftest',
4145
'breezy.tests.test_setup',
4146
'breezy.tests.test_sftp_transport',
4147
'breezy.tests.test_shelf',
4148
'breezy.tests.test_shelf_ui',
4149
'breezy.tests.test_smart_add',
4150
'breezy.tests.test_smtp_connection',
4151
'breezy.tests.test_source',
4152
'breezy.tests.test_ssh_transport',
4153
'breezy.tests.test_status',
4154
'breezy.tests.test_strace',
4155
'breezy.tests.test_subsume',
4156
'breezy.tests.test_switch',
4157
'breezy.tests.test_symbol_versioning',
4158
'breezy.tests.test_tag',
4159
'breezy.tests.test_test_server',
4160
'breezy.tests.test_textfile',
4161
'breezy.tests.test_textmerge',
4162
'breezy.tests.test_cethread',
4163
'breezy.tests.test_timestamp',
4164
'breezy.tests.test_trace',
4165
'breezy.tests.test_transactions',
4166
'breezy.tests.test_transform',
4167
'breezy.tests.test_transport',
4168
'breezy.tests.test_transport_log',
4169
'breezy.tests.test_tree',
4170
'breezy.tests.test_treebuilder',
4171
'breezy.tests.test_treeshape',
4172
'breezy.tests.test_tsort',
4173
'breezy.tests.test_tuned_gzip',
4174
'breezy.tests.test_ui',
4175
'breezy.tests.test_uncommit',
4176
'breezy.tests.test_upgrade',
4177
'breezy.tests.test_upgrade_stacked',
4178
'breezy.tests.test_upstream_import',
4179
'breezy.tests.test_urlutils',
4180
'breezy.tests.test_utextwrap',
4181
'breezy.tests.test_version',
4182
'breezy.tests.test_version_info',
4183
'breezy.tests.test_views',
4184
'breezy.tests.test_whitebox',
4185
'breezy.tests.test_win32utils',
4186
'breezy.tests.test_workspace',
4187
'breezy.tests.test_workingtree',
4188
'breezy.tests.test_wsgi',
4088
4491
# except on win32, where rmtree(str) will fail
4089
4492
# since it doesn't have the property of byte-stream paths
4090
4493
# (they are either ascii or mbcs)
4091
if sys.platform == 'win32':
4494
if sys.platform == 'win32' and isinstance(dirname, bytes):
4092
4495
# make sure we are using the unicode win32 api
4093
dirname = unicode(dirname)
4496
dirname = dirname.decode('mbcs')
4095
4498
dirname = dirname.encode(sys.getfilesystemencoding())
4097
4500
osutils.rmtree(dirname)
4501
except OSError as e:
4099
4502
# We don't want to fail here because some useful display will be lost
4100
4503
# otherwise. Polluting the tmp dir is bad, but not giving all the
4101
4504
# possible info to the test runner is even worse.
4505
if test_id is not None:
4103
4506
ui.ui_factory.clear_term()
4104
4507
sys.stderr.write('\nWhile running: %s\n' % (test_id,))
4508
# Ugly, but the last thing we want here is fail, so bear with it.
4509
printable_e = str(e).decode(osutils.get_user_encoding(), 'replace'
4510
).encode('ascii', 'replace')
4105
4511
sys.stderr.write('Unable to remove testing dir %s\n%s'
4106
% (os.path.basename(dirname), e))
4109
class Feature(object):
4110
"""An operating system Feature."""
4113
self._available = None
4115
def available(self):
4116
"""Is the feature available?
4118
:return: True if the feature is available.
4120
if self._available is None:
4121
self._available = self._probe()
4122
return self._available
4125
"""Implement this method in concrete features.
4127
:return: True if the feature is available.
4129
raise NotImplementedError
4132
if getattr(self, 'feature_name', None):
4133
return self.feature_name()
4134
return self.__class__.__name__
4137
class _SymlinkFeature(Feature):
4140
return osutils.has_symlinks()
4142
def feature_name(self):
4145
SymlinkFeature = _SymlinkFeature()
4148
class _HardlinkFeature(Feature):
4151
return osutils.has_hardlinks()
4153
def feature_name(self):
4156
HardlinkFeature = _HardlinkFeature()
4159
class _OsFifoFeature(Feature):
4162
return getattr(os, 'mkfifo', None)
4164
def feature_name(self):
4165
return 'filesystem fifos'
4167
OsFifoFeature = _OsFifoFeature()
4170
class _UnicodeFilenameFeature(Feature):
4171
"""Does the filesystem support Unicode filenames?"""
4175
# Check for character combinations unlikely to be covered by any
4176
# single non-unicode encoding. We use the characters
4177
# - greek small letter alpha (U+03B1) and
4178
# - braille pattern dots-123456 (U+283F).
4179
os.stat(u'\u03b1\u283f')
4180
except UnicodeEncodeError:
4182
except (IOError, OSError):
4183
# The filesystem allows the Unicode filename but the file doesn't
4187
# The filesystem allows the Unicode filename and the file exists,
4191
UnicodeFilenameFeature = _UnicodeFilenameFeature()
4194
class _CompatabilityThunkFeature(Feature):
4195
"""This feature is just a thunk to another feature.
4197
It issues a deprecation warning if it is accessed, to let you know that you
4198
should really use a different feature.
4201
def __init__(self, dep_version, module, name,
4202
replacement_name, replacement_module=None):
4203
super(_CompatabilityThunkFeature, self).__init__()
4204
self._module = module
4205
if replacement_module is None:
4206
replacement_module = module
4207
self._replacement_module = replacement_module
4209
self._replacement_name = replacement_name
4210
self._dep_version = dep_version
4211
self._feature = None
4214
if self._feature is None:
4215
depr_msg = self._dep_version % ('%s.%s'
4216
% (self._module, self._name))
4217
use_msg = ' Use %s.%s instead.' % (self._replacement_module,
4218
self._replacement_name)
4219
symbol_versioning.warn(depr_msg + use_msg, DeprecationWarning)
4220
# Import the new feature and use it as a replacement for the
4222
mod = __import__(self._replacement_module, {}, {},
4223
[self._replacement_name])
4224
self._feature = getattr(mod, self._replacement_name)
4228
return self._feature._probe()
4231
class ModuleAvailableFeature(Feature):
4232
"""This is a feature than describes a module we want to be available.
4234
Declare the name of the module in __init__(), and then after probing, the
4235
module will be available as 'self.module'.
4237
:ivar module: The module if it is available, else None.
4240
def __init__(self, module_name):
4241
super(ModuleAvailableFeature, self).__init__()
4242
self.module_name = module_name
4246
self._module = __import__(self.module_name, {}, {}, [''])
4253
if self.available(): # Make sure the probe has been done
4257
def feature_name(self):
4258
return self.module_name
4261
# This is kept here for compatibility, it is recommended to use
4262
# 'bzrlib.tests.feature.paramiko' instead
4263
ParamikoFeature = _CompatabilityThunkFeature(
4264
deprecated_in((2,1,0)),
4265
'bzrlib.tests.features', 'ParamikoFeature', 'paramiko')
4512
% (os.path.basename(dirname), printable_e))
4268
4515
def probe_unicode_in_user_encoding():
4301
class _HTTPSServerFeature(Feature):
4302
"""Some tests want an https Server, check if one is available.
4304
Right now, the only way this is available is under python2.6 which provides
4315
def feature_name(self):
4316
return 'HTTPSServer'
4319
HTTPSServerFeature = _HTTPSServerFeature()
4322
class _UnicodeFilename(Feature):
4323
"""Does the filesystem support Unicode filenames?"""
4328
except UnicodeEncodeError:
4330
except (IOError, OSError):
4331
# The filesystem allows the Unicode filename but the file doesn't
4335
# The filesystem allows the Unicode filename and the file exists,
4339
UnicodeFilename = _UnicodeFilename()
4342
class _UTF8Filesystem(Feature):
4343
"""Is the filesystem UTF-8?"""
4346
if osutils._fs_enc.upper() in ('UTF-8', 'UTF8'):
4350
UTF8Filesystem = _UTF8Filesystem()
4353
class _BreakinFeature(Feature):
4354
"""Does this platform support the breakin feature?"""
4357
from bzrlib import breakin
4358
if breakin.determine_signal() is None:
4360
if sys.platform == 'win32':
4361
# Windows doesn't have os.kill, and we catch the SIGBREAK signal.
4362
# We trigger SIGBREAK via a Console api so we need ctypes to
4363
# access the function
4370
def feature_name(self):
4371
return "SIGQUIT or SIGBREAK w/ctypes on win32"
4374
BreakinFeature = _BreakinFeature()
4377
class _CaseInsCasePresFilenameFeature(Feature):
4378
"""Is the file-system case insensitive, but case-preserving?"""
4381
fileno, name = tempfile.mkstemp(prefix='MixedCase')
4383
# first check truly case-preserving for created files, then check
4384
# case insensitive when opening existing files.
4385
name = osutils.normpath(name)
4386
base, rel = osutils.split(name)
4387
found_rel = osutils.canonical_relpath(base, name)
4388
return (found_rel == rel
4389
and os.path.isfile(name.upper())
4390
and os.path.isfile(name.lower()))
4395
def feature_name(self):
4396
return "case-insensitive case-preserving filesystem"
4398
CaseInsCasePresFilenameFeature = _CaseInsCasePresFilenameFeature()
4401
class _CaseInsensitiveFilesystemFeature(Feature):
4402
"""Check if underlying filesystem is case-insensitive but *not* case
4405
# Note that on Windows, Cygwin, MacOS etc, the file-systems are far
4406
# more likely to be case preserving, so this case is rare.
4409
if CaseInsCasePresFilenameFeature.available():
4412
if TestCaseWithMemoryTransport.TEST_ROOT is None:
4413
root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
4414
TestCaseWithMemoryTransport.TEST_ROOT = root
4416
root = TestCaseWithMemoryTransport.TEST_ROOT
4417
tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
4419
name_a = osutils.pathjoin(tdir, 'a')
4420
name_A = osutils.pathjoin(tdir, 'A')
4422
result = osutils.isdir(name_A)
4423
_rmtree_temp_dir(tdir)
4426
def feature_name(self):
4427
return 'case-insensitive filesystem'
4429
CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()
4432
class _CaseSensitiveFilesystemFeature(Feature):
4435
if CaseInsCasePresFilenameFeature.available():
4437
elif CaseInsensitiveFilesystemFeature.available():
4442
def feature_name(self):
4443
return 'case-sensitive filesystem'
4445
# new coding style is for feature instances to be lowercase
4446
case_sensitive_filesystem_feature = _CaseSensitiveFilesystemFeature()
4449
# Kept for compatibility, use bzrlib.tests.features.subunit instead
4450
SubUnitFeature = _CompatabilityThunkFeature(
4451
deprecated_in((2,1,0)),
4452
'bzrlib.tests.features', 'SubUnitFeature', 'subunit')
4453
4548
# Only define SubUnitBzrRunner if subunit is available.
4455
4550
from subunit import TestProtocolClient
4456
4551
from subunit.test_results import AutoTimingTestResultDecorator
4457
class SubUnitBzrRunner(TextTestRunner):
4553
class SubUnitBzrProtocolClientv1(TestProtocolClient):
4555
def stopTest(self, test):
4556
super(SubUnitBzrProtocolClientv1, self).stopTest(test)
4557
_clear__type_equality_funcs(test)
4559
def addSuccess(self, test, details=None):
4560
# The subunit client always includes the details in the subunit
4561
# stream, but we don't want to include it in ours.
4562
if details is not None and 'log' in details:
4564
return super(SubUnitBzrProtocolClientv1, self).addSuccess(
4567
class SubUnitBzrRunnerv1(TextTestRunner):
4458
4569
def run(self, test):
4459
4570
result = AutoTimingTestResultDecorator(
4460
TestProtocolClient(self.stream))
4571
SubUnitBzrProtocolClientv1(self.stream))
4461
4572
test.run(result)
4463
4574
except ImportError:
4466
class _PosixPermissionsFeature(Feature):
4470
# create temporary file and check if specified perms are maintained.
4473
write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
4474
f = tempfile.mkstemp(prefix='bzr_perms_chk_')
4477
os.chmod(name, write_perms)
4479
read_perms = os.stat(name).st_mode & 0777
4481
return (write_perms == read_perms)
4483
return (os.name == 'posix') and has_perms()
4485
def feature_name(self):
4486
return 'POSIX permissions support'
4488
posix_permissions_feature = _PosixPermissionsFeature()
4579
from subunit.run import SubunitTestRunner
4581
class SubUnitBzrRunnerv2(TextTestRunner, SubunitTestRunner):
4583
def __init__(self, stream=sys.stderr, descriptions=0, verbosity=1,
4584
bench_history=None, strict=False, result_decorators=None):
4585
TextTestRunner.__init__(
4586
self, stream=stream,
4587
descriptions=descriptions, verbosity=verbosity,
4588
bench_history=bench_history, strict=strict,
4589
result_decorators=result_decorators)
4590
SubunitTestRunner.__init__(self, verbosity=verbosity,
4593
run = SubunitTestRunner.run