Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5973)

Unified Diff: chrome/test/functional/media/media_test_utils.py

Issue 9290008: Introduce new basic playback test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Documentation. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/functional/media/media_test_utils.py
diff --git a/chrome/test/functional/media/media_test_utils.py b/chrome/test/functional/media/media_test_utils.py
new file mode 100644
index 0000000000000000000000000000000000000000..b784756f7a031b2fd546190d1e58845f42b58ed0
--- /dev/null
+++ b/chrome/test/functional/media/media_test_utils.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+import functools
Ami GONE FROM CHROMIUM 2012/01/25 17:58:48 missing newline
DaleCurtis 2012/01/25 23:59:25 Done.
+
+
+def FindMediaFiles(matrix, criteria=None, **kwargs):
+ """Given a loosely structured test matrix, finds media matching criteria.
Ami GONE FROM CHROMIUM 2012/01/25 17:58:48 This whole thing seems like crazy overkill to me.
DaleCurtis 2012/01/25 23:59:25 You should have seen the generic version :) In an
Ami GONE FROM CHROMIUM 2012/01/26 00:07:23 WDYT about keeping this matrix business in your ba
+
+ The only requirements for the test matrix structure are a top level element
+ and a 'files' list element under it containing dicts with at least a 'file'
+ tag, indicating the file name, in them. For example:
+
+ {
+ "<test name>": {
+ <...any tags...>
+
+ 'files': [
+ {'file': '<filename>', <...any tags...>}
+ ]
+ }
+ }
+
+ Any kind of metadata can be added in the any tags sections. All fields can be
+ filtered on using the criteria mechanism. For example, to match only files
+ with the name 'test.mp4' you would write:
+
+ FindMediaFiles(<matrix>, file='test.mp4')
+
+ If you wanted to ensure that a metadata named 'duration' was < 5.0 you can use
+ the criteria system:
+
+ FindMediaFiles(<matrix>, criteria={'duration': lambda v: v < 5.0})
+
+ Arguments:
+ matrix: Dictionary object as described above.
+ criteria: Dictionary of tags to boolean functions. Each file entry in the
+ matrix will be required to have the specified tags and pass the associated
+ function. The function will be called with the value associated with the
+ tag.
+ **kwargs: Generally a simple equality check is all that is required to find
+ the required tags. So by simply specifying the key and value here, you
+ can avoid typing out a full criteria entry. Entries here will override
+ those in |criteria|.
+ """
+ results = []
+
+ # Automatically covert each kwarg into a simple equality check.
+ criteria = criteria or {}
+ for arg in kwargs:
+ criteria[arg] = functools.partial(lambda x, y: x == y, kwargs[arg])
+
+ for entry in matrix:
+ # Make a shallow copy so we don't destroy the main data structure.
+ test = matrix[entry].copy()
+
+ # Insert the entry name into the dictionary so it can be filtered on.
+ test.setdefault('name', entry)
+
+ # Remove the files key from the top level test structure.
+ for f in test.pop('files'):
+ # Setup default values for files.
+ f.setdefault('audio', True)
+ f.setdefault('video', True)
+
+ # Copy in the top level tags from test into the file dictionary.
+ f.update(test)
+
+ # Ensure that all the file tags pass all the criteria.
+ success = True
+ for tag, fn in criteria.iteritems():
+ success = success and tag in f and fn(f[tag])
+
+ if success:
+ results.append(f['file'])
+
+ return results

Powered by Google App Engine
This is Rietveld 408576698