def test_broken_runner(self): # If the object called breaks, the stream is informed about it # regardless. class BrokenTest: # broken - no result parameter! def __call__(self): pass def run(self): pass result = LoggingStream() cases = lambda: [(BrokenTest(), '0')] suite = ConcurrentStreamTestSuite(cases) suite.run(result) events = result._events # Check the traceback loosely. self.assertEqual(events[1][6].decode('utf8'), "Traceback (most recent call last):\n") self.assertThat( events[2][6].decode('utf8'), DocTestMatches( """\ File "...testtools/testsuite.py", line ..., in _run_test test.run(process_result) """, doctest.ELLIPSIS)) self.assertThat( events[3][6].decode('utf8'), DocTestMatches( """\ TypeError: run() takes ...1 ...argument...2...given... """, doctest.ELLIPSIS)) events = [event[0:10] + (None, ) for event in events] events[1] = events[1][:6] + (None, ) + events[1][7:] events[2] = events[2][:6] + (None, ) + events[2][7:] events[3] = events[3][:6] + (None, ) + events[3][7:] self.assertEqual([ ('status', "broken-runner-'0'", 'inprogress', None, True, None, None, False, None, '0', None), ('status', "broken-runner-'0'", None, None, True, 'traceback', None, False, 'text/x-traceback; charset="utf8"; language="python"', '0', None), ('status', "broken-runner-'0'", None, None, True, 'traceback', None, False, 'text/x-traceback; charset="utf8"; language="python"', '0', None), ('status', "broken-runner-'0'", None, None, True, 'traceback', None, True, 'text/x-traceback; charset="utf8"; language="python"', '0', None), ('status', "broken-runner-'0'", 'fail', set(), True, None, None, False, None, '0', None) ], events)
def test_trivial(self): result = LoggingStream() test1 = Sample('test_method1') test2 = Sample('test_method2') cases = lambda: [(test1, '0'), (test2, '1')] suite = ConcurrentStreamTestSuite(cases) suite.run(result) def freeze(set_or_none): if set_or_none is None: return set_or_none return frozenset(set_or_none) # Ignore event order: we're testing the code is all glued together, # which just means we can pump events through and they get route codes # added appropriately. self.assertEqual( { ( 'status', 'testtools.tests.test_testsuite.Sample.test_method1', 'inprogress', None, True, None, None, False, None, '0', None, ), ( 'status', 'testtools.tests.test_testsuite.Sample.test_method1', 'success', frozenset(), True, None, None, False, None, '0', None, ), ( 'status', 'testtools.tests.test_testsuite.Sample.test_method2', 'inprogress', None, True, None, None, False, None, '1', None, ), ( 'status', 'testtools.tests.test_testsuite.Sample.test_method2', 'success', frozenset(), True, None, None, False, None, '1', None, ), }, { event[0:3] + (freeze(event[3]), ) + event[4:10] + (None, ) for event in result._events })