def test_initial_time_forwarded(self):
     # We always forward the first time event we see.
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TimeCollapsingDecorator(result)
     a_time = self.make_time()
     tag_collapser.time(a_time)
     self.assertEqual([('time', a_time)], result._events)
 def test_only_one_time_sent(self):
     # If we receive a single time event followed by a non-time event, we
     # send exactly one time event.
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TimeCollapsingDecorator(result)
     a_time = self.make_time()
     tag_collapser.time(a_time)
     tag_collapser.startTest(pysubunit.RemotedTestCase('foo'))
     self.assertEqual([('time', a_time)], result._events[:-1])
 def test_duplicate_times_not_sent(self):
     # Many time events with the exact same time are collapsed into one
     # time event.
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TimeCollapsingDecorator(result)
     a_time = self.make_time()
     for i in range(5):
         tag_collapser.time(a_time)
     tag_collapser.startTest(pysubunit.RemotedTestCase('foo'))
     self.assertEqual([('time', a_time)], result._events[:-1])
 def test_tags_collapsed_outside_of_tests(self):
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TagCollapsingDecorator(result)
     tag_collapser.tags(set(['a']), set())
     tag_collapser.tags(set(['b']), set())
     tag_collapser.startTest(self)
     self.assertEqual([
         ('tags', set(['a', 'b']), set([])),
         ('startTest', self),
     ], result._events)
 def test_skip_preserved(self):
     subunit_stream = compat._b('\n'.join(["test: foo", "skip: foo", ""]))
     result = doubles.ExtendedTestResult()
     result_filter = test_results.TestResultFilter(result)
     self.run_tests(result_filter, subunit_stream)
     foo = pysubunit.RemotedTestCase('foo')
     self.assertEqual([
         ('startTest', foo),
         ('addSkip', foo, {}),
         ('stopTest', foo),
     ], result._events)
 def test_time_collapsed_to_first_and_last(self):
     # If there are many consecutive time events, only the first and last
     # are sent through.
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TimeCollapsingDecorator(result)
     times = [self.make_time() for i in range(5)]
     for a_time in times:
         tag_collapser.time(a_time)
     tag_collapser.startTest(pysubunit.RemotedTestCase('foo'))
     self.assertEqual([('time', times[0]), ('time', times[-1])],
                      result._events[:-1])
 def test_no_times_inserted(self):
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TimeCollapsingDecorator(result)
     a_time = self.make_time()
     tag_collapser.time(a_time)
     foo = pysubunit.RemotedTestCase('foo')
     tag_collapser.startTest(foo)
     tag_collapser.addSuccess(foo)
     tag_collapser.stopTest(foo)
     self.assertEqual([('time', a_time), ('startTest', foo),
                       ('addSuccess', foo), ('stopTest', foo)],
                      result._events)
 def test_tags_collapsed_inside_of_tests_different_ordering(self):
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TagCollapsingDecorator(result)
     test = pysubunit.RemotedTestCase('foo')
     tag_collapser.startTest(test)
     tag_collapser.tags(set(), set(['a']))
     tag_collapser.tags(set(['a', 'b']), set())
     tag_collapser.tags(set(['c']), set())
     tag_collapser.stopTest(test)
     self.assertEqual([('startTest', test),
                       ('tags', set(['a', 'b', 'c']), set()),
                       ('stopTest', test)], result._events)
 def test_tag_filter(self):
     tag_filter = test_results.make_tag_filter(['global'], ['local'])
     result = doubles.ExtendedTestResult()
     result_filter = test_results.TestResultFilter(
         result, filter_success=False, filter_predicate=tag_filter)
     self.run_tests(result_filter)
     tests_included = [
         event[1] for event in result._events if event[0] == 'startTest'
     ]
     tests_expected = list(
         map(pysubunit.RemotedTestCase,
             ['passed', 'error', 'skipped', 'todo']))
     self.assertEqual(tests_expected, tests_included)
 def test_tags_sent_before_result(self):
     # Because addSuccess and friends tend to send subunit output
     # immediately, and because 'tags:' before a result line means
     # something different to 'tags:' after a result line, we need to be
     # sure that tags are emitted before 'addSuccess' (or whatever).
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TagCollapsingDecorator(result)
     test = pysubunit.RemotedTestCase('foo')
     tag_collapser.startTest(test)
     tag_collapser.tags(set(['a']), set())
     tag_collapser.addSuccess(test)
     tag_collapser.stopTest(test)
     self.assertEqual([('startTest', test), ('tags', set(['a']), set()),
                       ('addSuccess', test), ('stopTest', test)],
                      result._events)
 def test_time_passes_through_filtered_tests(self):
     # Passing a subunit stream through TestResultFilter preserves 'time'
     # directives even if a specific test is filtered out.
     date_a = datetime(year=2000, month=1, day=1, tzinfo=iso8601.UTC)
     date_b = datetime(year=2000, month=1, day=2, tzinfo=iso8601.UTC)
     date_c = datetime(year=2000, month=1, day=3, tzinfo=iso8601.UTC)
     subunit_stream = compat._b('\n'.join([
         "time: %s", "test: foo", "time: %s", "success: foo", "time: %s", ""
     ]) % (date_a, date_b, date_c))
     result = doubles.ExtendedTestResult()
     result_filter = test_results.TestResultFilter(result)
     result_filter.startTestRun()
     self.run_tests(result_filter, subunit_stream)
     result_filter.stopTestRun()
     self.maxDiff = None
     self.assertEqual([('startTestRun', ), ('time', date_a),
                       ('time', date_c), ('stopTestRun', )], result._events)
 def test_tags_tracked_correctly(self):
     tag_filter = test_results.make_tag_filter(['a'], [])
     result = doubles.ExtendedTestResult()
     result_filter = test_results.TestResultFilter(
         result, filter_success=False, filter_predicate=tag_filter)
     input_stream = compat._b("test: foo\n"
                              "tags: a\n"
                              "successful: foo\n"
                              "test: bar\n"
                              "successful: bar\n")
     self.run_tests(result_filter, input_stream)
     foo = pysubunit.RemotedTestCase('foo')
     self.assertEqual([
         ('startTest', foo),
         ('tags', set(['a']), set()),
         ('addSuccess', foo),
         ('stopTest', foo),
     ], result._events)
 def test_time_ordering_preserved(self):
     # Passing a subunit stream through TestResultFilter preserves the
     # relative ordering of 'time' directives and any other subunit
     # directives that are still included.
     date_a = datetime(year=2000, month=1, day=1, tzinfo=iso8601.UTC)
     date_b = datetime(year=2000, month=1, day=2, tzinfo=iso8601.UTC)
     date_c = datetime(year=2000, month=1, day=3, tzinfo=iso8601.UTC)
     subunit_stream = compat._b('\n'.join([
         "time: %s", "test: foo", "time: %s", "error: foo", "time: %s", ""
     ]) % (date_a, date_b, date_c))
     result = doubles.ExtendedTestResult()
     result_filter = test_results.TestResultFilter(result)
     self.run_tests(result_filter, subunit_stream)
     foo = pysubunit.RemotedTestCase('foo')
     self.maxDiff = None
     self.assertEqual([('time', date_a), ('time', date_b),
                       ('startTest', foo), ('addError', foo, {}),
                       ('stopTest', foo), ('time', date_c)], result._events)
 def test_tags_forwarded_after_tests(self):
     test = pysubunit.RemotedTestCase('foo')
     result = doubles.ExtendedTestResult()
     tag_collapser = pysubunit.test_results.TagCollapsingDecorator(result)
     tag_collapser.startTestRun()
     tag_collapser.startTest(test)
     tag_collapser.addSuccess(test)
     tag_collapser.stopTest(test)
     tag_collapser.tags(set(['a']), set(['b']))
     tag_collapser.stopTestRun()
     self.assertEqual([
         ('startTestRun', ),
         ('startTest', test),
         ('addSuccess', test),
         ('stopTest', test),
         ('tags', set(['a']), set(['b'])),
         ('stopTestRun', ),
     ], result._events)