| OLD | NEW |
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """PyAuto media test base. Handles PyAuto initialization and path setup. | 5 """PyAuto media test base. Handles PyAuto initialization and path setup. |
| 6 | 6 |
| 7 Required to ensure each media test can load the appropriate libraries. Each | 7 Required to ensure each media test can load the appropriate libraries. Each |
| 8 test must include this snippet: | 8 test must include this snippet: |
| 9 | 9 |
| 10 # This should be at the top | 10 # This should be at the top |
| 11 import pyauto_media | 11 import pyauto_media |
| 12 | 12 |
| 13 <test code> | 13 <test code> |
| 14 | 14 |
| 15 # This should be at the bottom. | 15 # This should be at the bottom. |
| 16 if __name__ == '__main__': | 16 if __name__ == '__main__': |
| 17 pyauto_media.Main() | 17 pyauto_media.Main() |
| 18 """ | 18 """ |
| 19 | 19 |
| 20 import os | 20 import os |
| 21 import sys | 21 import sys |
| 22 import tempfile | |
| 23 | |
| 24 from media_test_env_names import MediaTestEnvNames | |
| 25 | 22 |
| 26 | 23 |
| 27 def _SetupPaths(): | 24 def _SetupPaths(): |
| 28 """Add paths required for loading PyAuto and other utilities to sys.path.""" | 25 """Add paths required for loading PyAuto and other utilities to sys.path.""" |
| 29 media_dir = os.path.abspath(os.path.dirname(__file__)) | 26 media_dir = os.path.abspath(os.path.dirname(__file__)) |
| 30 sys.path.append(media_dir) | 27 sys.path.append(media_dir) |
| 31 sys.path.append(os.path.normpath(os.path.join(media_dir, os.pardir))) | 28 sys.path.append(os.path.normpath(os.path.join(media_dir, os.pardir))) |
| 32 | 29 |
| 33 # Add psutil library path. | 30 # Add psutil library path. |
| 34 # TODO(dalecurtis): This should only be added for tests which use psutil. | 31 # TODO(dalecurtis): This should only be added for tests which use psutil. |
| 35 sys.path.append(os.path.normpath(os.path.join( | 32 sys.path.append(os.path.normpath(os.path.join( |
| 36 media_dir, os.pardir, os.pardir, os.pardir, os.pardir, | 33 media_dir, os.pardir, os.pardir, os.pardir, os.pardir, |
| 37 'third_party', 'psutil'))) | 34 'third_party', 'psutil'))) |
| 38 | 35 |
| 39 # Setting PYTHONPATH for reference build. | |
| 40 # TODO(dalecurtis): Don't use env variables, each test can process a command | |
| 41 # line before passing off control to PyAuto. | |
| 42 if os.getenv(MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME): | |
| 43 reference_build_dir = os.getenv( | |
| 44 MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME, | |
| 45 # TODO(imasaki): Change the following default value. | |
| 46 # Default directory is just for testing so the correct directory | |
| 47 # must be set in the build script. | |
| 48 os.path.join(tempfile.gettempdir(), 'chrome-media-test')) | |
| 49 sys.path.insert(0, reference_build_dir) | |
| 50 | |
| 51 | 36 |
| 52 _SetupPaths() | 37 _SetupPaths() |
| 53 | 38 |
| 54 | 39 |
| 55 import pyauto_functional | 40 import pyauto_functional |
| 56 Main = pyauto_functional.Main | 41 Main = pyauto_functional.Main |
| OLD | NEW |