| OLD | NEW |
| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 '<!--comment-->\n\n' | 107 '<!--comment-->\n\n' |
| 108 '<actions>\n\n' | 108 '<actions>\n\n' |
| 109 '<action name="action1">\n' | 109 '<action name="action1">\n' |
| 110 ' <owner>name1@google.com</owner>\n' | 110 ' <owner>name1@google.com</owner>\n' |
| 111 ' <owner>name2@google.com</owner>\n' | 111 ' <owner>name2@google.com</owner>\n' |
| 112 ' <description>Description.</description>\n' | 112 ' <description>Description.</description>\n' |
| 113 '</action>\n\n' | 113 '</action>\n\n' |
| 114 '</actions>\n' | 114 '</actions>\n' |
| 115 ) | 115 ) |
| 116 | 116 |
| 117 | |
| 118 class ActionXmlTest(unittest.TestCase): | 117 class ActionXmlTest(unittest.TestCase): |
| 119 | 118 |
| 120 def _GetProcessedAction(self, owner, description, obsolete, new_actions=[], | 119 def _GetProcessedAction(self, owner, description, obsolete, new_actions=[], |
| 121 comment=NO_VALUE): | 120 comment=NO_VALUE): |
| 122 """Forms an actions XML string and returns it after processing. | 121 """Forms an actions XML string and returns it after processing. |
| 123 | 122 |
| 124 It parses the original XML string, adds new user actions (if there is any), | 123 It parses the original XML string, adds new user actions (if there is any), |
| 125 and pretty prints it. | 124 and pretty prints it. |
| 126 | 125 |
| 127 Args: | 126 Args: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 def testAddNewActions(self): | 186 def testAddNewActions(self): |
| 188 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, | 187 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, |
| 189 new_actions=['action2']) | 188 new_actions=['action2']) |
| 190 self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result) | 189 self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result) |
| 191 | 190 |
| 192 def testComment(self): | 191 def testComment(self): |
| 193 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, | 192 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, |
| 194 comment=COMMENT) | 193 comment=COMMENT) |
| 195 self.assertEqual(COMMENT_EXPECTED_XML, xml_result) | 194 self.assertEqual(COMMENT_EXPECTED_XML, xml_result) |
| 196 | 195 |
| 196 def testUserMetricsActionSpanningTwoLines(self): |
| 197 code = 'base::UserMetricsAction(\n"Foo.Bar"));' |
| 198 finder = extract_actions.ActionNameFinder('dummy', code) |
| 199 self.assertEqual('Foo.Bar', finder.FindNextAction()) |
| 200 self.assertFalse(finder.FindNextAction()) |
| 201 |
| 202 def testUserMetricsActionAsAParam(self): |
| 203 code = 'base::UserMetricsAction("Test.Foo"), "Test.Bar");' |
| 204 finder = extract_actions.ActionNameFinder('dummy', code) |
| 205 self.assertEqual('Test.Foo', finder.FindNextAction()) |
| 206 self.assertFalse(finder.FindNextAction()) |
| 207 |
| 208 def testNonLiteralUserMetricsAction(self): |
| 209 code = 'base::UserMetricsAction(FOO)' |
| 210 finder = extract_actions.ActionNameFinder('dummy', code) |
| 211 with self.assertRaises(Exception): |
| 212 finder.FindNextAction() |
| 213 |
| 214 def testTernaryUserMetricsAction(self): |
| 215 code = 'base::UserMetricsAction(foo ? "Foo.Bar" : "Bar.Foo"));' |
| 216 finder = extract_actions.ActionNameFinder('dummy', code) |
| 217 with self.assertRaises(Exception): |
| 218 finder.FindNextAction() |
| 219 |
| 220 def testTernaryUserMetricsActionWithNewLines(self): |
| 221 code = """base::UserMetricsAction( |
| 222 foo_bar ? "Bar.Foo" : |
| 223 "Foo.Car")""" |
| 224 finder = extract_actions.ActionNameFinder('dummy', code) |
| 225 with self.assertRaises(extract_actions.InvalidStatementException): |
| 226 finder.FindNextAction() |
| 227 |
| 197 | 228 |
| 198 if __name__ == '__main__': | 229 if __name__ == '__main__': |
| 199 unittest.main() | 230 unittest.main() |
| OLD | NEW |