Index: Tools/appengine_testing/appengine_testing.py |
diff --git a/Tools/appengine_testing/appengine_testing.py b/Tools/appengine_testing/appengine_testing.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6797a5ed6ba1faeef88ed33de94304442a7e0d54 |
--- /dev/null |
+++ b/Tools/appengine_testing/appengine_testing.py |
@@ -0,0 +1,54 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import imp |
+import os |
+import sys |
+ |
+ |
+_gae_sdk_root_not_set_message = ''' |
+ You must set the environment variable GAE_SDK_ROOT to point to the |
+ root of your google_appengine SDK installation.''' |
+ |
+ |
+_webtest_not_installed_message = ''' |
+ Could not load webtest python module. You may need to: |
+ sudo apt-get python-webtest |
+''' |
+ |
+ |
+def set_up(): |
+ """Sets up the environment for testing AppEngine services. |
+ |
+ Checks, then configures the environment and sys.path to include |
+ AppEngine libraries. Call this before importing test modules. |
+ |
+ Raises: |
+ AssertionError: the GAE_SDK_ROOT environment variable is not |
+ set. |
+ ImportError: webtest or AppEngine's wrapper_util could not be |
+ imported. |
+ """ |
+ assert 'GAE_SDK_ROOT' in os.environ, _gae_sdk_root_not_set_message |
+ os.environ.setdefault('APPENGINE_RUNTIME', 'python27') |
+ |
+ try: |
+ wrapper_util = imp.load_module( |
+ 'wrapper_util', *imp.find_module( |
+ 'wrapper_util', [os.environ['GAE_SDK_ROOT']])) |
+ except ImportError: |
+ message = ('GAE_SDK_ROOT=%s does not look like the root of an ' |
+ 'AppEngine SDK installation') % os.environ['GAE_SDK_ROOT'] |
+ print >> sys.stderr, message |
+ raise |
+ |
+ extra_paths = wrapper_util.Paths(os.environ['GAE_SDK_ROOT']).v2_extra_paths |
+ sys.path = extra_paths + sys.path |
+ |
+ # Check that WebTest is installed. Handler integration tests use WebTest. |
+ try: |
+ import webtest |
+ except ImportError: |
+ print >> sys.stderr, _webtest_not_installed_message |
+ raise |