b.t.__init__ : module documentation

Part of bzrlib.tests

Testing framework extensions
Function override_os_environ Modify os.environ keeping a copy.
Function restore_os_environ Restore os.environ to its original state.
Class ExtendedTestResult Accepts, reports and accumulates the results of running tests.
Class TextTestResult Displays progress and results of tests in text form
Class VerboseTestResult Produce long output, with one line per test run plus times
Class TextTestRunner No class docstring; 2/2 methods documented
Function iter_suite_tests Return all tests in a suite, recursing through nested suites
Class TestNotApplicable A test is not applicable to the situation where it was run.
Class UnavailableFeature A feature required for this test was not available.
Class StringIOWrapper A wrapper around cStringIO which just adds an encoding attribute.
Class TestUIFactory A UI Factory for testing.
Function isolated_doctest_setUp Undocumented
Function isolated_doctest_tearDown Undocumented
Function IsolatedDocTestSuite Overrides doctest.DocTestSuite to handle isolation.
Class TestCase Base class for bzr unit tests.
Class CapturedCall A helper for capturing smart server calls for easy debug analysis.
Class TestCaseWithMemoryTransport Common test class for tests that do not need disk resources.
Class TestCaseInTempDir Derived class that runs a test within a temporary directory.
Class TestCaseWithTransport A test case that provides get_url and get_readonly_url facilities.
Class ChrootedTestCase A support class that provides readonly urls outside the local namespace.
Function condition_id_re Create a condition filter which performs a re check on a test's id.
Function condition_isinstance Create a condition filter which returns isinstance(param, klass).
Function condition_id_in_list Create a condition filter which verify that test's id in a list.
Function condition_id_startswith Create a condition filter verifying that test's id starts with a string.
Function exclude_tests_by_condition Create a test suite which excludes some tests from suite.
Function filter_suite_by_condition Create a test suite by filtering another one.
Function filter_suite_by_re Create a test suite by filtering another one.
Function filter_suite_by_id_list Create a test suite by filtering another one.
Function filter_suite_by_id_startswith Create a test suite by filtering another one.
Function exclude_tests_by_re Create a test suite which excludes some tests from suite.
Function preserve_input A helper for performing test suite transformation chains.
Function randomize_suite Return a new TestSuite with suite's tests in random order.
Function split_suite_by_condition Split a test suite into two by a condition.
Function split_suite_by_re Split a test suite into two by a regular expression.
Function run_suite Run a test suite for bzr selftest.
Function fork_decorator Undocumented
Function subprocess_decorator Undocumented
Function exclude_tests Return a test suite decorator that excludes tests.
Function filter_tests Undocumented
Function random_order Return a test suite decorator factory for randomising tests order.
Function tests_first Undocumented
Function identity_decorator Return suite.
Class TestDecorator A decorator for TestCase/TestSuite objects.
Class CountingDecorator A decorator which calls result.progress(self.countTestCases).
Class ExcludeDecorator A decorator which excludes test matching an exclude pattern.
Class FilterTestsDecorator A decorator which filters tests to those matching a pattern.
Class RandomDecorator A decorator which randomises the order of its tests.
Class TestFirstDecorator A decorator which moves named tests to the front.
Function partition_tests Partition suite into count lists of tests.
Function workaround_zealous_crypto_random Crypto.Random want to help us being secure, but we don't care here.
Function fork_for_tests Take suite and start up one runner per CPU by forking()
Function reinvoke_for_tests Take suite and start up one runner per CPU using subprocess().
Class ProfileResult Generate profiling data for all activity between start and success.
Function selftest Run the whole test suite under the enhanced runner
Function load_test_id_list Load a test id list from a text file.
Function suite_matches_id_list Warns about tests not appearing or appearing more than once.
Class TestIdList Test id list to filter a test suite.
Class TestPrefixAliasRegistry A registry for test prefix aliases.
Function test_suite Build and return TestSuite for the whole of bzrlib.
Function multiply_scenarios Multiply two or more iterables of scenarios.
Function multiply_tests Multiply tests_list by scenarios into result.
Function apply_scenarios Apply the scenarios in scenarios to test and add to result.
Function apply_scenario Copy test and apply scenario to it.
Function clone_test Clone a test giving it a new id.
Function permute_tests_for_extension Helper for permutating tests against an extension module.
Function probe_unicode_in_user_encoding Try to encode several unicode strings to use in unicode-aware tests.
Function probe_bad_non_ascii Try to find [bad] character with code [128..255]
Class SubUnitBzrProtocolClient Undocumented
Class SubUnitBzrRunner Undocumented
Function ModuleAvailableFeature Undocumented
Function _clear__type_equality_funcs Cleanup bound methods stored on TestCase instances
Function _clever_some_str Undocumented
Function _test_suite_testmod_names Return the standard list of test module names to test.
Function _test_suite_modules_to_doctest Return the list of modules to doctest.
Function _multiply_two_scenarios Multiply two sets of scenarios.
Function _rmtree_temp_dir Undocumented
def override_os_environ(test, env=None):
Modify os.environ keeping a copy.
ParameterstestA test instance
envA dict containing variable definitions to be installed
def restore_os_environ(test):
Restore os.environ to its original state.
ParameterstestA test instance previously passed to override_os_environ.
def _clear__type_equality_funcs(test):
Cleanup bound methods stored on TestCase instances

