Skip to content

Commit 3cdd037

Browse files
committed
Factor shared constants / utility function out for DRY.
1 parent 5e29335 commit 3cdd037

3 files changed

Lines changed: 32 additions & 21 deletions

File tree

spanner/tests/system/utils/clear_streaming.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,13 @@
1414

1515
"""Depopulate spanner databases with data for streaming system tests."""
1616

17-
import os
18-
1917
from google.cloud.spanner import Client
20-
from google.cloud.spanner.keyset import KeySet
2118
from google.cloud.spanner.pool import BurstyPool
2219

23-
24-
INSTANCE_NAME = 'gcp-streaming-systests'
25-
DATABASE_NAME = 'testing'
26-
27-
28-
def print_func(message):
29-
if os.getenv('GOOGLE_CLOUD_NO_PRINT') != 'true':
30-
print(message)
20+
# Import relative to the script's directory
21+
from streaming_utils import DATABASE_NAME
22+
from streaming_utils import INSTANCE_NAME
23+
from streaming_utils import print_func
3124

3225

3326
def remove_database(client):

spanner/tests/system/utils/populate_streaming.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414

1515
"""Populate spanner databases with data for streaming system tests."""
1616

17-
import os
18-
1917
from google.cloud.spanner import Client
2018
from google.cloud.spanner.keyset import KeySet
2119
from google.cloud.spanner.pool import BurstyPool
2220

23-
24-
INSTANCE_NAME = 'gcp-streaming-systests'
25-
DATABASE_NAME = 'testing'
21+
# Import relative to the script's directory
22+
from streaming_utils import DATABASE_NAME
23+
from streaming_utils import INSTANCE_NAME
24+
from streaming_utils import print_func
2625

2726
DDL = """\
2827
CREATE TABLE four_kay (
@@ -47,11 +46,6 @@
4746
DDL_STATEMENTS = [stmt.strip() for stmt in DDL.split(';') if stmt.strip()]
4847

4948

50-
def print_func(message):
51-
if os.getenv('GOOGLE_CLOUD_NO_PRINT') != 'true':
52-
print(message)
53-
54-
5549
def ensure_database(client):
5650
instance = client.instance(INSTANCE_NAME)
5751

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2017 Google Inc.
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+
import os
16+
17+
INSTANCE_NAME = 'gcp-streaming-systests'
18+
DATABASE_NAME = 'testing'
19+
_SHOULD_PRINT = os.getenv('GOOGLE_CLOUD_NO_PRINT') != 'true'
20+
21+
22+
def print_func(message):
23+
if _SHOULD_PRINT:
24+
print(message)

0 commit comments

Comments
 (0)