327
330
self.report_unsupported(test, feature)
329
332
def _addSkipped(self, test, skip_excinfo):
330
self.report_skip(test, skip_excinfo)
331
# seems best to treat this as success from point-of-view of
332
# unittest -- it actually does nothing so it barely matters :)
333
if isinstance(skip_excinfo[1], TestNotApplicable):
334
self.not_applicable_count += 1
335
self.report_not_applicable(test, skip_excinfo)
338
self.report_skip(test, skip_excinfo)
335
341
except KeyboardInterrupt:
441
448
self._test_description(test), err[1])
443
450
def report_skip(self, test, skip_excinfo):
446
# at the moment these are mostly not things we can fix
447
# and so they just produce stipple; use the verbose reporter
450
# show test and reason for skip
451
self.pb.note('SKIP: %s\n %s\n',
452
self._shortened_test_description(test),
455
# since the class name was left behind in the still-visible
457
self.pb.note('SKIP: %s', skip_excinfo[1])
453
def report_not_applicable(self, test, skip_excinfo):
459
456
def report_unsupported(self, test, feature):
460
457
"""test cannot be run because feature is missing."""
520
517
self.stream.flush()
522
519
def report_skip(self, test, skip_excinfo):
524
520
self.stream.writeln(' SKIP %s\n%s'
525
521
% (self._testTimeString(test),
526
522
self._error_summary(skip_excinfo)))
524
def report_not_applicable(self, test, skip_excinfo):
525
self.stream.writeln(' N/A %s\n%s'
526
% (self._testTimeString(test),
527
self._error_summary(skip_excinfo)))
528
529
def report_unsupported(self, test, feature):
529
530
"""test cannot be run because feature is missing."""
530
531
self.stream.writeln("NODEP %s\n The feature '%s' is not available."
629
630
"""Indicates that a test was intentionally skipped, rather than failing."""
633
class TestNotApplicable(TestSkipped):
634
"""A test is not applicable to the situation where it was run.
636
This is only normally raised by parameterized tests, if they find that
637
the instance they're constructed upon does not support one aspect
632
642
class KnownFailure(AssertionError):
633
643
"""Indicates that a test failed in a precisely expected manner.
1671
1681
self.addCleanup(resetTimeout)
1672
1682
bzrlib.lockdir._DEFAULT_TIMEOUT_SECONDS = 0
1684
def make_utf8_encoded_stringio(self, encoding_type=None):
1685
"""Return a StringIOWrapper instance, that will encode Unicode
1688
if encoding_type is None:
1689
encoding_type = 'strict'
1691
output_encoding = 'utf-8'
1692
sio = codecs.getwriter(output_encoding)(sio, errors=encoding_type)
1693
sio.encoding = output_encoding
1675
1697
class TestCaseWithMemoryTransport(TestCase):
1676
1698
"""Common test class for tests that do not need disk resources.
2474
2496
except ValueError, e:
2475
2497
print '**failed to get doctest for: %s\n%s' %(m,e)
2477
for name, plugin in bzrlib.plugin.all_plugins().items():
2478
if getattr(plugin, 'test_suite', None) is not None:
2479
default_encoding = sys.getdefaultencoding()
2481
plugin_suite = plugin.test_suite()
2482
except ImportError, e:
2483
bzrlib.trace.warning(
2484
'Unable to test plugin "%s": %s', name, e)
2499
default_encoding = sys.getdefaultencoding()
2500
for name, plugin in bzrlib.plugin.plugins().items():
2502
plugin_suite = plugin.test_suite()
2503
except ImportError, e:
2504
bzrlib.trace.warning(
2505
'Unable to test plugin "%s": %s', name, e)
2507
if plugin_suite is not None:
2486
2508
suite.addTest(plugin_suite)
2487
if default_encoding != sys.getdefaultencoding():
2488
bzrlib.trace.warning(
2489
'Plugin "%s" tried to reset default encoding to: %s', name,
2490
sys.getdefaultencoding())
2492
sys.setdefaultencoding(default_encoding)
2509
if default_encoding != sys.getdefaultencoding():
2510
bzrlib.trace.warning(
2511
'Plugin "%s" tried to reset default encoding to: %s', name,
2512
sys.getdefaultencoding())
2514
sys.setdefaultencoding(default_encoding)
2518
def multiply_tests_from_modules(module_name_list, scenario_iter):
2519
"""Adapt all tests in some given modules to given scenarios.
2521
This is the recommended public interface for test parameterization.
2522
Typically the test_suite() method for a per-implementation test
2523
suite will call multiply_tests_from_modules and return the
2526
:param module_name_list: List of fully-qualified names of test
2528
:param scenario_iter: Iterable of pairs of (scenario_name,
2529
scenario_param_dict).
2531
This returns a new TestSuite containing the cross product of
2532
all the tests in all the modules, each repeated for each scenario.
2533
Each test is adapted by adding the scenario name at the end
2534
of its name, and updating the test object's __dict__ with the
2535
scenario_param_dict.
2537
>>> r = multiply_tests_from_modules(
2538
... ['bzrlib.tests.test_sampler'],
2539
... [('one', dict(param=1)),
2540
... ('two', dict(param=2))])
2541
>>> tests = list(iter_suite_tests(r))
2545
'bzrlib.tests.test_sampler.DemoTest.test_nothing(one)'
2551
loader = TestLoader()
2553
adapter = TestScenarioApplier()
2554
adapter.scenarios = list(scenario_iter)
2555
adapt_modules(module_name_list, adapter, loader, suite)