s4-python: Install external included packages only if they're not present on the...
[nivanova/samba-autobuild/.git] / lib / testtools / testtools / tests / test_testsuite.py
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.matchers import (
15     Equals,
16     )
17 from testtools.tests.helpers import LoggingResult
18
19
20 class TestConcurrentTestSuiteRun(TestCase):
21
22     def test_trivial(self):
23         log = []
24         result = LoggingResult(log)
25         class Sample(TestCase):
26             def __hash__(self):
27                 return id(self)
28
29             def test_method1(self):
30                 pass
31             def test_method2(self):
32                 pass
33         test1 = Sample('test_method1')
34         test2 = Sample('test_method2')
35         original_suite = unittest.TestSuite([test1, test2])
36         suite = ConcurrentTestSuite(original_suite, self.split_suite)
37         suite.run(result)
38         test1 = log[0][1]
39         test2 = log[-1][1]
40         self.assertIsInstance(test1, Sample)
41         self.assertIsInstance(test2, Sample)
42         self.assertNotEqual(test1.id(), test2.id())
43         # We expect the start/outcome/stop to be grouped
44         expected = [('startTest', test1), ('addSuccess', test1),
45             ('stopTest', test1), ('startTest', test2), ('addSuccess', test2),
46             ('stopTest', test2)]
47         self.assertThat(log, Equals(expected))
48
49     def split_suite(self, suite):
50         tests = list(iterate_tests(suite))
51         return tests[0], tests[1]
52
53
54 def test_suite():
55     from unittest import TestLoader
56     return TestLoader().loadTestsFromName(__name__)