def test_with_subunit_shows_subunit_stream(self):
     ui, cmd = self.get_test_ui_and_cmd(options=[('subunit', True)])
     cmd.repository_factory = memory.RepositoryFactory()
     repo = cmd.repository_factory.initialise(ui.here)
     inserter = repo.get_inserter()
     inserter.startTestRun()
     inserter.status(test_id='failing', test_status='fail')
     inserter.status(test_id='ok', test_status='success')
     inserter.stopTestRun()
     self.assertEqual(0, cmd.execute())
     self.assertEqual(1, len(ui.outputs))
     self.assertEqual('stream', ui.outputs[0][0])
     as_subunit = BytesIO(ui.outputs[0][1])
     stream = ByteStreamToStreamResult(as_subunit)
     log = StreamResult()
     log.startTestRun()
     try:
         stream.run(log)
     finally:
         log.stopTestRun()
     self.assertEqual(
         log._events, [
         ('startTestRun',),
         ('status', 'failing', 'inprogress', None, True, None, None, False,
          None, None, Wildcard),
         ('status', 'failing', 'fail', None, True, None, None, False, None,
          None, Wildcard),
         ('stopTestRun',)
         ])
Exemple #2
0
 def test_shows_subunit_stream(self):
     ui, cmd = self.get_test_ui_and_cmd(options=[('subunit', True)])
     cmd.repository_factory = memory.RepositoryFactory()
     repo = cmd.repository_factory.initialise(ui.here)
     self._add_run(repo)
     self.assertEqual(0, cmd.execute())
     # We should have seen test outputs (of the failure) and summary data.
     self.assertEqual([
         ('stream', Wildcard),
         ], ui.outputs)
     as_subunit = BytesIO(ui.outputs[0][1])
     stream = ByteStreamToStreamResult(as_subunit)
     log = StreamResult()
     log.startTestRun()
     try:
         stream.run(log)
     finally:
         log.stopTestRun()
     self.assertEqual(
         log._events, [
         ('startTestRun',),
         ('status', 'failing', 'fail', None, True, None, None, False,
          None, None, None),
         ('status', 'ok', 'success', None, True, None, None, False, None,
          None, None),
         ('stopTestRun',)
         ])
 def test_get_failing_get_subunit_stream(self):
     repo = self.repo_impl.initialise(self.sample_url)
     result = repo.get_inserter()
     legacy_result = testtools.ExtendedToStreamDecorator(result)
     legacy_result.startTestRun()
     make_test('testrepository.tests.test_repository.Case.method', False).run(legacy_result)
     legacy_result.stopTestRun()
     run = repo.get_failing()
     as_subunit = run.get_subunit_stream()
     stream = v2.ByteStreamToStreamResult(as_subunit)
     log = StreamResult()
     log.startTestRun()
     try:
         stream.run(log)
     finally:
         log.stopTestRun()
     self.assertEqual(
         [tuple(ev) for ev in log._events], [
         ('startTestRun',),
         ('status',
          'testrepository.tests.test_repository.Case.method',
          'inprogress',
          None,
          True,
          None,
          None,
          False,
          None,
          None,
          Wildcard),
         ('status',
          'testrepository.tests.test_repository.Case.method',
          None,
          None,
          True,
          'traceback',
          Wildcard,
          True,
          Wildcard,
          None,
          Wildcard),
         ('status',
          'testrepository.tests.test_repository.Case.method',
          'fail',
          None,
          True,
          None,
          None,
          False,
          None,
          None,
          Wildcard),
         ('stopTestRun',)
         ])
Exemple #4
0
def parse_enumeration(enumeration_bytes):
    """Parse enumeration_bytes into a list of test_ids."""
    parser = ByteStreamToStreamResult(BytesIO(enumeration_bytes),
        non_subunit_name='stdout')
    result = StreamResult()
    parser.run(result)
    return [event[1] for event in result._events if event[2]=='exists']
Exemple #5
0
 def test_hypothesis_decoding(self, code_bytes):
     source = BytesIO(code_bytes)
     result = StreamResult()
     stream = subunit.ByteStreamToStreamResult(source,
                                               non_subunit_name="stdout")
     stream.run(result)
     self.assertEqual(b'', source.read())
