OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import imp |
| 6 import os |
| 7 import sys |
| 8 |
| 9 |
| 10 _gae_sdk_root_not_set_message = ''' |
| 11 You must set the environment variable GAE_SDK_ROOT to point to the |
| 12 root of your google_appengine SDK installation.''' |
| 13 |
| 14 |
| 15 _webtest_not_installed_message = ''' |
| 16 Could not load webtest python module. You may need to: |
| 17 sudo apt-get python-webtest |
| 18 ''' |
| 19 |
| 20 |
| 21 def set_up(): |
| 22 """Sets up the environment for testing AppEngine services. |
| 23 |
| 24 Checks, then configures the environment and sys.path to include |
| 25 AppEngine libraries. Call this before importing test modules. |
| 26 |
| 27 Raises: |
| 28 AssertionError: the GAE_SDK_ROOT environment variable is not |
| 29 set. |
| 30 ImportError: webtest or AppEngine's wrapper_util could not be |
| 31 imported. |
| 32 """ |
| 33 assert 'GAE_SDK_ROOT' in os.environ, _gae_sdk_root_not_set_message |
| 34 os.environ.setdefault('APPENGINE_RUNTIME', 'python27') |
| 35 |
| 36 try: |
| 37 wrapper_util = imp.load_module( |
| 38 'wrapper_util', *imp.find_module( |
| 39 'wrapper_util', [os.environ['GAE_SDK_ROOT']])) |
| 40 except ImportError: |
| 41 message = ('GAE_SDK_ROOT=%s does not look like the root of an ' |
| 42 'AppEngine SDK installation') % os.environ['GAE_SDK_ROOT'] |
| 43 print >> sys.stderr, message |
| 44 raise |
| 45 |
| 46 extra_paths = wrapper_util.Paths(os.environ['GAE_SDK_ROOT']).v2_extra_paths |
| 47 sys.path = extra_paths + sys.path |
| 48 |
| 49 # Check that WebTest is installed. Handler integration tests use WebTest. |
| 50 try: |
| 51 import webtest |
| 52 except ImportError: |
| 53 print >> sys.stderr, _webtest_not_installed_message |
| 54 raise |
OLD | NEW |