~dingqi-lxb/percona-server/5.5_log_queries_in_memory

« back to all changes in this revision

Viewing changes to python-for-subunit2junitxml/testtools/tests/test_testsuite.py

  • Committer: Stewart Smith
  • Date: 2011-10-06 07:49:44 UTC
  • mfrom: (175.1.4 5.5)
  • Revision ID: stewart@flamingspork.com-20111006074944-xtwnccssnymjqfj0
Merge subunit support for mtr

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2009 testtools developers. See LICENSE for details.
 
2
 
 
3
"""Test ConcurrentTestSuite and related things."""
 
4
 
 
5
__metaclass__ = type
 
6
 
 
7
import datetime
 
8
import unittest
 
9
 
 
10
from testtools import (
 
11
    ConcurrentTestSuite,
 
12
    iterate_tests,
 
13
    TestCase,
 
14
    )
 
15
from testtools.matchers import (
 
16
    Equals,
 
17
    )
 
18
from testtools.tests.helpers import LoggingResult
 
19
 
 
20
 
 
21
class TestConcurrentTestSuiteRun(TestCase):
 
22
 
 
23
    def test_trivial(self):
 
24
        log = []
 
25
        result = LoggingResult(log)
 
26
        class Sample(TestCase):
 
27
            def __hash__(self):
 
28
                return id(self)
 
29
 
 
30
            def test_method1(self):
 
31
                pass
 
32
            def test_method2(self):
 
33
                pass
 
34
        test1 = Sample('test_method1')
 
35
        test2 = Sample('test_method2')
 
36
        original_suite = unittest.TestSuite([test1, test2])
 
37
        suite = ConcurrentTestSuite(original_suite, self.split_suite)
 
38
        suite.run(result)
 
39
        # 0 is the timestamp for the first test starting.
 
40
        test1 = log[1][1]
 
41
        test2 = log[-1][1]
 
42
        self.assertIsInstance(test1, Sample)
 
43
        self.assertIsInstance(test2, Sample)
 
44
        self.assertNotEqual(test1.id(), test2.id())
 
45
 
 
46
    def split_suite(self, suite):
 
47
        tests = list(iterate_tests(suite))
 
48
        return tests[0], tests[1]
 
49
 
 
50
 
 
51
def test_suite():
 
52
    from unittest import TestLoader
 
53
    return TestLoader().loadTestsFromName(__name__)