-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding tox env for datastore sys tests w / emulator. #1393
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2016 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Run datastore system tests locally with the datastore emulator. | ||
|
||
First makes system calls to spawn the datastore emulator and get | ||
the local environment variables needed for it. Then calls the | ||
datastore system tests. | ||
""" | ||
|
||
|
||
import os | ||
import subprocess | ||
|
||
from gcloud.environment_vars import GCD_DATASET | ||
from gcloud.environment_vars import GCD_HOST | ||
|
||
|
||
_START_CMD = ('gcloud', 'beta', 'emulators', 'datastore', 'start') | ||
_ENV_INIT_CMD = ('gcloud', 'beta', 'emulators', 'datastore', 'env-init') | ||
_HOST_VAR_NAME = 'DATASTORE_HOST' | ||
_DATASET_PREFIX = 'export ' + GCD_DATASET + '=' | ||
_HOST_LINE_PREFIX = 'export ' + GCD_HOST + '=' | ||
|
||
|
||
def main(): | ||
"""Spawn an emulator instance and run the datastore system tests.""" | ||
# Ignore stdin and stdout, don't pollute the user's output with them. | ||
proc_start = subprocess.Popen(_START_CMD, stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE) | ||
try: | ||
env_lines = subprocess.check_output( | ||
_ENV_INIT_CMD).strip().split('\n') | ||
dataset, = [line.split(_DATASET_PREFIX, 1)[1] for line in env_lines | ||
if line.startswith(_DATASET_PREFIX)] | ||
host, = [line.split(_HOST_LINE_PREFIX, 1)[1] for line in env_lines | ||
if line.startswith(_HOST_LINE_PREFIX)] | ||
# Set environment variables before running the system tests. | ||
os.environ[GCD_DATASET] = dataset | ||
os.environ[GCD_HOST] = host | ||
os.environ['GCLOUD_NO_PRINT'] = 'true' | ||
# Delay import until after environment variables are set. | ||
from system_tests.run_system_test import run_module_tests | ||
run_module_tests('datastore', | ||
ignore_requirements=True) | ||
finally: | ||
# NOTE: This is mostly defensive. Since ``proc_start`` will be spawned | ||
# by this current process, it should be killed when this process | ||
# exits whether or not we kill it. | ||
proc_start.kill() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.