Clear the dict breaking a few (mostly) harmless cycles in the affected unittests released with Python 2.6 and initial Python 2.7 versions.

For a few revisions between Python 2.7.1 and Python 2.7.2 that annoyingly shipped in Oneiric, an object with no clear method was used, hence the extra complications, see bug 809048 for details.

def iter_suite_tests(suite):
Return all tests in a suite, recursing through nested suites
def _clever_some_str(value):
Undocumented
def isolated_doctest_setUp(test):
Undocumented
def isolated_doctest_tearDown(test):
Undocumented
def IsolatedDocTestSuite(*args, **kwargs):
Overrides doctest.DocTestSuite to handle isolation.

The method is really a factory and users are expected to use it as such.

def condition_id_re(pattern):
Create a condition filter which performs a re check on a test's id.
ParameterspatternA regular expression string.
ReturnsA callable that returns True if the re matches.
def condition_isinstance(klass_or_klass_list):
Create a condition filter which returns isinstance(param, klass).
ReturnsA callable which when called with one parameter obj return the result of isinstance(obj, klass_or_klass_list).
def condition_id_in_list(id_list):
Create a condition filter which verify that test's id in a list.
Parametersid_listA TestIdList object.
ReturnsA callable that returns True if the test's id appears in the list.
def condition_id_startswith(starts):
Create a condition filter verifying that test's id starts with a string.
ParametersstartsA list of string.
ReturnsA callable that returns True if the test's id starts with one of the given strings.
def exclude_tests_by_condition(suite, condition):
Create a test suite which excludes some tests from suite.
ParameterssuiteThe suite to get tests from.
conditionA callable whose result evaluates True when called with a test case which should be excluded from the result.
ReturnsA suite which contains the tests found in suite that fail condition.
def filter_suite_by_condition(suite, condition):
Create a test suite by filtering another one.
ParameterssuiteThe source suite.
conditionA callable whose result evaluates True when called with a test case which should be included in the result.
ReturnsA suite which contains the tests found in suite that pass condition.
def filter_suite_by_re(suite, pattern):
Create a test suite by filtering another one.
Parameterssuitethe source suite
patternpattern that names must match
Returnsthe newly created suite
def filter_suite_by_id_list(suite, test_id_list):
Create a test suite by filtering another one.
ParameterssuiteThe source suite.
test_id_listA list of the test ids to keep as strings.
Returnsthe newly created suite
def filter_suite_by_id_startswith(suite, start):
Create a test suite by filtering another one.
ParameterssuiteThe source suite.
startA list of string the test id must start with one of.
Returnsthe newly created suite
def exclude_tests_by_re(suite, pattern):
Create a test suite which excludes some tests from suite.
ParameterssuiteThe suite to get tests from.
patternA regular expression string. Test ids that match this pattern will be excluded from the result.
ReturnsA TestSuite that contains all the tests from suite without the tests that matched pattern. The order of tests is the same as it was in suite.
def preserve_input(something):
A helper for performing test suite transformation chains.
ParameterssomethingAnything you want to preserve.
ReturnsSomething.
def randomize_suite(suite):
Return a new TestSuite with suite's tests in random order.

