| 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 class TestName(pyauto_media.MediaTestBase): |
| 14 <test code> |
| 14 | 15 |
| 15 # This should be at the bottom. | 16 # This should be at the bottom. |
| 16 if __name__ == '__main__': | 17 if __name__ == '__main__': |
| 17 pyauto_media.Main() | 18 pyauto_media.Main() |
| 18 """ | 19 """ |
| 19 | 20 import json |
| 20 import os | 21 import os |
| 21 import sys | 22 import sys |
| 22 import tempfile | |
| 23 | 23 |
| 24 from media_test_env_names import MediaTestEnvNames | 24 import media_test_utils |
| 25 | 25 |
| 26 | 26 |
| 27 def _SetupPaths(): | 27 def _SetupPaths(): |
| 28 """Add paths required for loading PyAuto and other utilities to sys.path.""" | 28 """Add paths required for loading PyAuto and other utilities to sys.path.""" |
| 29 media_dir = os.path.abspath(os.path.dirname(__file__)) | 29 media_dir = os.path.abspath(os.path.dirname(__file__)) |
| 30 sys.path.append(media_dir) | 30 sys.path.append(media_dir) |
| 31 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 | 32 |
| 33 # Add psutil library path. | |
| 34 # TODO(dalecurtis): This should only be added for tests which use psutil. | |
| 35 sys.path.append(os.path.normpath(os.path.join( | |
| 36 media_dir, os.pardir, os.pardir, os.pardir, os.pardir, | |
| 37 'third_party', 'psutil'))) | |
| 38 | 33 |
| 39 # Setting PYTHONPATH for reference build. | 34 _SetupPaths() |
| 40 # TODO(dalecurtis): Don't use env variables, each test can process a command | 35 import pyauto_functional |
| 41 # line before passing off control to PyAuto. | 36 import 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 | 37 |
| 51 | 38 |
| 52 _SetupPaths() | 39 class MediaTestBase(pyauto.PyUITest): |
| 40 def setUp(self): |
| 41 pyauto.PyUITest.setUp(self) |
| 42 self._test_matrix = json.load(open( |
| 43 os.path.join(self.DataDir(), 'media', 'csv', 'media.json'))) |
| 44 |
| 45 def FindMedia(self, **kwargs): |
| 46 """Returns a list of matching media paths from the test matrix. |
| 47 |
| 48 Given a list of keys like audio=True, duration=1.0, etc... returns a list |
| 49 of files matching these constraints. |
| 50 |
| 51 See media_test_utils.FindMediaFiles for more advanced syntax. |
| 52 |
| 53 Arguments: |
| 54 **kwargs: List of attributes desired for each media file. |
| 55 |
| 56 Returns: |
| 57 List of matching file names. |
| 58 """ |
| 59 media_files = media_test_utils.FindMediaFiles(self._test_matrix, **kwargs) |
| 60 # Covert unicode strings to regular strings because PyAuto doesn't know how |
| 61 # to process unicode at the moment. |
| 62 return map(str, media_files) |
| 53 | 63 |
| 54 | 64 |
| 55 import pyauto_functional | |
| 56 Main = pyauto_functional.Main | 65 Main = pyauto_functional.Main |
| OLD | NEW |