def test_context(self, MockBufferedTransport): mock_buffer = MockBufferedTransport.return_value mock_transport = mock.Mock(spec=metrics.NullTransport) batch = metrics.Batch(mock_transport, "namespace") with batch as b: self.assertEqual(b, batch) self.assertTrue(mock_buffer.flush.called)
def setUp(self): self.patcher = mock.patch("baseplate.metrics.BufferedTransport", autospec=True) self.mock_buffer = self.patcher.start().return_value self.mock_transport = mock.Mock(spec=metrics.NullTransport) # encode is called here since metrics.Batch is designed to be instantiated # by an instance of metrics.Client which encodes the namespace arg self.batch = metrics.Batch(self.mock_transport, "namespace".encode("ascii"))