The tests in the input suite are flattened into a single suite in order to accomplish this. Any nested TestSuites are removed to provide global randomness.

def split_suite_by_condition(suite, condition):
Split a test suite into two by a condition.
ParameterssuiteThe suite to split.
conditionThe condition to match on. Tests that match this condition are returned in the first test suite, ones that do not match are in the second suite.
ReturnsA tuple of two test suites, where the first contains tests from suite matching the condition, and the second contains the remainder from suite. The order within each output suite is the same as it was in suite.
def split_suite_by_re(suite, pattern):
Split a test suite into two by a regular expression.
ParameterssuiteThe suite to split.
patternA regular expression string. Test ids that match this pattern will be in the first test suite returned, and the others in the second test suite returned.
ReturnsA tuple of two test suites, where the first contains tests from suite matching pattern, and the second contains the remainder from suite. The order within each output suite is the same as it was in suite.
def run_suite(suite, name='test', verbose=False, pattern='.*', stop_on_failure=False, transport=None, lsprof_timed=None, bench_history=None, matching_tests_first=None, list_only=False, random_seed=None, exclude_pattern=None, strict=False, runner_class=None, suite_decorators=None, stream=None, result_decorators=None):
Run a test suite for bzr selftest.
Parametersrunner_classThe class of runner to use. Must support the constructor arguments passed by run_suite which are more than standard python uses.
ReturnsA boolean indicating success.
def fork_decorator(suite):
Undocumented
def subprocess_decorator(suite):
Undocumented
def exclude_tests(exclude_pattern):
Return a test suite decorator that excludes tests.
def filter_tests(pattern):
Undocumented
def random_order(random_seed, runner):
Return a test suite decorator factory for randomising tests order.
Parametersrandom_seednow, a string which casts to a long, or a long.
runnerA test runner with a stream attribute to report on.
def tests_first(pattern):
Undocumented
def identity_decorator(suite):
Return suite.
def partition_tests(suite, count):
Partition suite into count lists of tests.
def workaround_zealous_crypto_random():
Crypto.Random want to help us being secure, but we don't care here.

This workaround some test failure related to the sftp server. Once paramiko stop using the controversial API in Crypto.Random, we may get rid of it.

def fork_for_tests(suite):
Take suite and start up one runner per CPU by forking()
ReturnsAn iterable of TestCase-like objects which can each have run(result) called on them to feed tests to result.
def reinvoke_for_tests(suite):
Take suite and start up one runner per CPU using subprocess().
ReturnsAn iterable of TestCase-like objects which can each have run(result) called on them to feed tests to result.
def selftest(verbose=False, pattern='.*', stop_on_failure=True, transport=None, test_suite_factory=None, lsprof_timed=None, bench_history=None, matching_tests_first=None, list_only=False, random_seed=None, exclude_pattern=None, strict=False, load_list=None, debug_flags=None, starting_with=None, runner_class=None, suite_decorators=None, stream=None, lsprof_tests=False):
Run the whole test suite under the enhanced runner
def load_test_id_list(file_name):
Load a test id list from a text file.

The format is one test id by line. No special care is taken to impose strict rules, these test ids are used to filter the test suite so a test id that do not match an existing test will do no harm. This allows user to add comments, leave blank lines, etc.

def suite_matches_id_list(test_suite, id_list):
Warns about tests not appearing or appearing more than once.

When using a prefined test id list, it may occurs that some tests do not exist anymore or that some tests use the same id. This function warns the tester about potential problems in his workflow (test lists are volatile) or in the test suite itself (using the same id for several tests does not help to localize defects).

Parameterstest_suiteA TestSuite object.
test_id_listThe list of test ids that should be found in test_suite.
Returns(absents, duplicates) absents is a list containing the test found in id_list but not in test_suite, duplicates is a list containing the test found multiple times in test_suite.
def _test_suite_testmod_names():
Return the standard list of test module names to test.
def _test_suite_modules_to_doctest():
Return the list of modules to doctest.
def test_suite(keep_only=None, starting_with=None):
Build and return TestSuite for the whole of bzrlib.

