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

Unified Diff: chrome/test/functional/test_utils.py

Issue 5255005: Add pyauto tests for the New Tab page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 10 years, 1 month 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
« no previous file with comments | « chrome/test/functional/ntp.py ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/functional/test_utils.py
diff --git a/chrome/test/functional/test_utils.py b/chrome/test/functional/test_utils.py
index a5fd8ee89983029bb251e22bde0f8a37f50531bb..7a7d315cbce741aa56deeb6752aa4ba3b0fb4104 100644
--- a/chrome/test/functional/test_utils.py
+++ b/chrome/test/functional/test_utils.py
@@ -4,7 +4,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import copy
import os
+import types
import pyauto_functional
import pyauto_utils
@@ -42,3 +44,53 @@ def RemoveDownloadedTestFile(test, file_name):
file_name)
pyauto_utils.RemovePath(downloaded_pkg)
pyauto_utils.RemovePath(downloaded_pkg + '.crdownload')
+
+
+def StripUnmatchedKeys(item_to_strip, reference_item):
+ """Returns a copy of 'item_to_strip' where unmatched key-value pairs in
+ every dictionary are removed.
+
+ This will examine each dictionary in 'item_to_strip' recursively, and will
+ remove keys that are not found in the corresponding dictionary in
+ 'reference_item'. This is useful for testing equality of a subset of data.
+
+ Items may contain dictionaries, lists, or primitives, but only corresponding
+ dictionaries will be stripped. A corresponding entry is one which is found
+ in the same index in the corresponding parent array or at the same key in the
+ corresponding parent dictionary.
+
+ Arg:
+ item_to_strip: item to copy and remove all unmatched key-value pairs
+ reference_item: item that serves as a reference for which keys-value pairs
+ to strip from 'item_to_strip'
+
+ Returns:
+ a copy of 'item_to_strip' where all key-value pairs that do not have a
+ matching key in 'reference_item' are removed
+
+ Example:
+ item_to_strip = {'tabs': 3,
+ 'time': 5908}
+ reference_item = {'tabs': 2}
+ StripUnmatchedKeys(item_to_strip, reference_item) will return {'tabs': 3}
+ """
+ def StripList(list1, list2):
+ return_list = copy.deepcopy(list2)
+ for i in range(min(len(list1), len(list2))):
+ return_list[i] = StripUnmatchedKeys(list1[i], list2[i])
+ return return_list
+
+ def StripDict(dict1, dict2):
+ return_dict = {}
+ for key in dict1:
+ if key in dict2:
+ return_dict[key] = StripUnmatchedKeys(dict1[key], dict2[key])
+ return return_dict
+
+ item_to_strip_type = type(item_to_strip)
+ if item_to_strip_type is type(reference_item):
+ if item_to_strip_type is types.ListType:
+ return StripList(item_to_strip, reference_item)
+ elif item_to_strip_type is types.DictType:
+ return StripDict(item_to_strip, reference_item)
+ return copy.deepcopy(item_to_strip)
« no previous file with comments | « chrome/test/functional/ntp.py ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698