本文整理匯總了Python中dev_appserver.fix_sys_path函數的典型用法代碼示例。如果您正苦於以下問題:Python fix_sys_path函數的具體用法?Python fix_sys_path怎麽用?Python fix_sys_path使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了fix_sys_path函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup
def setup():
if os.path.exists('frankenserver/python'):
sdk_path = 'frankenserver/python'
else: # running on travis
sdk_path = '../google_appengine'
# If the SDK path points to a Google Cloud SDK installation
# then we should alter it to point to the GAE platform location.
if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')):
sdk_path = os.path.join(sdk_path, 'platform/google_appengine')
# Make sure google.appengine.* modules are importable.
fixup_paths(sdk_path)
# Make sure all bundled third-party packages are available.
import dev_appserver
dev_appserver.fix_sys_path()
from google.appengine.ext import vendor
vendor.add('lib-local')
vendor.add('lib-both')
# Loading appengine_config from the current project ensures that any
# changes to configuration there are available to all tests (e.g.
# sys.path modifications, namespaces, etc.)
try:
import appengine_config
(appengine_config)
except ImportError:
print('Note: unable to import appengine_config.')
示例2: main
def main():
"""Runs the tests."""
# TODO(sll): Check if the next dir is valid.
sdk_path = os.path.join(os.getcwd(), "..", "oppia_runtime", "google_appengine_1.7.4", "google_appengine")
sys.path.insert(0, sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
root_dir = os.path.realpath(os.path.join(os.getcwd()))
suite = unittest.loader.TestLoader().discover(root_dir, pattern="*_test.py", top_level_dir=root_dir)
result = unittest.TextTestRunner(verbosity=2).run(suite)
suite2 = unittest.loader.TestLoader().discover(root_dir, pattern="tests.py", top_level_dir=root_dir)
result2 = unittest.TextTestRunner(verbosity=2).run(suite2)
if result.errors or result.failures or result2.errors or result2.failures:
raise Exception(
"Functional test suite failed: %s errors, %s failures of "
" %s tests run." % (len(result.errors), len(result.failures), result.testsRun)
)
if result.testsRun + result2.testsRun != EXPECTED_TEST_COUNT:
raise Exception(
"Expected %s tests to be run, not %s." % (EXPECTED_TEST_COUNT, result.testsRun + result2.testsRun)
)
示例3: main
def main(sdk_path, test_path):
# If the sdk path points to a google cloud sdk installation
# then we should alter it to point to the GAE platform location.
if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')):
sys.path.insert(0, os.path.join(sdk_path, 'platform/google_appengine'))
else:
sys.path.insert(0, sdk_path)
sys.path.insert(0, '../../public/')
#print(sys.path)
# Ensure that the google.appengine.* packages are available
# in tests as well as all bundled third-party packages.
import dev_appserver
dev_appserver.fix_sys_path()
# Loading appengine_config from the current project ensures that any
# changes to configuration there are available to all tests (e.g.
# sys.path modifications, namespaces, etc.)
try:
import appengine_config
(appengine_config)
except ImportError:
print "Note: unable to import appengine_config."
# Discover and run tests.
suite = unittest.loader.TestLoader().discover(test_path)
unittest.TextTestRunner(verbosity=2).run(suite)
示例4: fix_up_path
def fix_up_path():
"""Changes import path to make all dependencies import correctly.
Performs the following:
- Removes the 'google' module from sys.modules, if it exists, since
this could cause the google.appengine... imports to fail.
- Follow the symlink that puts dev_appserver.py on the user's path
to find the App Engine SDK and add the SDK root to the path.
- Import dev_appserver from the SDK and fix up the path for imports using
dev_appserver.fix_sys_path.
- Add the current git project root to the import path.
"""
# May have namespace conflicts with google.appengine.api...
# such as google.net.proto
sys.modules.pop('google', None)
# Find where dev_appserver.py is installed locally. If dev_appserver.py
# is not on the path, then 'which' will return None.
dev_appserver_on_path = test_utils.which('dev_appserver.py')
if dev_appserver_on_path is None or not os.path.exists(dev_appserver_on_path):
print >>sys.stderr, NO_DEVAPPSERVER_TEMPLATE % (dev_appserver_on_path,)
raise SystemExit(1)
real_path = os.path.realpath(dev_appserver_on_path)
sys.path.insert(0, os.path.dirname(real_path))
import dev_appserver
# Use fix_sys_path to make all App Engine imports work
dev_appserver.fix_sys_path()
project_root = subprocess.check_output(
['git', 'rev-parse', '--show-toplevel']).strip()
sys.path.insert(0, project_root)
示例5: main
def main(sdk_path, test_path, test_pattern):
# If the SDK path points to a Google Cloud SDK installation
# then we should alter it to point to the GAE platform location.
if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')):
sdk_path = os.path.join(sdk_path, 'platform/google_appengine')
# Make sure google.appengine.* modules are importable.
fixup_paths(sdk_path)
# Make sure all bundled third-party packages are available.
import dev_appserver
dev_appserver.fix_sys_path()
# Loading appengine_config from the current project ensures that any
# changes to configuration there are available to all tests (e.g.
# sys.path modifications, namespaces, etc.)
try:
import appengine_config
(appengine_config)
except ImportError:
print('Note: unable to import appengine_config.')
# Discover and run tests.
suite = unittest.loader.TestLoader().discover(test_path, test_pattern)
return unittest.TextTestRunner(verbosity=2).run(suite)
示例6: setup_gae
def setup_gae(sdk_path):
if sys.version_info < (2, 7,):
return
sys.path.insert(0, sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
示例7: main
def main():
sys.path.insert(0, os.environ.get('GAE_SDK'))
import dev_appserver
dev_appserver.fix_sys_path()
suite = unittest.loader.TestLoader().discover('.')
unittest.TextTestRunner(verbosity=2).run(suite)
示例8: setUp
def setUp(self):
from main import app
if not AppEngineTestCase.dev_appserver_fixed:
warnings.filterwarnings('ignore', category=UserWarning)
import appengine_config
appengine_config.PRODUCTION_MODE = False
import dev_appserver
dev_appserver.fix_sys_path()
AppEngineTestCase.dev_appserver_fixed = True
# Flask apps testing. See: http://flask.pocoo.org/docs/testing/
app.config['TESTING'] = True
app.config['CSRF_ENABLED'] = False
app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False
self.app = app
self.new_client()
# Setups app engine test bed. See: http://code.google.com/appengine/docs/python/tools/localunittesting.html#Introducing_the_Python_Testing_Utilities
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_user_stub()
self.testbed.init_memcache_stub()
self.testbed.init_search_stub()
self.testbed.init_urlfetch_stub()
import datahelper
datahelper.put_later = self.put_later
self.dirty_ndb = []
import config
config.security_wait = 0 # When we test user authentication, we don't want to slow down the tests with security sleeps
示例9: setup_environ
def setup_environ():
"""
This func will import the required modules and set up enough of an
appengine environment to let some of our management commands run inside the
SDK sandbox
"""
# Find the path on which the SDK is installed
test_path = distutils.spawn.find_executable('dev_appserver.py')
if test_path is None: # pragma: no cover
print "ERROR: Can't find appengine SDK on your PATH"
sys.exit(1)
sdk_path = os.path.dirname(os.readlink(test_path) if os.path.islink(test_path) else test_path)
# add the SDK path to the system path
sys.path.insert(0, sdk_path)
# Use dev_appserver to set up the python path
if 'google-cloud-sdk' in sdk_path:
sdk_path = os.path.join(os.path.split(sdk_path)[0], 'platform', 'google_appengine')
sys.path.insert(0, os.path.abspath(sdk_path))
from dev_appserver import fix_sys_path
else:
from dev_appserver import fix_sys_path
fix_sys_path()
示例10: main
def main(sdk_path, test_path):
# Get the appserver on the path.
sys.path.insert(0, sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
# Copy datastore to new file.
shutil.copyfile(TEST_DATASTORE, TEST_DATASTORE + "_tmp")
# Set up datastore so we can test on meaningful data.
t = testbed.Testbed()
t.setup_env(True, application_id='dev~openmobiledata')
t.activate()
t.init_datastore_v3_stub(True, TEST_DATASTORE + "_tmp", False)
t.init_memcache_stub()
# Get correct Django version.
from google.appengine.dist import use_library
use_library('django', '1.2')
suite = unittest2.loader.TestLoader().discover(test_path,
pattern='*_test.py')
unittest2.TextTestRunner(verbosity=2).run(suite)
t.deactivate()
示例11: run_tests
def run_tests():
sys.path.insert(0, "/usr/local/google_appengine")
import dev_appserver
dev_appserver.fix_sys_path()
loader = unittest.defaultTestLoader
suite = loader.loadTestsFromNames(modules_with_tests)
unittest.TextTestRunner(verbosity=2).run(suite)
示例12: main
def main(test_path, args):
sdk_path = getenv('APP_ENGINE',
expanduser("~") + '/google-cloud-sdk/platform/google_appengine/')
sys.path.insert(0, sdk_path) # add AppEngine SDK to path
import dev_appserver
dev_appserver.fix_sys_path()
# Loading appengine_config from the current project ensures that any
# changes to configuration there are available to all tests (e.g.
# sys.path modifications, namespaces, etc.)
try:
import appengine_config
(appengine_config)
except ImportError:
#print "Note: unable to import appengine_config."
print "..."
# Discover and run tests.
#suite = unittest.loader.TestLoader().discover(test_path)
#unittest.TextTestRunner(verbosity=2).run(suite)
if vars(args)["skipbasics"]:
suite = unittest.loader.TestLoader().discover(test_path, pattern="*graphs*.py")
else:
suite = unittest.loader.TestLoader().discover(test_path, pattern="test*.py")
unittest.TextTestRunner(verbosity=2).run(suite)
示例13: main
def main(sdk_path, test_path):
sys.path.insert(0, sdk_path)
site.addsitedir(os.path.join(os.getcwd(), 'lib'))
import dev_appserver
dev_appserver.fix_sys_path()
suite = unittest.loader.TestLoader().discover(test_path, top_level_dir='.')
unittest.TextTestRunner(verbosity=2).run(suite)
示例14: run
def run():
sys.path.insert(0, "/usr/local/bin")
import dev_appserver
dev_appserver.fix_sys_path()
suite = unittest.loader.TestLoader().discover(os.path.dirname(__file__))
unittest.TextTestRunner(verbosity=2).run(suite)
示例15: main
def main():
if '--help' in sys.argv:
print 'Usage: python runtests.py [-q|--quiet|-v|--verbose] [--exit_on_failure] [tests|functional_tests|contrib_tests]'
return
verbosity = 1
exit_on_failure = '--exit_on_failure' in sys.argv
if '-q' in sys.argv or '--quiet' in sys.argv:
verbosity = 0
if "-v" in sys.argv or '--verbose' in sys.argv:
verbosity = 2
if verbosity == 0:
logging.disable(logging.CRITICAL)
elif verbosity == 1:
logging.disable(logging.ERROR)
elif verbosity == 2:
logging.basicConfig(level=logging.DEBUG)
import dev_appserver
dev_appserver.fix_sys_path()
# Allow user to run a specific folder of tests
if 'tests' in sys.argv:
run('tests', verbosity, exit_on_failure)
elif 'functional_tests' in sys.argv:
run('functional_tests', verbosity, exit_on_failure)
elif 'contrib_tests' in sys.argv:
run('contrib_tests', verbosity, exit_on_failure)
else:
run('tests', verbosity, exit_on_failure)
run('functional_tests', verbosity, exit_on_failure)
run('contrib_tests', verbosity, exit_on_failure)