109
110
default_transport = LocalURLServer
113
MODULES_TO_DOCTEST = [
123
bzrlib.version_info_formats.format_custom,
124
# quoted to avoid module-loading circularity
129
def packages_to_test():
130
"""Return a list of packages to test.
132
The packages are not globally imported so that import failures are
133
triggered when running selftest, not when importing the command.
136
import bzrlib.tests.blackbox
137
import bzrlib.tests.branch_implementations
138
import bzrlib.tests.bzrdir_implementations
139
import bzrlib.tests.commands
140
import bzrlib.tests.interrepository_implementations
141
import bzrlib.tests.interversionedfile_implementations
142
import bzrlib.tests.intertree_implementations
143
import bzrlib.tests.inventory_implementations
144
import bzrlib.tests.per_lock
145
import bzrlib.tests.repository_implementations
146
import bzrlib.tests.revisionstore_implementations
147
import bzrlib.tests.tree_implementations
148
import bzrlib.tests.workingtree_implementations
151
bzrlib.tests.blackbox,
152
bzrlib.tests.branch_implementations,
153
bzrlib.tests.bzrdir_implementations,
154
bzrlib.tests.commands,
155
bzrlib.tests.interrepository_implementations,
156
bzrlib.tests.interversionedfile_implementations,
157
bzrlib.tests.intertree_implementations,
158
bzrlib.tests.inventory_implementations,
159
bzrlib.tests.per_lock,
160
bzrlib.tests.repository_implementations,
161
bzrlib.tests.revisionstore_implementations,
162
bzrlib.tests.tree_implementations,
163
bzrlib.tests.workingtree_implementations,
112
167
class ExtendedTestResult(unittest._TextTestResult):
113
168
"""Accepts, reports and accumulates the results of running tests.
363
416
self.pb.update('[test 0/%d] starting...' % (self.num_tests))
365
418
def _progress_prefix_text(self):
366
# the longer this text, the less space we have to show the test
368
a = '[%d' % self.count # total that have been run
369
# tests skipped as known not to be relevant are not important enough
371
## if self.skip_count:
372
## a += ', %d skip' % self.skip_count
373
## if self.known_failure_count:
374
## a += '+%dX' % self.known_failure_count
419
a = '[%d' % self.count
375
420
if self.num_tests is not None:
376
421
a +='/%d' % self.num_tests
378
runtime = time.time() - self._overall_start_time
380
a += '%dm%ds' % (runtime / 60, runtime % 60)
422
a += ' in %ds' % (time.time() - self._overall_start_time)
383
423
if self.error_count:
384
a += ', %d err' % self.error_count
424
a += ', %d errors' % self.error_count
385
425
if self.failure_count:
386
a += ', %d fail' % self.failure_count
426
a += ', %d failed' % self.failure_count
427
if self.known_failure_count:
428
a += ', %d known failures' % self.known_failure_count
430
a += ', %d skipped' % self.skip_count
387
431
if self.unsupported:
388
a += ', %d missing' % len(self.unsupported)
432
a += ', %d missing features' % len(self.unsupported)
771
803
self._benchtime = None
772
804
self._clear_hooks()
773
805
self._clear_debug_flags()
774
TestCase._active_threads = threading.activeCount()
775
self.addCleanup(self._check_leaked_threads)
777
def _check_leaked_threads(self):
778
active = threading.activeCount()
779
leaked_threads = active - TestCase._active_threads
780
TestCase._active_threads = active
782
TestCase._leaking_threads_tests += 1
783
if TestCase._first_thread_leaker_id is None:
784
TestCase._first_thread_leaker_id = self.id()
785
# we're not specifically told when all tests are finished.
786
# This will do. We use a function to avoid keeping a reference
787
# to a TestCase object.
788
atexit.register(_report_leaked_threads)
790
807
def _clear_debug_flags(self):
791
808
"""Prevent externally set debug flags affecting tests.
793
810
Tests that want to use debug flags can just set them in the
794
811
debug_flags set during setup/teardown.
796
813
self._preserved_debug_flags = set(debug.debug_flags)
797
if 'allow_debug' not in selftest_debug_flags:
798
debug.debug_flags.clear()
814
debug.debug_flags.clear()
799
815
self.addCleanup(self._restore_debug_flags)
801
817
def _clear_hooks(self):
802
818
# prevent hooks affecting tests
803
819
import bzrlib.branch
804
import bzrlib.smart.client
805
820
import bzrlib.smart.server
806
821
self._preserved_hooks = {
807
822
bzrlib.branch.Branch: bzrlib.branch.Branch.hooks,
808
bzrlib.mutabletree.MutableTree: bzrlib.mutabletree.MutableTree.hooks,
809
bzrlib.smart.client._SmartClient: bzrlib.smart.client._SmartClient.hooks,
810
823
bzrlib.smart.server.SmartTCPServer: bzrlib.smart.server.SmartTCPServer.hooks,
811
bzrlib.commands.Command: bzrlib.commands.Command.hooks,
813
825
self.addCleanup(self._restoreHooks)
814
826
# reset all hooks to an empty instance of the appropriate type
815
827
bzrlib.branch.Branch.hooks = bzrlib.branch.BranchHooks()
816
bzrlib.smart.client._SmartClient.hooks = bzrlib.smart.client.SmartClientHooks()
817
828
bzrlib.smart.server.SmartTCPServer.hooks = bzrlib.smart.server.SmartServerHooks()
818
bzrlib.commands.Command.hooks = bzrlib.commands.CommandHooks()
820
830
def _silenceUI(self):
821
831
"""Turn off UI for duration of test"""
879
885
self.assertEqual(mode, mode_test,
880
886
'mode mismatch %o != %o' % (mode, mode_test))
882
def assertEqualStat(self, expected, actual):
883
"""assert that expected and actual are the same stat result.
885
:param expected: A stat result.
886
:param actual: A stat result.
887
:raises AssertionError: If the expected and actual stat values differ
890
self.assertEqual(expected.st_size, actual.st_size)
891
self.assertEqual(expected.st_mtime, actual.st_mtime)
892
self.assertEqual(expected.st_ctime, actual.st_ctime)
893
self.assertEqual(expected.st_dev, actual.st_dev)
894
self.assertEqual(expected.st_ino, actual.st_ino)
895
self.assertEqual(expected.st_mode, actual.st_mode)
897
888
def assertPositive(self, val):
898
889
"""Assert that val is greater than 0."""
899
890
self.assertTrue(val > 0, 'expected a positive value, but got %s' % val)
1217
1206
"""Make the logfile not be deleted when _finishLogFile is called."""
1218
1207
self._keep_log_file = True
1220
def addCleanup(self, callable, *args, **kwargs):
1209
def addCleanup(self, callable):
1221
1210
"""Arrange to run a callable when this case is torn down.
1223
1212
Callables are run in the reverse of the order they are registered,
1224
1213
ie last-in first-out.
1226
self._cleanups.append((callable, args, kwargs))
1215
if callable in self._cleanups:
1216
raise ValueError("cleanup function %r already registered on %s"
1218
self._cleanups.append(callable)
1228
1220
def _cleanEnvironment(self):
1230
1222
'BZR_HOME': None, # Don't inherit BZR_HOME to all the tests.
1231
1223
'HOME': os.getcwd(),
1232
# bzr now uses the Win32 API and doesn't rely on APPDATA, but the
1233
# tests do check our impls match APPDATA
1224
'APPDATA': None, # bzr now use Win32 API and don't rely on APPDATA
1234
1225
'BZR_EDITOR': None, # test_msgeditor manipulates this variable
1235
1226
'BZR_EMAIL': None,
1236
1227
'BZREMAIL': None, # may still be present in the environment
1238
1229
'BZR_PROGRESS_BAR': None,
1239
1230
'BZR_LOG': None,
1240
'BZR_PLUGIN_PATH': None,
1242
1232
'SSH_AUTH_SOCK': None,
2072
2045
self.log("actually: %r" % contents)
2073
2046
self.fail("contents of %s not as expected" % filename)
2075
def _getTestDirPrefix(self):
2076
# create a directory within the top level test directory
2077
if sys.platform == 'win32':
2078
name_prefix = re.sub('[<>*=+",:;_/\\-]', '_', self.id())
2079
# windows is likely to have path-length limits so use a short name
2080
name_prefix = name_prefix[-30:]
2082
name_prefix = re.sub('[/]', '_', self.id())
2085
2048
def makeAndChdirToTestDir(self):
2086
2049
"""See TestCaseWithMemoryTransport.makeAndChdirToTestDir().
2088
2051
For TestCaseInTempDir we create a temporary directory based on the test
2089
2052
name and then create two subdirs - test and home under it.
2091
name_prefix = osutils.pathjoin(self.TEST_ROOT, self._getTestDirPrefix())
2093
for i in range(100):
2094
if os.path.exists(name):
2095
name = name_prefix + '_' + str(i)
2054
# create a directory within the top level test directory
2055
candidate_dir = osutils.mkdtemp(dir=self.TEST_ROOT)
2099
2056
# now create test and home directories within this dir
2100
self.test_base_dir = name
2057
self.test_base_dir = candidate_dir
2101
2058
self.test_home_dir = self.test_base_dir + '/home'
2102
2059
os.mkdir(self.test_home_dir)
2103
2060
self.test_dir = self.test_base_dir + '/work'
2373
2308
return TestUtil.TestSuite(result)
2376
def filter_suite_by_re(suite, pattern):
2311
def filter_suite_by_re(suite, pattern, exclude_pattern=DEPRECATED_PARAMETER,
2312
random_order=DEPRECATED_PARAMETER):
2377
2313
"""Create a test suite by filtering another one.
2379
2315
:param suite: the source suite
2380
2316
:param pattern: pattern that names must match
2317
:param exclude_pattern: A pattern that names must not match. This parameter
2318
is deprecated as of bzrlib 1.0. Please use the separate function
2319
exclude_tests_by_re instead.
2320
:param random_order: If True, tests in the new suite will be put in
2321
random order. This parameter is deprecated as of bzrlib 1.0. Please
2322
use the separate function randomize_suite instead.
2381
2323
:returns: the newly created suite
2325
if deprecated_passed(exclude_pattern):
2326
symbol_versioning.warn(
2327
one_zero % "passing exclude_pattern to filter_suite_by_re",
2328
DeprecationWarning, stacklevel=2)
2329
if exclude_pattern is not None:
2330
suite = exclude_tests_by_re(suite, exclude_pattern)
2383
2331
condition = condition_id_re(pattern)
2384
2332
result_suite = filter_suite_by_condition(suite, condition)
2333
if deprecated_passed(random_order):
2334
symbol_versioning.warn(
2335
one_zero % "passing random_order to filter_suite_by_re",
2336
DeprecationWarning, stacklevel=2)
2338
result_suite = randomize_suite(result_suite)
2385
2339
return result_suite
2443
2385
return TestUtil.TestSuite(tests)
2446
def split_suite_by_condition(suite, condition):
2447
"""Split a test suite into two by a condition.
2388
@deprecated_function(one_zero)
2389
def sort_suite_by_re(suite, pattern, exclude_pattern=None,
2390
random_order=False, append_rest=True):
2391
"""DEPRECATED: Create a test suite by sorting another one.
2393
This method has been decomposed into separate helper methods that should be
2395
- filter_suite_by_re
2396
- exclude_tests_by_re
2449
:param suite: The suite to split.
2450
:param condition: The condition to match on. Tests that match this
2451
condition are returned in the first test suite, ones that do not match
2452
are in the second suite.
2453
:return: A tuple of two test suites, where the first contains tests from
2454
suite matching the condition, and the second contains the remainder
2455
from suite. The order within each output suite is the same as it was in
2460
for test in iter_suite_tests(suite):
2462
matched.append(test)
2464
did_not_match.append(test)
2465
return TestUtil.TestSuite(matched), TestUtil.TestSuite(did_not_match)
2400
:param suite: the source suite
2401
:param pattern: pattern that names must match in order to go
2402
first in the new suite
2403
:param exclude_pattern: pattern that names must not match, if any
2404
:param random_order: if True, tests in the new suite will be put in
2405
random order (with all tests matching pattern
2407
:param append_rest: if False, pattern is a strict filter and not
2408
just an ordering directive
2409
:returns: the newly created suite
2411
if exclude_pattern is not None:
2412
suite = exclude_tests_by_re(suite, exclude_pattern)
2414
order_changer = randomize_suite
2416
order_changer = preserve_input
2418
suites = map(order_changer, split_suite_by_re(suite, pattern))
2419
return TestUtil.TestSuite(suites)
2421
return order_changer(filter_suite_by_re(suite, pattern))
2468
2424
def split_suite_by_re(suite, pattern):
2632
2573
return test_list
2635
def suite_matches_id_list(test_suite, id_list):
2636
"""Warns about tests not appearing or appearing more than once.
2638
:param test_suite: A TestSuite object.
2639
:param test_id_list: The list of test ids that should be found in
2642
:return: (absents, duplicates) absents is a list containing the test found
2643
in id_list but not in test_suite, duplicates is a list containing the
2644
test found multiple times in test_suite.
2646
When using a prefined test id list, it may occurs that some tests do not
2647
exist anymore or that some tests use the same id. This function warns the
2648
tester about potential problems in his workflow (test lists are volatile)
2649
or in the test suite itself (using the same id for several tests does not
2650
help to localize defects).
2652
# Build a dict counting id occurrences
2654
for test in iter_suite_tests(test_suite):
2656
tests[id] = tests.get(id, 0) + 1
2661
occurs = tests.get(id, 0)
2663
not_found.append(id)
2665
duplicates.append(id)
2667
return not_found, duplicates
2670
2576
class TestIdList(object):
2671
2577
"""Test id list to filter a test suite.
2703
2609
modules[mod_name] = True
2704
2610
self.modules = modules
2706
def refers_to(self, module_name):
2612
def is_module_name_used(self, module_name):
2707
2613
"""Is there tests for the module or one of its sub modules."""
2708
2614
return self.modules.has_key(module_name)
2710
def includes(self, test_id):
2616
def test_in(self, test_id):
2711
2617
return self.tests.has_key(test_id)
2714
class TestPrefixAliasRegistry(registry.Registry):
2715
"""A registry for test prefix aliases.
2717
This helps implement shorcuts for the --starting-with selftest
2718
option. Overriding existing prefixes is not allowed but not fatal (a
2719
warning will be emitted).
2722
def register(self, key, obj, help=None, info=None,
2723
override_existing=False):
2724
"""See Registry.register.
2726
Trying to override an existing alias causes a warning to be emitted,
2727
not a fatal execption.
2730
super(TestPrefixAliasRegistry, self).register(
2731
key, obj, help=help, info=info, override_existing=False)
2733
actual = self.get(key)
2734
note('Test prefix alias %s is already used for %s, ignoring %s'
2735
% (key, actual, obj))
2737
def resolve_alias(self, id_start):
2738
"""Replace the alias by the prefix in the given string.
2740
Using an unknown prefix is an error to help catching typos.
2742
parts = id_start.split('.')
2744
parts[0] = self.get(parts[0])
2746
raise errors.BzrCommandError(
2747
'%s is not a known test prefix alias' % parts[0])
2748
return '.'.join(parts)
2751
test_prefix_alias_registry = TestPrefixAliasRegistry()
2752
"""Registry of test prefix aliases."""
2755
# This alias allows to detect typos ('bzrlin.') by making all valid test ids
2756
# appear prefixed ('bzrlib.' is "replaced" by 'bzrlib.').
2757
test_prefix_alias_registry.register('bzrlib', 'bzrlib')
2759
# Obvious higest levels prefixes, feel free to add your own via a plugin
2760
test_prefix_alias_registry.register('bd', 'bzrlib.doc')
2761
test_prefix_alias_registry.register('bu', 'bzrlib.utils')
2762
test_prefix_alias_registry.register('bt', 'bzrlib.tests')
2763
test_prefix_alias_registry.register('bb', 'bzrlib.tests.blackbox')
2764
test_prefix_alias_registry.register('bp', 'bzrlib.plugins')
2767
def test_suite(keep_only=None, starting_with=None):
2620
def test_suite(keep_only=None):
2768
2621
"""Build and return TestSuite for the whole of bzrlib.
2770
2623
:param keep_only: A list of test ids limiting the suite returned.
2772
:param starting_with: An id limiting the suite returned to the tests
2775
2625
This function can be replaced if you need to change the default test
2776
2626
suite on a global basis, but it is not encouraged.
2778
2628
testmod_names = [
2780
'bzrlib.tests.blackbox',
2781
'bzrlib.tests.branch_implementations',
2782
'bzrlib.tests.bzrdir_implementations',
2783
'bzrlib.tests.commands',
2784
'bzrlib.tests.interrepository_implementations',
2785
'bzrlib.tests.intertree_implementations',
2786
'bzrlib.tests.inventory_implementations',
2787
'bzrlib.tests.per_lock',
2788
'bzrlib.tests.per_repository',
2789
'bzrlib.tests.per_repository_reference',
2629
'bzrlib.util.tests.test_bencode',
2790
2630
'bzrlib.tests.test__dirstate_helpers',
2791
'bzrlib.tests.test__walkdirs_win32',
2792
2631
'bzrlib.tests.test_ancestry',
2793
2632
'bzrlib.tests.test_annotate',
2794
2633
'bzrlib.tests.test_api',
2797
2636
'bzrlib.tests.test_bisect_multi',
2798
2637
'bzrlib.tests.test_branch',
2799
2638
'bzrlib.tests.test_branchbuilder',
2800
'bzrlib.tests.test_btree_index',
2801
2639
'bzrlib.tests.test_bugtracker',
2802
2640
'bzrlib.tests.test_bundle',
2803
2641
'bzrlib.tests.test_bzrdir',
2804
2642
'bzrlib.tests.test_cache_utf8',
2805
'bzrlib.tests.test_chunk_writer',
2806
'bzrlib.tests.test__chunks_to_lines',
2807
2643
'bzrlib.tests.test_commands',
2808
2644
'bzrlib.tests.test_commit',
2809
2645
'bzrlib.tests.test_commit_merge',
2814
2650
'bzrlib.tests.test_delta',
2815
2651
'bzrlib.tests.test_deprecated_graph',
2816
2652
'bzrlib.tests.test_diff',
2817
'bzrlib.tests.test_directory_service',
2818
2653
'bzrlib.tests.test_dirstate',
2819
2654
'bzrlib.tests.test_email_message',
2820
2655
'bzrlib.tests.test_errors',
2656
'bzrlib.tests.test_escaped_store',
2821
2657
'bzrlib.tests.test_extract',
2822
2658
'bzrlib.tests.test_fetch',
2823
'bzrlib.tests.test_fifo_cache',
2824
2659
'bzrlib.tests.test_ftp_transport',
2825
'bzrlib.tests.test_foreign',
2826
2660
'bzrlib.tests.test_generate_docs',
2827
2661
'bzrlib.tests.test_generate_ids',
2828
2662
'bzrlib.tests.test_globbing',
2857
2691
'bzrlib.tests.test_missing',
2858
2692
'bzrlib.tests.test_msgeditor',
2859
2693
'bzrlib.tests.test_multiparent',
2860
'bzrlib.tests.test_mutabletree',
2861
2694
'bzrlib.tests.test_nonascii',
2862
2695
'bzrlib.tests.test_options',
2863
2696
'bzrlib.tests.test_osutils',
2864
2697
'bzrlib.tests.test_osutils_encodings',
2865
2698
'bzrlib.tests.test_pack',
2866
'bzrlib.tests.test_pack_repository',
2867
2699
'bzrlib.tests.test_patch',
2868
2700
'bzrlib.tests.test_patches',
2869
2701
'bzrlib.tests.test_permissions',
2870
2702
'bzrlib.tests.test_plugins',
2871
2703
'bzrlib.tests.test_progress',
2872
'bzrlib.tests.test_read_bundle',
2704
'bzrlib.tests.test_reconfigure',
2873
2705
'bzrlib.tests.test_reconcile',
2874
'bzrlib.tests.test_reconfigure',
2875
2706
'bzrlib.tests.test_registry',
2876
2707
'bzrlib.tests.test_remote',
2877
2708
'bzrlib.tests.test_repository',
2878
2709
'bzrlib.tests.test_revert',
2879
2710
'bzrlib.tests.test_revision',
2880
'bzrlib.tests.test_revisionspec',
2711
'bzrlib.tests.test_revisionnamespaces',
2881
2712
'bzrlib.tests.test_revisiontree',
2882
2713
'bzrlib.tests.test_rio',
2883
'bzrlib.tests.test_rules',
2884
2714
'bzrlib.tests.test_sampler',
2885
2715
'bzrlib.tests.test_selftest',
2886
2716
'bzrlib.tests.test_setup',
2887
2717
'bzrlib.tests.test_sftp_transport',
2888
'bzrlib.tests.test_shelf',
2889
'bzrlib.tests.test_shelf_ui',
2890
2718
'bzrlib.tests.test_smart',
2891
2719
'bzrlib.tests.test_smart_add',
2892
'bzrlib.tests.test_smart_request',
2893
2720
'bzrlib.tests.test_smart_transport',
2894
2721
'bzrlib.tests.test_smtp_connection',
2895
2722
'bzrlib.tests.test_source',
2909
2736
'bzrlib.tests.test_transactions',
2910
2737
'bzrlib.tests.test_transform',
2911
2738
'bzrlib.tests.test_transport',
2912
'bzrlib.tests.test_transport_implementations',
2913
'bzrlib.tests.test_transport_log',
2914
2739
'bzrlib.tests.test_tree',
2915
2740
'bzrlib.tests.test_treebuilder',
2916
2741
'bzrlib.tests.test_tsort',
2917
2742
'bzrlib.tests.test_tuned_gzip',
2918
2743
'bzrlib.tests.test_ui',
2919
'bzrlib.tests.test_uncommit',
2920
2744
'bzrlib.tests.test_upgrade',
2921
'bzrlib.tests.test_upgrade_stacked',
2922
2745
'bzrlib.tests.test_urlutils',
2746
'bzrlib.tests.test_versionedfile',
2923
2747
'bzrlib.tests.test_version',
2924
2748
'bzrlib.tests.test_version_info',
2925
'bzrlib.tests.test_versionedfile',
2926
2749
'bzrlib.tests.test_weave',
2927
2750
'bzrlib.tests.test_whitebox',
2928
2751
'bzrlib.tests.test_win32utils',
2930
2753
'bzrlib.tests.test_workingtree_4',
2931
2754
'bzrlib.tests.test_wsgi',
2932
2755
'bzrlib.tests.test_xml',
2933
'bzrlib.tests.tree_implementations',
2934
'bzrlib.tests.workingtree_implementations',
2935
'bzrlib.util.tests.test_bencode',
2757
test_transport_implementations = [
2758
'bzrlib.tests.test_transport_implementations',
2759
'bzrlib.tests.test_read_bundle',
2761
suite = TestUtil.TestSuite()
2938
2762
loader = TestUtil.TestLoader()
2941
starting_with = [test_prefix_alias_registry.resolve_alias(start)
2942
for start in starting_with]
2943
# We take precedence over keep_only because *at loading time* using
2944
# both options means we will load less tests for the same final result.
2945
def interesting_module(name):
2946
for start in starting_with:
2948
# Either the module name starts with the specified string
2949
name.startswith(start)
2950
# or it may contain tests starting with the specified string
2951
or start.startswith(name)
2955
loader = TestUtil.FilteredByModuleTestLoader(interesting_module)
2957
elif keep_only is not None:
2764
if keep_only is not None:
2958
2765
id_filter = TestIdList(keep_only)
2959
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
2960
def interesting_module(name):
2961
return id_filter.refers_to(name)
2964
loader = TestUtil.TestLoader()
2965
def interesting_module(name):
2966
# No filtering, all modules are interesting
2969
suite = loader.suiteClass()
2971
2767
# modules building their suite with loadTestsFromModuleNames
2972
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2974
modules_to_doctest = [
2976
'bzrlib.branchbuilder',
2979
'bzrlib.iterablefile',
2983
'bzrlib.symbol_versioning',
2986
'bzrlib.version_info_formats.format_custom',
2989
for mod in modules_to_doctest:
2990
if not interesting_module(mod):
2991
# No tests to keep here, move along
2768
if keep_only is None:
2769
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2771
for mod in [m for m in testmod_names
2772
if id_filter.is_module_name_used(m)]:
2773
mod_suite = loader.loadTestsFromModuleNames([mod])
2774
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2775
suite.addTest(mod_suite)
2777
# modules adapted for transport implementations
2778
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2779
adapter = TransportTestProviderAdapter()
2780
if keep_only is None:
2781
adapt_modules(test_transport_implementations, adapter, loader, suite)
2783
for mod in [m for m in test_transport_implementations
2784
if id_filter.is_module_name_used(m)]:
2785
mod_suite = TestUtil.TestSuite()
2786
adapt_modules([mod], adapter, loader, mod_suite)
2787
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2788
suite.addTest(mod_suite)
2790
# modules defining their own test_suite()
2791
for package in [p for p in packages_to_test()
2792
if (keep_only is None
2793
or id_filter.is_module_name_used(p.__name__))]:
2794
pack_suite = package.test_suite()
2795
if keep_only is not None:
2796
pack_suite = filter_suite_by_id_list(pack_suite, id_filter)
2797
suite.addTest(pack_suite)
2799
# XXX: MODULES_TO_TEST should be obsoleted ?
2800
for mod in [m for m in MODULES_TO_TEST
2801
if keep_only is None or id_filter.is_module_name_used(m)]:
2802
mod_suite = loader.loadTestsFromModule(mod)
2803
if keep_only is not None:
2804
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2805
suite.addTest(mod_suite)
2807
for mod in MODULES_TO_DOCTEST:
2994
# note that this really does mean "report only" -- doctest
2995
# still runs the rest of the examples
2996
doc_suite = doctest.DocTestSuite(mod,
2997
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)
2809
doc_suite = doctest.DocTestSuite(mod)
2998
2810
except ValueError, e:
2999
2811
print '**failed to get doctest for: %s\n%s' % (mod, e)
3001
if len(doc_suite._tests) == 0:
3002
raise errors.BzrError("no doctests found in %s" % (mod,))
2813
if keep_only is not None:
2814
# DocTests may use ids which doesn't contain the module name
2815
doc_suite = filter_suite_by_id_list(doc_suite, id_filter)
3003
2816
suite.addTest(doc_suite)
3005
2818
default_encoding = sys.getdefaultencoding()
3006
2819
for name, plugin in bzrlib.plugin.plugins().items():
3007
if not interesting_module(plugin.module.__name__):
2820
if keep_only is not None:
2821
if not id_filter.is_module_name_used(plugin.module.__name__):
3009
2823
plugin_suite = plugin.test_suite()
3010
2824
# We used to catch ImportError here and turn it into just a warning,
3011
2825
# but really if you don't have --no-plugins this should be a failure.
3012
2826
# mbp 20080213 - see http://bugs.launchpad.net/bugs/189771
3013
if plugin_suite is None:
3014
plugin_suite = plugin.load_plugin_tests(loader)
3015
2827
if plugin_suite is not None:
2828
if keep_only is not None:
2829
plugin_suite = filter_suite_by_id_list(plugin_suite,
3016
2831
suite.addTest(plugin_suite)
3017
2832
if default_encoding != sys.getdefaultencoding():
3018
2833
bzrlib.trace.warning(
3020
2835
sys.getdefaultencoding())
3022
2837
sys.setdefaultencoding(default_encoding)
3025
suite = filter_suite_by_id_startswith(suite, starting_with)
3027
if keep_only is not None:
3028
# Now that the referred modules have loaded their tests, keep only the
3030
suite = filter_suite_by_id_list(suite, id_filter)
3031
# Do some sanity checks on the id_list filtering
3032
not_found, duplicates = suite_matches_id_list(suite, keep_only)
3034
# The tester has used both keep_only and starting_with, so he is
3035
# already aware that some tests are excluded from the list, there
3036
# is no need to tell him which.
3039
# Some tests mentioned in the list are not in the test suite. The
3040
# list may be out of date, report to the tester.
3041
for id in not_found:
3042
bzrlib.trace.warning('"%s" not found in the test suite', id)
3043
for id in duplicates:
3044
bzrlib.trace.warning('"%s" is used as an id by several tests', id)
3049
def multiply_tests_from_modules(module_name_list, scenario_iter, loader=None):
2841
def multiply_tests_from_modules(module_name_list, scenario_iter):
3050
2842
"""Adapt all tests in some given modules to given scenarios.
3052
2844
This is the recommended public interface for test parameterization.
3112
2897
def adapt_modules(mods_list, adapter, loader, suite):
3113
2898
"""Adapt the modules in mods_list using adapter and add to suite."""
3114
tests = loader.loadTestsFromModuleNames(mods_list)
3115
adapt_tests(tests, adapter, suite)
3118
def adapt_tests(tests_list, adapter, suite):
2899
for test in iter_suite_tests(loader.loadTestsFromModuleNames(mods_list)):
2900
suite.addTests(adapter.adapt(test))
2903
def adapt_tests(tests_list, adapter, loader, suite):
3119
2904
"""Adapt the tests in tests_list using adapter and add to suite."""
3120
for test in iter_suite_tests(tests_list):
3121
suite.addTests(adapter.adapt(test))
2905
for test in tests_list:
2906
suite.addTests(adapter.adapt(loader.loadTestsFromName(test)))
3124
2909
def _rmtree_temp_dir(dirname):
3308
3069
def feature_name(self):
3309
3070
return 'FTPServer'
3312
3072
FTPServerFeature = _FTPServerFeature()
3315
class _HTTPSServerFeature(Feature):
3316
"""Some tests want an https Server, check if one is available.
3318
Right now, the only way this is available is under python2.6 which provides
3329
def feature_name(self):
3330
return 'HTTPSServer'
3333
HTTPSServerFeature = _HTTPSServerFeature()
3336
class _UnicodeFilename(Feature):
3337
"""Does the filesystem support Unicode filenames?"""
3342
except UnicodeEncodeError:
3344
except (IOError, OSError):
3345
# The filesystem allows the Unicode filename but the file doesn't
3349
# The filesystem allows the Unicode filename and the file exists,
3353
UnicodeFilename = _UnicodeFilename()
3356
class _UTF8Filesystem(Feature):
3357
"""Is the filesystem UTF-8?"""
3360
if osutils._fs_enc.upper() in ('UTF-8', 'UTF8'):
3364
UTF8Filesystem = _UTF8Filesystem()
3367
class _CaseInsCasePresFilenameFeature(Feature):
3368
"""Is the file-system case insensitive, but case-preserving?"""
3371
fileno, name = tempfile.mkstemp(prefix='MixedCase')
3373
# first check truly case-preserving for created files, then check
3374
# case insensitive when opening existing files.
3375
name = osutils.normpath(name)
3376
base, rel = osutils.split(name)
3377
found_rel = osutils.canonical_relpath(base, name)
3378
return (found_rel == rel
3379
and os.path.isfile(name.upper())
3380
and os.path.isfile(name.lower()))
3385
def feature_name(self):
3386
return "case-insensitive case-preserving filesystem"
3388
CaseInsCasePresFilenameFeature = _CaseInsCasePresFilenameFeature()
3391
3075
class _CaseInsensitiveFilesystemFeature(Feature):
3392
"""Check if underlying filesystem is case-insensitive but *not* case
3076
"""Check if underlined filesystem is case-insensitive
3077
(e.g. on Windows, Cygwin, MacOS)
3395
# Note that on Windows, Cygwin, MacOS etc, the file-systems are far
3396
# more likely to be case preserving, so this case is rare.
3398
3080
def _probe(self):
3399
if CaseInsCasePresFilenameFeature.available():
3402
3081
if TestCaseWithMemoryTransport.TEST_ROOT is None:
3403
3082
root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
3404
3083
TestCaseWithMemoryTransport.TEST_ROOT = root