This function can be replaced if you need to change the default test suite on a global basis, but it is not encouraged.

Parameterskeep_onlyA list of test ids limiting the suite returned.
starting_withAn id limiting the suite returned to the tests starting with it.
def multiply_scenarios(*scenarios):
Multiply two or more iterables of scenarios.

It is safe to pass scenario generators or iterators.

ReturnsA list of compound scenarios: the cross-product of all scenarios, with the names concatenated and the parameters merged together.
def _multiply_two_scenarios(scenarios_left, scenarios_right):
Multiply two sets of scenarios.
Returnsthe cartesian product of the two sets of scenarios, that is a scenario for every possible combination of a left scenario and a right scenario.
def multiply_tests(tests, scenarios, result):

Multiply tests_list by scenarios into result.

This is the core workhorse for test parameterisation.

Typically the load_tests() method for a per-implementation test suite will call multiply_tests and return the result.

This returns the passed in result TestSuite with the cross product of all the tests repeated once for each scenario. Each test is adapted by adding the scenario name at the end of its id(), and updating the test object's __dict__ with the scenario_param_dict.

>>> import bzrlib.tests.test_sampler
>>> r = multiply_tests(
...     bzrlib.tests.test_sampler.DemoTest('test_nothing'),
...     [('one', dict(param=1)),
...      ('two', dict(param=2))],
...     TestUtil.TestSuite())
>>> tests = list(iter_suite_tests(r))
>>> len(tests)
2
>>> tests[0].id()
'bzrlib.tests.test_sampler.DemoTest.test_nothing(one)'
>>> tests[0].param
1
>>> tests[1].param
2
ParameterstestsThe tests to parameterise.
scenariosThe scenarios to apply: pairs of (scenario_name, scenario_param_dict).
resultA TestSuite to add created tests to.
def apply_scenarios(test, scenarios, result):
Apply the scenarios in scenarios to test and add to result.
ParameterstestThe test to apply scenarios to.
scenariosAn iterable of scenarios to apply to test.
Returnsresult
See Alsoapply_scenario
def apply_scenario(test, scenario):
Copy test and apply scenario to it.
ParameterstestA test to adapt.
scenarioA tuple describing the scenarion. The first element of the tuple is the new test id. The second element is a dict containing attributes to set on the test.
ReturnsThe adapted test.
def clone_test(test, new_id):
Clone a test giving it a new id.
ParameterstestThe test to clone.
new_idThe id to assign to it.
ReturnsThe new test.
def permute_tests_for_extension(standard_tests, loader, py_module_name, ext_module_name):
Helper for permutating tests against an extension module.

This is meant to be used inside a modules 'load_tests()' function. It will create 2 scenarios, and cause all tests in the 'standard_tests' to be run against both implementations. Setting 'test.module' to the appropriate module. See bzrlib.tests.test__chk_map.load_tests as an example.

Parametersstandard_testsA test suite to permute
loaderA TestLoader
py_module_nameThe python path to a python module that can always be loaded, and will be considered the 'python' implementation. (eg 'bzrlib._chk_map_py')
ext_module_nameThe python path to an extension module. If the module cannot be loaded, a single test will be added, which notes that the module is not available. If it can be loaded, all standard_tests will be run against that module.
Returns(suite, feature) suite is a test-suite that has all the permuted tests. feature is the Feature object that can be used to determine if the module is available.
def _rmtree_temp_dir(dirname, test_id=None):
Undocumented
def probe_unicode_in_user_encoding():
Try to encode several unicode strings to use in unicode-aware tests. Return first successfull match.
Returns(unicode value, encoded plain string value) or (None, None)
def probe_bad_non_ascii(encoding):
Try to find [bad] character with code [128..255] that cannot be decoded to unicode in some encoding. Return None if all non-ascii characters is valid for given encoding.
@deprecated_function(deprecated_in((2, 5, 0)))
def ModuleAvailableFeature(name):
Undocumented
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.