Exemple #6
0
 def setUp(self):
     super(AsyncByteStreamToStreamResultTest, self).setUp()
     self.result = StreamResult()
     self.stream = AsyncBytesIO()
     self.encoder = StreamResultToBytes(self.stream.buffer)
     self.decoder = AsyncByteStreamToStreamResult(self.stream)
     self.decoder.run(self.result)
 def test_non_subunit_disabled_raises(self):
     source = BytesIO(b"foo\nbar\n")
     result = StreamResult()
     case = subunit.ByteStreamToStreamResult(source)
     e = self.assertRaises(Exception, case.run, result)
     self.assertEqual(b'f', e.args[1])
     self.assertEqual(b'oo\nbar\n', source.read())
     self.assertEqual([], result._events)
 def test_get_subunit_from_test_run(self):
     repo = self.repo_impl.initialise(self.sample_url)
     result = repo.get_inserter()
     legacy_result = testtools.ExtendedToStreamDecorator(result)
     legacy_result.startTestRun()
     make_test('testrepository.tests.test_repository.Case.method', True).run(legacy_result)
     legacy_result.stopTestRun()
     inserted = result.get_id()
     run = repo.get_test_run(inserted)
     as_subunit = run.get_subunit_stream()
     stream = v2.ByteStreamToStreamResult(as_subunit)
     log = StreamResult()
     log.startTestRun()
     try:
         stream.run(log)
     finally:
         log.stopTestRun()
     self.assertEqual(
         log._events,
         [
         ('startTestRun',),
         ('status',
          'testrepository.tests.test_repository.Case.method',
          'inprogress',
          None,
          True,
          None,
          None,
          False,
          None,
          None,
          Wildcard),
         ('status',
          'testrepository.tests.test_repository.Case.method',
          'success',
          None,
          True,
          None,
          None,
          False,
          None,
          None,
          Wildcard),
         ('stopTestRun',)
         ])
 def test_trivial_enumeration(self):
     source = BytesIO(CONSTANT_ENUM)
     result = StreamResult()
     subunit.ByteStreamToStreamResult(source,
                                      non_subunit_name="stdout").run(result)
     self.assertEqual(b'', source.read())
     self.assertEqual([
         ('status', 'foo', 'exists', None, True, None, None, False, None,
          None, None),
     ], result._events)
Exemple #10
0
 def test_includes_timing_output(self):
     bytestream = io.BytesIO()
     runner = SubunitTestRunner(stream=bytestream)
     test = PlaceHolder('name')
     runner.run(test)
     bytestream.seek(0)
     eventstream = StreamResult()
     subunit.ByteStreamToStreamResult(bytestream).run(eventstream)
     timestamps = [event[-1] for event in eventstream._events
         if event is not None]
     self.assertNotEqual([], timestamps)
 def check_events(self, source_bytes, events):
     source = BytesIO(source_bytes)
     result = StreamResult()
     subunit.ByteStreamToStreamResult(source,
                                      non_subunit_name="stdout").run(result)
     self.assertEqual(b'', source.read())
     self.assertEqual(events, result._events)
     #- any file attachments should be byte contents [as users assume that].
     for event in result._events:
         if event[5] is not None:
             self.assertIsInstance(event[6], bytes)
    def test_add_tests(self):
        class DummyTest(TestCase):
            def test(self):
                logging.info("hello")

        suite = LoggingSuite([DummyTest(methodName="test")])
        result = StreamResult()
        suite.run(
            AutoTimingTestResultDecorator(ExtendedToStreamDecorator(result)))
        event = result._events[2]
        self.assertIn("DummyTest.test", event[1])
        self.assertEqual(b("hello\n"), event[6])
