| OLD | NEW |
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 | 8 |
| 9 # swarming_bot/ | 9 # swarming_bot/ |
| 10 BOT_DIR = os.path.dirname(os.path.realpath(os.path.abspath(__file__))) | 10 BOT_DIR = os.path.dirname(os.path.realpath(os.path.abspath(__file__))) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 if '\n' in link: | 29 if '\n' in link: |
| 30 continue | 30 continue |
| 31 dest = os.path.normpath(os.path.join(root, link)) | 31 dest = os.path.normpath(os.path.join(root, link)) |
| 32 # This is not exactly right but close enough. | 32 # This is not exactly right but close enough. |
| 33 sys.path.insert(0, os.path.dirname(dest)) | 33 sys.path.insert(0, os.path.dirname(dest)) |
| 34 | 34 |
| 35 | 35 |
| 36 def setup_test_env(): | 36 def setup_test_env(): |
| 37 """Sets up the environment for bot tests.""" | 37 """Sets up the environment for bot tests.""" |
| 38 init_symlinks(BOT_DIR) | 38 init_symlinks(BOT_DIR) |
| 39 client_tests = os.path.normpath( | 39 client = os.path.normpath(os.path.join(BOT_DIR, '..', '..', '..', 'client')) |
| 40 os.path.join(BOT_DIR, '..', '..', '..', 'client', 'tests')) | 40 client_tests = os.path.join(client, 'tests') |
| 41 sys.path.insert(0, client_tests) | 41 sys.path.insert(0, client_tests) |
| 42 | 42 |
| 43 tp = os.path.join(BOT_DIR, 'third_party') | 43 tp = os.path.join(BOT_DIR, 'third_party') |
| 44 if sys.platform == 'win32': | 44 if sys.platform == 'win32': |
| 45 # third_party is a symlink. | 45 # third_party is a symlink. |
| 46 with open(tp, 'rb') as f: | 46 with open(tp, 'rb') as f: |
| 47 tp = os.path.join(BOT_DIR, f.read()) | 47 tp = os.path.join(BOT_DIR, f.read()) |
| 48 sys.path.insert(0, tp) | 48 sys.path.insert(0, tp) |
| 49 | 49 |
| 50 # libusb1 expects to be directly in sys.path. | 50 # libusb1 expects to be directly in sys.path. |
| 51 sys.path.insert(0, os.path.join(BOT_DIR, 'python_libusb1')) | 51 sys.path.insert(0, os.path.join(BOT_DIR, 'python_libusb1')) |
| 52 | 52 |
| 53 # For python-rsa. | 53 # For python-rsa. |
| 54 sys.path.insert(0, os.path.join(tp, 'rsa')) | 54 sys.path.insert(0, os.path.join(tp, 'rsa')) |
| 55 sys.path.insert(0, os.path.join(tp, 'pyasn1')) | 55 sys.path.insert(0, os.path.join(tp, 'pyasn1')) |
| 56 |
| 57 # Protobuf is now used in the bot itself. |
| 58 # See fix_protobuf_package() in appengine/components/components/utils.py |
| 59 # but until this code, the version under client is used. |
| 60 if 'google' in sys.modules: |
| 61 # It may be in lib/python2.7/site-packages/google, take not chance and flush |
| 62 # it out. |
| 63 del sys.modules['google'] |
| 64 # This should import client/third_party/google |
| 65 import google |
| 66 google_pkg = os.path.join(client, 'third_party', 'google') |
| 67 if google_pkg not in google.__path__: |
| 68 google.__path__.insert(0, google_pkg) |
| 69 six_path = os.path.join(client, 'third_party', 'six') |
| 70 if six_path not in sys.path: |
| 71 sys.path.insert(0, six_path) |
| OLD | NEW |