summaryrefslogtreecommitdiffstats
path: root/tools/metrics/rappor/pretty_print_test.py
diff options
context:
space:
mode:
authorholte <holte@chromium.org>2015-02-17 11:55:14 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-17 19:55:40 +0000
commit3edb8729b72e1b1c77cda6d2431094079d2a8fad (patch)
tree4f52e98773917e65e29aba58e8bee8a0ea6d2c0d /tools/metrics/rappor/pretty_print_test.py
parent5ebf46e9c536323affb26a8c08667537bc21e1b5 (diff)
downloadchromium_src-3edb8729b72e1b1c77cda6d2431094079d2a8fad.zip
chromium_src-3edb8729b72e1b1c77cda6d2431094079d2a8fad.tar.gz
chromium_src-3edb8729b72e1b1c77cda6d2431094079d2a8fad.tar.bz2
Add pretty printing for rappor.xml
BUG=381380 Review URL: https://codereview.chromium.org/925753002 Cr-Commit-Position: refs/heads/master@{#316634}
Diffstat (limited to 'tools/metrics/rappor/pretty_print_test.py')
-rwxr-xr-xtools/metrics/rappor/pretty_print_test.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/tools/metrics/rappor/pretty_print_test.py b/tools/metrics/rappor/pretty_print_test.py
new file mode 100755
index 0000000..428158a
--- /dev/null
+++ b/tools/metrics/rappor/pretty_print_test.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# Copyright 2015 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 pretty_print
+
+
+PRETTY_XML = """
+<!-- Comment1 -->
+
+<rappor-configuration>
+<!-- Comment2 -->
+
+<rappor-parameter-types>
+<!-- Comment3 -->
+
+<rappor-parameters name="TEST_RAPPOR_TYPE">
+ <summary>
+ Fake type for tests.
+ </summary>
+ <parameters num-cohorts="128" bytes="1" hash-functions="2" fake-prob="0.5"
+ fake-one-prob="0.5" one-coin-prob="0.75" zero-coin-prob="0.25"
+ reporting-level="COARSE"/>
+</rappor-parameters>
+
+</rappor-parameter-types>
+
+<rappor-metrics>
+<!-- Comment4 -->
+
+<rappor-metric name="Test.Rappor.Metric" type="TEST_RAPPOR_TYPE">
+ <owner>user1@chromium.org</owner>
+ <owner>user2@chromium.org</owner>
+ <summary>
+ A fake metric summary.
+ </summary>
+</rappor-metric>
+
+</rappor-metrics>
+
+</rappor-configuration>
+""".strip()
+
+BASIC_METRIC = {
+ 'comments': [],
+ 'name': 'Test.Rappor.Metric',
+ 'type': 'TEST_RAPPOR_TYPE',
+ 'owners': ['user1@chromium.org', 'user2@chromium.org'],
+ 'summary': 'A fake metric summary.',
+}
+
+
+class ActionXmlTest(unittest.TestCase):
+
+ def testIsPretty(self):
+ result = pretty_print.UpdateXML(PRETTY_XML)
+ self.assertEqual(PRETTY_XML, result)
+
+ def testParsing(self):
+ comments, config = pretty_print.RAPPOR_XML_TYPE.Parse(PRETTY_XML)
+ self.assertEqual(BASIC_METRIC, config['metrics']['metrics'][0])
+ self.assertEqual(set(['TEST_RAPPOR_TYPE']),
+ pretty_print.GetTypeNames(config))
+
+ def testMissingOwners(self):
+ self.assertFalse(pretty_print.HasMissingOwners([BASIC_METRIC]))
+ no_owners = BASIC_METRIC.copy()
+ no_owners['owners'] = []
+ self.assertTrue(pretty_print.HasMissingOwners([no_owners]))
+
+ def testInvalidTypes(self):
+ self.assertFalse(pretty_print.HasInvalidTypes(
+ set(['TEST_RAPPOR_TYPE']), [BASIC_METRIC]))
+ self.assertTrue(pretty_print.HasInvalidTypes(
+ set(['OTHER_TYPE']), [BASIC_METRIC]))
+
+
+if __name__ == '__main__':
+ unittest.main()