~bzr/ubuntu/natty/python-testtools/bzr-ppa

« back to all changes in this revision

Viewing changes to testtools/tests/test_testsuite.py

Add a test suite and a test result to support concurrent testing.

Thanks to Robert Collins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2009 Jonathan M. Lange. See LICENSE for details.
 
2
 
 
3
"""Test ConcurrentTestSuite and related things."""
 
4
 
 
5
__metaclass__ = type
 
6
 
 
7
import unittest
 
8
 
 
9
from testtools import (
 
10
    ConcurrentTestSuite,
 
11
    iterate_tests,
 
12
    TestCase,
 
13
    )
 
14
from testtools.tests.helpers import LoggingResult
 
15
 
 
16
 
 
17
class TestConcurrentTestSuiteRun(TestCase):
 
18
 
 
19
    def test_trivial(self):
 
20
        log = []
 
21
        result = LoggingResult(log)
 
22
        class Sample(TestCase):
 
23
            def test_method(self):
 
24
                pass
 
25
        test1 = Sample('test_method')
 
26
        test2 = Sample('test_method')
 
27
        original_suite = unittest.TestSuite([test1, test2])
 
28
        suite = ConcurrentTestSuite(original_suite, self.split_suite)
 
29
        suite.run(result)
 
30
        try:
 
31
            self.assertEqual([('startTest', test1), ('addSuccess', test1), ('stopTest', test1),
 
32
                ('startTest', test2), ('addSuccess', test2), ('stopTest', test2)], log)
 
33
        except AssertionError:
 
34
            self.assertEqual([('startTest', test2), ('addSuccess', test2), ('stopTest', test2),
 
35
                ('startTest', test1), ('addSuccess', test1), ('stopTest', test1)], log)
 
36
 
 
37
    def split_suite(self, suite):
 
38
        tests = list(iterate_tests(suite))
 
39
        return tests[0], tests[1]
 
40
 
 
41
 
 
42
def test_suite():
 
43
    from unittest import TestLoader
 
44
    return TestLoader().loadTestsFromName(__name__)