Example #1
0
    def test_export(self):  # pylint: disable=no-self-use
        """Check that the console exporter prints spans."""
        exporter = export.ConsoleSpanExporter()

        # Mocking stdout interferes with debugging and test reporting, mock on
        # the exporter instance instead.
        span = trace.Span("span name", mock.Mock())
        with mock.patch.object(exporter, "out") as mock_stdout:
            exporter.export([span])
        mock_stdout.write.assert_called_once_with(str(span))
        self.assertEqual(mock_stdout.write.call_count, 1)
    def test_export_custom(self):  # pylint: disable=no-self-use
        """Check that console exporter uses custom io, formatter."""
        mock_span_str = mock.Mock(str)

        def formatter(span):  # pylint: disable=unused-argument
            return mock_span_str

        mock_stdout = mock.Mock()
        exporter = export.ConsoleSpanExporter(out=mock_stdout,
                                              formatter=formatter)
        exporter.export([trace._Span("span name", mock.Mock())])
        mock_stdout.write.assert_called_once_with(mock_span_str)
    def test_export(self):  # pylint: disable=no-self-use
        """Check that the console exporter prints spans."""
        exporter = export.ConsoleSpanExporter()

        # Mocking stdout interferes with debugging and test reporting, mock on
        # the exporter instance instead.
        span = trace._Span("span name", trace_api.INVALID_SPAN_CONTEXT)
        with mock.patch.object(exporter, "out") as mock_stdout:
            exporter.export([span])
        mock_stdout.write.assert_called_once_with(span.to_json() + os.linesep)
        self.assertEqual(mock_stdout.write.call_count, 1)
        self.assertEqual(mock_stdout.flush.call_count, 1)