def get_result_for(commands):
    """Get a result object from *commands.

    Runs the 'generate_stream_results' function from subunit._output after
    parsing *commands as if they were specified on the command line. The
    resulting bytestream is then converted back into a result object and
    returned.
    """
    result = StreamResult()
    args = safe_parse_arguments(commands)
    generate_stream_results(args, result)
    return result
 def test_with_subunit_shows_subunit_stream(self):
     ui, cmd = self.get_test_ui_and_cmd(options=[('subunit', True)])
     cmd.repository_factory = memory.RepositoryFactory()
     repo = cmd.repository_factory.initialise(ui.here)
     inserter = repo.get_inserter()
     inserter.startTestRun()
     inserter.status(test_id='failing', test_status='fail')
     inserter.status(test_id='ok', test_status='success')
     inserter.stopTestRun()
     self.assertEqual(0, cmd.execute())
     self.assertEqual(1, len(ui.outputs))
     self.assertEqual('stream', ui.outputs[0][0])
     as_subunit = BytesIO(ui.outputs[0][1])
     stream = ByteStreamToStreamResult(as_subunit)
     log = StreamResult()
     log.startTestRun()
     try:
         stream.run(log)
     finally:
         log.stopTestRun()
     self.assertEqual([tuple(ev) for ev in log._events],
                      [('startTestRun', ),
                       ('status', 'failing', 'inprogress', None, True, None,
                        None, False, None, None, Wildcard),
                       ('status', 'failing', 'fail', None, True, None, None,
                        False, None, None, Wildcard), ('stopTestRun', )])
Exemple #15
0
 def test_get_subunit_from_test_run(self):
     repo = self.repo_impl.initialise(self.sample_url)
     result = repo.get_inserter()
     legacy_result = testtools.ExtendedToStreamDecorator(result)
     legacy_result.startTestRun()
     make_test('testrepository.tests.test_repository.Case.method',
               True).run(legacy_result)
     legacy_result.stopTestRun()
     inserted = result.get_id()
     run = repo.get_test_run(inserted)
     as_subunit = run.get_subunit_stream()
     stream = v2.ByteStreamToStreamResult(as_subunit)
     log = StreamResult()
     log.startTestRun()
     try:
         stream.run(log)
     finally:
         log.stopTestRun()
     self.assertEqual(
         [tuple(ev) for ev in log._events],
         [('startTestRun', ),
          ('status', 'testrepository.tests.test_repository.Case.method',
           'inprogress', None, True, None, None, False, None, None,
           Wildcard),
          ('status', 'testrepository.tests.test_repository.Case.method',
           'success', None, True, None, None, False, None, None, Wildcard),
          ('stopTestRun', )])
 def test_get_failing_get_subunit_stream(self):
     repo = self.repo_impl.initialise(self.sample_url)
     result = repo.get_inserter()
     legacy_result = testtools.ExtendedToStreamDecorator(result)
     legacy_result.startTestRun()
     make_test('testrepository.tests.test_repository.Case.method',
               False).run(legacy_result)
     legacy_result.stopTestRun()
     run = repo.get_failing()
     as_subunit = run.get_subunit_stream()
     stream = v2.ByteStreamToStreamResult(as_subunit)
     log = StreamResult()
     log.startTestRun()
     try:
         stream.run(log)
     finally:
         log.stopTestRun()
     self.assertEqual(
         log._events,
         [('startTestRun', ),
          ('status', 'testrepository.tests.test_repository.Case.method',
           'inprogress', None, True, None, None, False, None, None,
           Wildcard),
          ('status', 'testrepository.tests.test_repository.Case.method',
           None, None, True, 'traceback', Wildcard, True, Wildcard, None,
           Wildcard),
          ('status', 'testrepository.tests.test_repository.Case.method',
           'fail', None, True, None, None, False, None, None, Wildcard),
          ('stopTestRun', )])
Exemple #17
0
 def test_default(self):
     byte_stream = BytesIO()
     stream = StreamResultToBytes(byte_stream)
     stream.status(test_id="foo", test_status="inprogress")
     stream.status(test_id="foo", test_status="skip")
     output = self.run_command([], byte_stream.getvalue())
     events = StreamResult()
     ByteStreamToStreamResult(BytesIO(output)).run(events)
     ids = set(event[1] for event in events._events)
     self.assertEqual([
         ('status', 'foo', 'inprogress'),
         ('status', 'foo', 'skip'),
     ], [event[:3] for event in events._events])
