Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # 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 |
| 4 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 5 | 4 |
| 6 """Setup for PyAuto media tests. | 5 """PyAuto media test base. Handles PyAuto initialization and path setup. |
|
Nirnimesh
2011/12/06 22:15:05
Please leave 2 spaces after every period.
DaleCurtis
2011/12/06 23:42:54
Done.
| |
| 7 | 6 |
| 8 Use the following in your scripts to run them standalone: | 7 Required to ensure each media test can load the appropriate libraries. Each test |
| 8 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 if __name__ == '__main__': | 13 <test code> |
| 14 pyauto_media.Main() | |
| 15 | 14 |
| 16 This script looks similar to pyauto_functional.py. However, unlike | 15 # This should be at the bottom. |
| 17 pyauto_functional, this script can NOT be used as an executable to | 16 if __name__ == '__main__': |
| 18 fire off other media scripts since media tests require additional | 17 pyauto_media.Main() |
| 19 parameters to be set in the form of environment variables (unless you | |
| 20 want these variables to be defaults, which is generally not a good | |
| 21 idea). | |
| 22 """ | 18 """ |
| 23 | 19 |
| 24 import os | 20 import os |
| 25 import sys | 21 import sys |
| 26 import tempfile | 22 import tempfile |
| 27 | 23 |
| 28 from media_test_env_names import MediaTestEnvNames | 24 from media_test_env_names import MediaTestEnvNames |
| 29 | 25 |
| 30 | 26 |
| 31 def _SetupPaths(): | 27 def _SetupPaths(): |
| 32 """Setting path to find pyauto_functional.py.""" | 28 """Add paths required for loading PyAuto and other utilities to sys.path.""" |
| 33 media_dir = os.path.abspath(os.path.dirname(__file__)) | 29 media_dir = os.path.abspath(os.path.dirname(__file__)) |
| 34 sys.path.append(media_dir) | 30 sys.path.append(media_dir) |
| 35 sys.path.append(os.path.normpath(os.path.join(media_dir, os.pardir))) | 31 sys.path.append(os.path.normpath(os.path.join(media_dir, os.pardir))) |
| 32 | |
| 33 # Add psutil library path. TODO(dalecurtis): This should only be added for | |
| 34 # tests which use psutil. | |
| 36 sys.path.append(os.path.normpath(os.path.join( | 35 sys.path.append(os.path.normpath(os.path.join( |
| 37 media_dir, os.pardir, os.pardir, os.pardir, os.pardir, | 36 media_dir, os.pardir, os.pardir, os.pardir, os.pardir, |
| 38 'third_party', 'psutil'))) | 37 'third_party', 'psutil'))) |
| 39 # Setting PYTHONPATH for reference build. | 38 |
| 39 # Setting PYTHONPATH for reference build. TODO(dalecurtis): Don't use env | |
| 40 # variables, each test can process a command line before passing off control | |
| 41 # to PyAuto. | |
| 40 if os.getenv(MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME): | 42 if os.getenv(MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME): |
| 41 reference_build_dir = os.getenv( | 43 reference_build_dir = os.getenv( |
| 42 MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME, | 44 MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME, |
| 43 # TODO(imasaki@): Change the following default value. | 45 # TODO(imasaki): Change the following default value. |
| 44 # Default directory is just for testing so the correct directory | 46 # Default directory is just for testing so the correct directory |
| 45 # must be set in the build script. | 47 # must be set in the build script. |
| 46 os.path.join(tempfile.gettempdir(), 'chrome-media-test')) | 48 os.path.join(tempfile.gettempdir(), 'chrome-media-test')) |
| 47 sys.path.insert(0, reference_build_dir) | 49 sys.path.insert(0, reference_build_dir) |
| 48 | 50 |
| 51 | |
| 49 _SetupPaths() | 52 _SetupPaths() |
| 50 | 53 |
| 54 | |
| 51 import pyauto_functional | 55 import pyauto_functional |
| 52 import pyauto | |
| 53 | 56 |
| 54 | 57 |
| 55 class Main(pyauto_functional.Main): | 58 class Main(pyauto_functional.Main): |
|
Nirnimesh
2011/12/06 22:15:05
This class is a no-op. It can be replaced with:
M
DaleCurtis
2011/12/06 23:42:54
Done.
| |
| 56 """Main program for running PyAuto media tests.""" | 59 """Main program for running PyAuto media tests.""" |
| 57 | 60 |
| 58 def __init__(self): | 61 def __init__(self): |
| 59 pyauto_functional.Main.__init__(self) | 62 pyauto_functional.Main.__init__(self) |
| 60 | |
| 61 | |
| 62 if __name__ == '__main__': | |
| 63 Main() | |
| OLD | NEW |