File tree Expand file tree Collapse file tree 3 files changed +44
-6
lines changed Expand file tree Collapse file tree 3 files changed +44
-6
lines changed Original file line number Diff line number Diff line change 46
46
from tests ._fixtures import DDL_STATEMENTS
47
47
48
48
49
- IS_CIRCLE = os .getenv ('CIRCLECI' ) == 'true'
50
- CREATE_INSTANCE = IS_CIRCLE or os .getenv (
49
+ CREATE_INSTANCE = os .getenv (
51
50
'GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE' ) is not None
52
51
53
52
if CREATE_INSTANCE :
Original file line number Diff line number Diff line change @@ -84,8 +84,9 @@ def ensure_database(client):
84
84
def populate_table (database , table_desc ):
85
85
all_ = KeySet (all_ = True )
86
86
columns = ('pkey' , 'chunk_me' )
87
- rows = list (database .execute_sql (
88
- 'SELECT COUNT(*) FROM {}' .format (table_desc .table )))
87
+ with database .snapshot () as snapshot :
88
+ rows = list (snapshot .execute_sql (
89
+ 'SELECT COUNT(*) FROM {}' .format (table_desc .table )))
89
90
assert len (rows ) == 1
90
91
count = rows [0 ][0 ]
91
92
if count != table_desc .row_count :
@@ -102,8 +103,9 @@ def populate_table(database, table_desc):
102
103
def populate_table_2_columns (database , table_desc ):
103
104
all_ = KeySet (all_ = True )
104
105
columns = ('pkey' , 'chunk_me' , 'chunk_me_2' )
105
- rows = list (database .execute_sql (
106
- 'SELECT COUNT(*) FROM {}' .format (table_desc .table )))
106
+ with database .snapshot () as snapshot :
107
+ rows = list (snapshot .execute_sql (
108
+ 'SELECT COUNT(*) FROM {}' .format (table_desc .table )))
107
109
assert len (rows ) == 1
108
110
count = rows [0 ][0 ]
109
111
if count != table_desc .row_count :
Original file line number Diff line number Diff line change
1
+ # Copyright 2017 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from google .cloud .spanner import Client
16
+ from .streaming_utils import INSTANCE_NAME as STREAMING_INSTANCE
17
+
18
+ STANDARD_INSTANCE = 'google-cloud-python-systest'
19
+
20
+
21
+ def scrub_instances (client ):
22
+ for instance in client .list_instances ():
23
+ if instance .name == STREAMING_INSTANCE :
24
+ print ('Not deleting streaming instance: {}' .format (
25
+ STREAMING_INSTANCE ))
26
+ continue
27
+ elif instance .name == STANDARD_INSTANCE :
28
+ print ('Not deleting standard instance: {}' .format (
29
+ STANDARD_INSTANCE ))
30
+ else :
31
+ print ("deleting instance: {}" .format (instance .name ))
32
+ instance .delete ()
33
+
34
+
35
+ if __name__ == '__main__' :
36
+ client = Client ()
37
+ scrub_instances (client )
You can’t perform that action at this time.
0 commit comments