From 9a9a3769f83118e6c83e720a61dcfd57510387aa Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Mon, 28 Mar 2016 12:37:08 -0400 Subject: [PATCH] Add coverage for can't-get-here 'else' clause. Addresses: https://github.com/GoogleCloudPlatform/gcloud-python/pull/1665#discussion_r57588502 --- gcloud/logging/logger.py | 2 +- gcloud/logging/test_logger.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gcloud/logging/logger.py b/gcloud/logging/logger.py index c824d4dbda68..3aea0585d83a 100644 --- a/gcloud/logging/logger.py +++ b/gcloud/logging/logger.py @@ -289,7 +289,7 @@ def commit(self, client=None): as_json_str = MessageToJson(entry) as_json = json.loads(as_json_str) info = {'protoPayload': as_json} - else: # pragma: NO COVER + else: raise ValueError('Unknown entry type: %s' % (entry_type,)) entries.append(info) diff --git a/gcloud/logging/test_logger.py b/gcloud/logging/test_logger.py index 679ee2cb9640..a155ce693fa9 100644 --- a/gcloud/logging/test_logger.py +++ b/gcloud/logging/test_logger.py @@ -318,6 +318,15 @@ def test_log_proto(self): self.assertEqual(len(connection._requested), 0) self.assertEqual(batch.entries, [('proto', message)]) + def test_commit_w_invalid_entry_type(self): + logger = _Logger() + conn = _Connection() + CLIENT = _Client(project=self.PROJECT, connection=conn) + batch = self._makeOne(logger, CLIENT) + batch.entries.append(('bogus', 'BOGUS')) + with self.assertRaises(ValueError): + batch.commit() + def test_commit_w_bound_client(self): import json from google.protobuf.json_format import MessageToJson