Exemple #18
0
 def test_enumerates_tests_before_run(self):
     io = BytesIO()
     runner = SubunitTestRunner(stream=io)
     test1 = PlaceHolder('name1')
     test2 = PlaceHolder('name2')
     case = unittest.TestSuite([test1, test2])
     runner.run(case)
     io.seek(0)
     eventstream = StreamResult()
     subunit.ByteStreamToStreamResult(io).run(eventstream)
     self.assertEqual([
         ('status', 'name1', 'exists'),
         ('status', 'name2', 'exists'),
     ], [event[:3] for event in eventstream._events[:2]])
 def test_signature_middle_utf8_char(self):
     utf8_bytes = b'\xe3\xb3\x8a'
     source = BytesIO(utf8_bytes)
     # Should be treated as one character (it is u'\u3cca') and wrapped
     result = StreamResult()
     subunit.ByteStreamToStreamResult(source,
                                      non_subunit_name="stdout").run(result)
     self.assertEqual([
         ('status', None, None, None, True, 'stdout', b'\xe3', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'\xb3', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'\x8a', False, None,
          None, None),
     ], result._events)
 def test_todo_and_skip(self):
     # A file
     # not ok 1 - a fail but # TODO but is TODO
     # not ok 2 - another fail # SKIP instead
     # results in two tests, numbered and commented.
     self.tap.write(_u("not ok 1 - a fail but # TODO but is TODO\n"))
     self.tap.write(_u("not ok 2 - another fail # SKIP instead\n"))
     self.tap.seek(0)
     result = subunit.TAP2SubUnit(self.tap, self.subunit)
     self.assertEqual(0, result)
     self.subunit.seek(0)
     events = StreamResult()
     subunit.ByteStreamToStreamResult(self.subunit).run(events)
     self.check_events([
         ('status', 'test 1 - a fail but', 'xfail', None, False,
          'tap comment', b'but is TODO', True, 'text/plain; charset=UTF8',
          None, None),
         ('status', 'test 2 - another fail', 'skip', None, False,
          'tap comment', b'instead', True, 'text/plain; charset=UTF8',
          None, None)])
Exemple #21
0
 def test_tags(self):
     byte_stream = BytesIO()
     stream = StreamResultToBytes(byte_stream)
     stream.status(test_id="foo",
                   test_status="inprogress",
                   test_tags=set(["a"]))
     stream.status(test_id="foo",
                   test_status="success",
                   test_tags=set(["a"]))
     stream.status(test_id="bar", test_status="inprogress")
     stream.status(test_id="bar", test_status="inprogress")
     stream.status(test_id="baz",
                   test_status="inprogress",
                   test_tags=set(["a"]))
     stream.status(test_id="baz",
                   test_status="success",
                   test_tags=set(["a"]))
     output = self.run_command(['-s', '--with-tag', 'a'],
                               byte_stream.getvalue())
     events = StreamResult()
     ByteStreamToStreamResult(BytesIO(output)).run(events)
     ids = set(event[1] for event in events._events)
     self.assertEqual(set(['foo', 'baz']), ids)
 def test_non_subunit_encapsulated(self):
     source = BytesIO(b"foo\nbar\n")
     result = StreamResult()
     subunit.ByteStreamToStreamResult(source,
                                      non_subunit_name="stdout").run(result)
     self.assertEqual([
         ('status', None, None, None, True, 'stdout', b'f', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'o', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'o', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'\n', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'b', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'a', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'r', False, None,
          None, None),
         ('status', None, None, None, True, 'stdout', b'\n', False, None,
          None, None),
     ], result._events)
     self.assertEqual(b'', source.read())
 def test_shows_subunit_stream(self):
     ui, cmd = self.get_test_ui_and_cmd(options=[('subunit', True)])
     cmd.repository_factory = memory.RepositoryFactory()
     repo = cmd.repository_factory.initialise(ui.here)
     self._add_run(repo)
     self.assertEqual(0, cmd.execute())
     # We should have seen test outputs (of the failure) and summary data.
     self.assertEqual([
         ('stream', Wildcard),
     ], ui.outputs)
     as_subunit = BytesIO(ui.outputs[0][1])
     stream = ByteStreamToStreamResult(as_subunit)
     log = StreamResult()
     log.startTestRun()
     try:
         stream.run(log)
     finally:
         log.stopTestRun()
     self.assertEqual(log._events,
                      [('startTestRun', ),
                       ('status', 'failing', 'fail', None, True, None, None,
                        False, None, None, None),
                       ('status', 'ok', 'success', None, True, None, None,
                        False, None, None, None), ('stopTestRun', )])
 def check_events(self, events):
     self.subunit.seek(0)
     eventstream = StreamResult()
     subunit.ByteStreamToStreamResult(self.subunit).run(eventstream)
     self.assertEqual(events, eventstream._events)