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

Side by Side Diff: tools/metrics/actions/extract_actions_test.py

Issue 848453002: Improve script to find user actions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address more comments. Created 5 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 unified diff | Download patch
« no previous file with comments | « tools/metrics/actions/extract_actions.py ('k') | no next file » | 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/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import unittest 6 import unittest
7 7
8 import extract_actions 8 import extract_actions
9 9
10 # Empty value to be inserted to |ACTIONS_MOCK|. 10 # Empty value to be inserted to |ACTIONS_MOCK|.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 def testAddNewActions(self): 187 def testAddNewActions(self):
188 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, 188 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE,
189 new_actions=['action2']) 189 new_actions=['action2'])
190 self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result) 190 self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result)
191 191
192 def testComment(self): 192 def testComment(self):
193 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, 193 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE,
194 comment=COMMENT) 194 comment=COMMENT)
195 self.assertEqual(COMMENT_EXPECTED_XML, xml_result) 195 self.assertEqual(COMMENT_EXPECTED_XML, xml_result)
196 196
197 def testUserMetricsActionSpanningTwoLines(self):
198 code = 'base::UserMetricsAction(\n"Foo.Bar"));'
199 finder = extract_actions.ActionNameFinder('dummy', code)
200 self.assertEqual('Foo.Bar', finder.FindNextAction())
201 self.assertFalse(finder.FindNextAction())
202
203 def testUserMetricsActionAsAParam(self):
204 code = 'base::UserMetricsAction("Test.Foo"), "Test.Bar");'
205 finder = extract_actions.ActionNameFinder('dummy', code)
206 self.assertEqual('Test.Foo', finder.FindNextAction())
207 self.assertFalse(finder.FindNextAction())
208
209 def testNonLiteralUserMetricsAction(self):
210 code = 'base::UserMetricsAction(FOO)'
211 finder = extract_actions.ActionNameFinder('dummy', code)
212 with self.assertRaises(Exception):
213 finder.FindNextAction()
214
215 def testTernaryUserMetricsAction(self):
216 code = 'base::UserMetricsAction(foo ? "Foo.Bar" : "Bar.Foo"));'
217 finder = extract_actions.ActionNameFinder('dummy', code)
218 with self.assertRaises(Exception):
219 finder.FindNextAction()
220
221 def testTernaryUserMetricsActionWithNewLines(self):
222 code = """base::UserMetricsAction(
223 foo_bar ? "Bar.Foo" :
224 "Foo.Car")"""
225 finder = extract_actions.ActionNameFinder('dummy', code)
226 with self.assertRaises(extract_actions.InvalidStatementException):
227 finder.FindNextAction()
228
197 229
198 if __name__ == '__main__': 230 if __name__ == '__main__':
199 unittest.main() 231 unittest.main()
OLDNEW
« no previous file with comments | « tools/metrics/actions/extract_actions.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698