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

Unified Diff: tools/metrics/actions/extract_actions_test.py

Issue 149503005: Change actions.txt to actions.xml (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comment on patch 34 Created 6 years, 9 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
« no previous file with comments | « tools/metrics/actions/extract_actions.py ('k') | tools/metrics/actions/print_style.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/metrics/actions/extract_actions_test.py
diff --git a/tools/metrics/actions/extract_actions_test.py b/tools/metrics/actions/extract_actions_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..a5cfd387717a1b2498ebdc099c991e5e0d8611be
--- /dev/null
+++ b/tools/metrics/actions/extract_actions_test.py
@@ -0,0 +1,199 @@
+#!/usr/bin/env python
+# Copyright 2014 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 unittest
+
+import extract_actions
+
+# Empty value to be inserted to |ACTIONS_MOCK|.
+NO_VALUE = ''
+
+ONE_OWNER = '<owner>name1@google.com</owner>\n'
+TWO_OWNERS = """
+<owner>name1@google.com</owner>\n
+<owner>name2@google.com</owner>\n
+"""
+
+DESCRIPTION = '<description>Description.</description>\n'
+TWO_DESCRIPTIONS = """
+<description>Description.</description>\n
+<description>Description2.</description>\n
+"""
+
+OBSOLETE = '<obsolete>Not used anymore. Replaced by action2.</obsolete>\n'
+TWO_OBSOLETE = '<obsolete>Obsolete1.</obsolete><obsolete>Obsolete2.</obsolete>'
+
+COMMENT = '<!--comment-->'
+
+# A format string to mock the input action.xml file.
+ACTIONS_XML = """
+{comment}
+<actions>
+
+<action name="action1">
+{owners}{obsolete}{description}
+</action>
+
+</actions>"""
+
+NO_OWNER_EXPECTED_XML = (
+ '<actions>\n\n'
+ '<action name="action1">\n'
+ ' <owner>Please list the metric\'s owners. '
+ 'Add more owner tags as needed.</owner>\n'
+ ' <description>Description.</description>\n'
+ '</action>\n\n'
+ '</actions>\n'
+)
+
+ONE_OWNER_EXPECTED_XML = (
+ '<actions>\n\n'
+ '<action name="action1">\n'
+ ' <owner>name1@google.com</owner>\n'
+ ' <description>Description.</description>\n'
+ '</action>\n\n'
+ '</actions>\n'
+)
+
+TWO_OWNERS_EXPECTED_XML = (
+ '<actions>\n\n'
+ '<action name="action1">\n'
+ ' <owner>name1@google.com</owner>\n'
+ ' <owner>name2@google.com</owner>\n'
+ ' <description>Description.</description>\n'
+ '</action>\n\n'
+ '</actions>\n'
+)
+
+NO_DESCRIPTION_EXPECTED_XML = (
+ '<actions>\n\n'
+ '<action name="action1">\n'
+ ' <owner>name1@google.com</owner>\n'
+ ' <owner>name2@google.com</owner>\n'
+ ' <description>Please enter the description of the metric.</description>\n'
+ '</action>\n\n'
+ '</actions>\n'
+)
+
+OBSOLETE_EXPECTED_XML = (
+ '<actions>\n\n'
+ '<action name="action1">\n'
+ ' <owner>name1@google.com</owner>\n'
+ ' <owner>name2@google.com</owner>\n'
+ ' <description>Description.</description>\n'
+ ' <obsolete>Not used anymore. Replaced by action2.</obsolete>\n'
+ '</action>\n\n'
+ '</actions>\n'
+)
+
+ADD_ACTION_EXPECTED_XML = (
+ '<actions>\n\n'
+ '<action name="action1">\n'
+ ' <owner>name1@google.com</owner>\n'
+ ' <owner>name2@google.com</owner>\n'
+ ' <description>Description.</description>\n'
+ '</action>\n\n'
+ '<action name="action2">\n'
+ ' <owner>Please list the metric\'s owners.'
+ ' Add more owner tags as needed.</owner>\n'
+ ' <description>Please enter the description of the metric.</description>\n'
+ '</action>\n\n'
+ '</actions>\n'
+)
+
+COMMENT_EXPECTED_XML = (
+ '<!--comment-->\n\n'
+ '<actions>\n\n'
+ '<action name="action1">\n'
+ ' <owner>name1@google.com</owner>\n'
+ ' <owner>name2@google.com</owner>\n'
+ ' <description>Description.</description>\n'
+ '</action>\n\n'
+ '</actions>\n'
+)
+
+
+class ActionXmlTest(unittest.TestCase):
+
+ def _GetProcessedAction(self, owner, description, obsolete, new_actions=[],
+ comment=NO_VALUE):
+ """Forms an actions XML string and returns it after processing.
+
+ It parses the original XML string, adds new user actions (if there is any),
+ and pretty prints it.
+
+ Args:
+ owner: the owner tag to be inserted in the original XML string.
+ description: the description tag to be inserted in the original XML
+ string.
+ obsolete: the obsolete tag to be inserted in the original XML string.
+ new_actions: optional. List of new user actions' names to be inserted.
+ comment: the comment tag to be inserted in the original XML string.
+
+ Returns:
+ An updated and pretty-printed action XML string.
+ """
+ # Form the actions.xml mock content based on the input parameters.
+ current_xml = ACTIONS_XML.format(owners=owner, description=description,
+ obsolete=obsolete, comment=comment)
+ actions, actions_dict, comments = extract_actions.ParseActionFile(
+ current_xml)
+ for new_action in new_actions:
+ actions.add(new_action)
+ return extract_actions.PrettyPrint(actions, actions_dict, comments)
+
+ def testNoOwner(self):
+ xml_result = self._GetProcessedAction(NO_VALUE, DESCRIPTION, NO_VALUE)
+ self.assertEqual(NO_OWNER_EXPECTED_XML, xml_result)
+
+ def testOneOwnerOneDescription(self):
+ xml_result = self._GetProcessedAction(ONE_OWNER, DESCRIPTION, NO_VALUE)
+ self.assertEqual(ONE_OWNER_EXPECTED_XML, xml_result)
+
+ def testTwoOwners(self):
+ xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE)
+ self.assertEqual(TWO_OWNERS_EXPECTED_XML, xml_result)
+
+ def testNoDescription(self):
+ xml_result = self._GetProcessedAction(TWO_OWNERS, NO_VALUE, NO_VALUE)
+ self.assertEqual(NO_DESCRIPTION_EXPECTED_XML, xml_result)
+
+ def testTwoDescriptions(self):
+ current_xml = ACTIONS_XML.format(owners=TWO_OWNERS, obsolete=NO_VALUE,
+ description=TWO_DESCRIPTIONS,
+ comment=NO_VALUE)
+ # Since there are two description tags, the function ParseActionFile will
+ # raise SystemExit with exit code 1.
+ with self.assertRaises(SystemExit) as cm:
+ _, _ = extract_actions.ParseActionFile(current_xml)
+ self.assertEqual(cm.exception.code, 1)
+
+ def testObsolete(self):
+ xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, OBSOLETE)
+ self.assertEqual(OBSOLETE_EXPECTED_XML, xml_result)
+
+
+ def testTwoObsoletes(self):
+ current_xml = ACTIONS_XML.format(owners=TWO_OWNERS, obsolete=TWO_OBSOLETE,
+ description=DESCRIPTION, comment=NO_VALUE)
+ # Since there are two obsolete tags, the function ParseActionFile will
+ # raise SystemExit with exit code 1.
+ with self.assertRaises(SystemExit) as cm:
+ _, _ = extract_actions.ParseActionFile(current_xml)
+ self.assertEqual(cm.exception.code, 1)
+
+ def testAddNewActions(self):
+ xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE,
+ new_actions=['action2'])
+ self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result)
+
+ def testComment(self):
+ xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE,
+ comment=COMMENT)
+ self.assertEqual(COMMENT_EXPECTED_XML, xml_result)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « tools/metrics/actions/extract_actions.py ('k') | tools/metrics/actions/print_style.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698