From 9c627775ecc0ee22b1c8c2da894bc9742a2e6755 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 20 Dec 2017 09:15:15 -0800 Subject: [PATCH] Final review pass. Using `assertRaises` instead of a `self.fail()` branch that will never get triggered. Also moving around imports in `google.cloud.spanner_v1.database` to be alphabetical / separated by 1st-party and 3rd-party. --- spanner/google/cloud/spanner_v1/database.py | 8 ++++---- spanner/tests/system/test_system.py | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/spanner/google/cloud/spanner_v1/database.py b/spanner/google/cloud/spanner_v1/database.py index fe57e4e981cd..381a88c39463 100644 --- a/spanner/google/cloud/spanner_v1/database.py +++ b/spanner/google/cloud/spanner_v1/database.py @@ -17,20 +17,20 @@ import re import threading -import google.auth.credentials from google.api_core import exceptions +import google.auth.credentials +from google.cloud.exceptions import Conflict +from google.cloud.exceptions import NotFound from google.gax.errors import GaxError from google.gax.grpc import exc_to_code -from google.cloud.spanner_v1.gapic.spanner_client import SpannerClient from grpc import StatusCode import six # pylint: disable=ungrouped-imports -from google.cloud.exceptions import Conflict -from google.cloud.exceptions import NotFound from google.cloud.spanner_v1 import __version__ from google.cloud.spanner_v1._helpers import _options_with_prefix from google.cloud.spanner_v1.batch import Batch +from google.cloud.spanner_v1.gapic.spanner_client import SpannerClient from google.cloud.spanner_v1.pool import BurstyPool from google.cloud.spanner_v1.pool import SessionCheckout from google.cloud.spanner_v1.session import Session diff --git a/spanner/tests/system/test_system.py b/spanner/tests/system/test_system.py index 0e5127220cd5..346f63a78ba9 100644 --- a/spanner/tests/system/test_system.py +++ b/spanner/tests/system/test_system.py @@ -304,13 +304,11 @@ def test_table_not_found(self): index, ], ) - try: + with self.assertRaises(NotFound) as exc_info: temp_db.create() - except NotFound as exc: - self.assertEqual(exc.args[0], - 'Table not found: {0}'.format(incorrect_table)) - except: - self.fail() + + expected = 'Table not found: {0}'.format(incorrect_table) + self.assertEqual(exc_info.exception.args, (expected,)) def test_update_database_ddl(self): pool = BurstyPool()