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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/functional/ntp.py ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import copy
7 import os 8 import os
9 import types
8 10
9 import pyauto_functional 11 import pyauto_functional
10 import pyauto_utils 12 import pyauto_utils
11 13
12 14
13 """Commonly used functions for PyAuto tests.""" 15 """Commonly used functions for PyAuto tests."""
14 16
15 def DownloadFileFromDownloadsDataDir(test, file_name): 17 def DownloadFileFromDownloadsDataDir(test, file_name):
16 """Download a file from downloads data directory. 18 """Download a file from downloads data directory.
17 19
(...skipping 17 matching lines...) Expand all
35 """Delete a file from the downloads directory. 37 """Delete a file from the downloads directory.
36 38
37 Arg: 39 Arg:
38 test: derived from pyauto.PyUITest - base class for UI test cases 40 test: derived from pyauto.PyUITest - base class for UI test cases
39 file_name: name of file to remove 41 file_name: name of file to remove
40 """ 42 """
41 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), 43 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(),
42 file_name) 44 file_name)
43 pyauto_utils.RemovePath(downloaded_pkg) 45 pyauto_utils.RemovePath(downloaded_pkg)
44 pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') 46 pyauto_utils.RemovePath(downloaded_pkg + '.crdownload')
47
48
49 def StripUnmatchedKeys(item_to_strip, reference_item):
50 """Returns a copy of 'item_to_strip' where unmatched key-value pairs in
51 every dictionary are removed.
52
53 This will examine each dictionary in 'item_to_strip' recursively, and will
54 remove keys that are not found in the corresponding dictionary in
55 'reference_item'. This is useful for testing equality of a subset of data.
56
57 Items may contain dictionaries, lists, or primitives, but only corresponding
58 dictionaries will be stripped. A corresponding entry is one which is found
59 in the same index in the corresponding parent array or at the same key in the
60 corresponding parent dictionary.
61
62 Arg:
63 item_to_strip: item to copy and remove all unmatched key-value pairs
64 reference_item: item that serves as a reference for which keys-value pairs
65 to strip from 'item_to_strip'
66
67 Returns:
68 a copy of 'item_to_strip' where all key-value pairs that do not have a
69 matching key in 'reference_item' are removed
70
71 Example:
72 item_to_strip = {'tabs': 3,
73 'time': 5908}
74 reference_item = {'tabs': 2}
75 StripUnmatchedKeys(item_to_strip, reference_item) will return {'tabs': 3}
76 """
77 def StripList(list1, list2):
78 return_list = copy.deepcopy(list2)
79 for i in range(min(len(list1), len(list2))):
80 return_list[i] = StripUnmatchedKeys(list1[i], list2[i])
81 return return_list
82
83 def StripDict(dict1, dict2):
84 return_dict = {}
85 for key in dict1:
86 if key in dict2:
87 return_dict[key] = StripUnmatchedKeys(dict1[key], dict2[key])
88 return return_dict
89
90 item_to_strip_type = type(item_to_strip)
91 if item_to_strip_type is type(reference_item):
92 if item_to_strip_type is types.ListType:
93 return StripList(item_to_strip, reference_item)
94 elif item_to_strip_type is types.DictType:
95 return StripDict(item_to_strip, reference_item)
96 return copy.deepcopy(item_to_strip)
OLDNEW
« 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