forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregression_utils.py
More file actions
38 lines (29 loc) · 1.07 KB
/
regression_utils.py
File metadata and controls
38 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import sys
from gcloud import datastore
# Defaults from shell environ. May be None.
DATASET_ID = os.getenv('GCLOUD_TESTS_DATASET_ID')
CLIENT_EMAIL = os.getenv('GCLOUD_TESTS_CLIENT_EMAIL')
KEY_FILENAME = os.getenv('GCLOUD_TESTS_KEY_FILE')
DATASETS = {}
ENVIRON_ERROR_MSG = """\
To run the regression tests, you need to set some environment variables.
Please check the Contributing guide for instructions.
"""
def get_environ():
if DATASET_ID is None or CLIENT_EMAIL is None or KEY_FILENAME is None:
print >> sys.stderr, ENVIRON_ERROR_MSG
sys.exit(1)
return {
'dataset_id': DATASET_ID,
'client_email': CLIENT_EMAIL,
'key_filename': KEY_FILENAME,
}
def get_dataset():
environ = get_environ()
get_dataset_args = (environ['dataset_id'], environ['client_email'],
environ['key_filename'])
if get_dataset_args not in DATASETS:
# Cache return value for the environment.
DATASETS[get_dataset_args] = datastore.get_dataset(*get_dataset_args)
return DATASETS[get_dataset_args]