/usr/share/pyshared/bzrlib/tests/scenarios.py is in python-bzrlib.tests 2.5.0-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # Copyright (C) 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Generate multiple variations in different scenarios.
For a class whose tests should be repeated in varying scenarios, set a
`scenarios` member to a list of scenarios where it should be repeated.
This is similar to the interface provided by
<http://launchpad.net/testscenarios/>.
"""
from bzrlib.tests import (
iter_suite_tests,
multiply_scenarios,
multiply_tests,
)
def load_tests_apply_scenarios(standard_tests, module, loader):
"""Multiply tests depending on their 'scenarios' attribute.
This can be assigned to 'load_tests' in any test module to make this
automatically work across tests in the module.
"""
result = loader.suiteClass()
multiply_tests_by_their_scenarios(standard_tests, result)
return result
def multiply_tests_by_their_scenarios(some_tests, into_suite):
"""Multiply the tests in the given suite by their declared scenarios.
Each test must have a 'scenarios' attribute which is a list of
(name, params) pairs.
:param some_tests: TestSuite or Test.
:param into_suite: A TestSuite into which the resulting tests will be
inserted.
"""
for test in iter_suite_tests(some_tests):
scenarios = getattr(test, 'scenarios', None)
if scenarios is None:
into_suite.addTest(test)
else:
multiply_tests(test, test.scenarios, into_suite)
|