Rev 3174: Add tests for run_suite. in file:///v/home/vila/src/bzr/experimental/selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Jan 10 15:51:59 GMT 2008
At file:///v/home/vila/src/bzr/experimental/selftest/
------------------------------------------------------------
revno: 3174
revision-id:v.ladeuil+lp at free.fr-20080110155154-eg6c2an9ipdjnv31
parent: v.ladeuil+lp at free.fr-20080110101445-zgxudx4bq2q41352
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest
timestamp: Thu 2008-01-10 16:51:54 +0100
message:
Add tests for run_suite.
* bzrlib/tests/test_selftest.py:
(TestSelftestLoader): Add tests for loading and running a test list.
* bzrlib/builtins.py:
(cmd_selftest.run): selftest now returns the TestResult and the
TestSuite runned. 'strict' is now handled locally.
* bzrlib/tests/__init__.py:
(run_suite): Now returns the test suite and the result.
(selftest): Delete 'strict' parameter.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-12-29 18:55:20 +0000
+++ b/bzrlib/builtins.py 2008-01-10 15:51:54 +0000
@@ -2637,29 +2637,34 @@
else:
test_suite_factory = None
benchfile = None
+
+ success = None
try:
- result = selftest(verbose=verbose,
- pattern=pattern,
- stop_on_failure=one,
- transport=transport,
- test_suite_factory=test_suite_factory,
- lsprof_timed=lsprof_timed,
- bench_history=benchfile,
- matching_tests_first=first,
- list_only=list_only,
- random_seed=randomize,
- exclude_pattern=exclude,
- strict=strict,
- coverage_dir=coverage,
- )
+ result, suite = selftest(verbose=verbose,
+ pattern=pattern,
+ stop_on_failure=one,
+ transport=transport,
+ test_suite_factory=test_suite_factory,
+ lsprof_timed=lsprof_timed,
+ bench_history=benchfile,
+ matching_tests_first=first,
+ list_only=list_only,
+ random_seed=randomize,
+ exclude_pattern=exclude,
+ coverage_dir=coverage,
+ )
+ if strict:
+ success = result.wasStrictlySuccessful()
+ else:
+ success = result.wasSuccessful()
finally:
if benchfile is not None:
benchfile.close()
- if result:
+ if success:
info('tests passed')
else:
info('tests failed')
- return int(not result)
+ return int(not success)
class cmd_version(Command):
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-01-10 10:14:45 +0000
+++ b/bzrlib/tests/__init__.py 2008-01-10 15:51:54 +0000
@@ -2425,7 +2425,6 @@
list_only=False,
random_seed=None,
exclude_pattern=None,
- strict=False,
coverage_dir=None,
):
TestCase._gather_lsprof_in_benchmarks = lsprof_timed
@@ -2482,11 +2481,7 @@
results = tracer.results()
results.write_results(show_missing=1, summary=False,
coverdir=coverage_dir)
-
- if strict:
- return result.wasStrictlySuccessful()
-
- return result.wasSuccessful()
+ return result, suite
def selftest(verbose=False, pattern=".*", stop_on_failure=True,
@@ -2498,7 +2493,6 @@
list_only=False,
random_seed=None,
exclude_pattern=None,
- strict=False,
coverage_dir=None,
):
"""Run the whole test suite under the enhanced runner"""
@@ -2527,7 +2521,6 @@
list_only=list_only,
random_seed=random_seed,
exclude_pattern=exclude_pattern,
- strict=strict,
coverage_dir=coverage_dir)
finally:
default_transport = old_transport
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2008-01-10 10:14:45 +0000
+++ b/bzrlib/tests/test_selftest.py 2008-01-10 15:51:54 +0000
@@ -1848,16 +1848,23 @@
"""Tests for saving/loading test lists."""
def _create_test_list(self):
+
+ class Stub(TestCase):
+ def test_foo(self):
+ pass
+
suite = tests.TestSuite()
-
- class Stub(TestCase):
- def test_foo(self):
- pass
-
test = Stub('test_foo')
suite.addTest(test)
return suite
+ def _run_suite(self, suite, **kwargs):
+ out = StringIO()
+ err = StringIO()
+ result, runned_suite = self.apply_redirected(
+ out, err, None, tests.run_suite, suite, **kwargs)
+ return result, runned_suite
+
def test_save_test_list(self):
suite = self._create_test_list()
test_list_fname = 'test.list'
@@ -1875,3 +1882,23 @@
suite = tests.load_test_list(test_list_fname)
self.assertIsInstance(suite, TestSuite)
+
+ def test_loaded_tests_runned(self):
+ suite = self._create_test_list()
+ ref_test_id = tests.iter_suite_tests(suite).next().id()
+
+ out = StringIO()
+ err = StringIO()
+ result, runned_suite = self._run_suite(suite)
+ runned_tests = list(tests.iter_suite_tests(runned_suite))
+ self.assertEqual(1, len(runned_tests))
+ self.assertEqual(1, result.testsRun)
+ self.assertEquals(ref_test_id, runned_tests[0].id())
+
+ def test_loaded_tests_filtered(self):
+ suite = self._create_test_list()
+ result, runned_suite = self._run_suite(suite, pattern='not_matched')
+ runned_tests = list(tests.iter_suite_tests(runned_suite))
+ self.assertEqual([], runned_tests)
+ self.assertEqual(0, result.testsRun)
+
More information about the bazaar-commits
mailing list