def test_compile_proto_absolute_path(self, getfile, compile_import_proto): proto_path = '/abs/path/to/my_proto.proto' compiler_out = Mock() MetricLogger._compile_proto(proto_path, compiler_out=compiler_out) compile_import_proto.assert_called_once_with(compiler_out, proto_path) getfile.assert_not_called()
def test_compile_proto_default_compiler_out(self, mkdtemp, getfile, compile_import_proto): compiler_out = Mock() mkdtemp.return_value = compiler_out proto_path = '/abs/path/to/my_proto.proto' MetricLogger._compile_proto(proto_path) compile_import_proto.assert_called_once_with(compiler_out, proto_path)
def test_compile_proto_relative_path(self, getfile, compile_import_proto): getfile.return_value = '/path/to/class/file.py' proto_path = 'dir/my_proto.proto' compiler_out = Mock() MetricLogger._compile_proto(proto_path, compiler_out=compiler_out) full_proto_path = '/path/to/class/dir/my_proto.proto' compile_import_proto.assert_called_once_with(compiler_out, full_proto_path)
def test_init_with_context_and_publisher(self): context = Mock() publisher = Mock() logger = MetricLogger(context=context, publisher=publisher) self.assertEqual(logger.context, context) self.assertEqual(logger.publisher, publisher)
def test_init_with_event(self, get_context, publisher_cls): context = Mock() publisher = Mock() get_context.return_value = context publisher_cls.return_value = publisher event = Mock() logger = MetricLogger(event=event) get_context.assert_called_once_with(event) publisher_cls.assert_called_once_with(context) self.assertEqual(logger.context, context) self.assertEqual(logger.publisher, publisher)
def test_init_empty(self): logger = MetricLogger() self.assertIsNone(logger.context) self.assertIsNone(logger.publisher)
def test_for_test_class_returns_test_class_proxy(self, proxy_cls): args = (Mock(), ) kwargs = {'mock': Mock()} logger = MetricLogger.for_test_class(*args, **kwargs) proxy_cls.assert_called_once_with(MetricLogger, args, kwargs)
def test_end_has_default_impl(self): logger = MetricLogger() logger.end(Mock())
def test_start_has_default_impl(self): logger = MetricLogger() logger.start(Mock())
def test_compile_proto(self): logger = MetricLogger()