[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / tools / metrics / rappor / pretty_print_test.py
blobf69b7df9bdbae240d52ac93c0c2864bccb55581f
1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import unittest
8 import pretty_print
11 PRETTY_XML = """
12 <!-- Comment1 -->
14 <rappor-configuration>
15 <!-- Comment2 -->
17 <rappor-parameter-types>
18 <!-- Comment3 -->
20 <rappor-parameters name="TEST_RAPPOR_TYPE">
21 <summary>
22 Fake type for tests.
23 </summary>
24 <parameters num-cohorts="128" bytes="1" hash-functions="2" fake-prob="0.5"
25 fake-one-prob="0.5" one-coin-prob="0.75" zero-coin-prob="0.25"
26 reporting-level="COARSE"/>
27 </rappor-parameters>
29 </rappor-parameter-types>
31 <rappor-metrics>
32 <!-- Comment4 -->
34 <rappor-metric name="Test.Rappor.Metric" type="TEST_RAPPOR_TYPE">
35 <owner>user1@chromium.org</owner>
36 <owner>user2@chromium.org</owner>
37 <summary>
38 A fake metric summary.
39 </summary>
40 </rappor-metric>
42 <rappor-metric name="Test.Rappor.Metric2" type="TEST_RAPPOR_TYPE">
43 <owner>user1@chromium.org</owner>
44 <owner>user2@chromium.org</owner>
45 <summary>
46 A fake metric summary.
47 </summary>
48 <string-field name="Url">
49 <summary>
50 The url of the event.
51 </summary>
52 </string-field>
53 <flags-field name="Flags">
54 <flag>Flag bit #1</flag>
55 <flag>Flag bit #2</flag>
56 </flags-field>
57 </rappor-metric>
59 </rappor-metrics>
61 </rappor-configuration>
62 """.strip()
64 BASIC_METRIC = {
65 'comments': [],
66 'name': 'Test.Rappor.Metric',
67 'type': 'TEST_RAPPOR_TYPE',
68 'owners': ['user1@chromium.org', 'user2@chromium.org'],
69 'summary': 'A fake metric summary.',
70 'flags': [],
71 'strings': [],
74 MULTI_FIELD_METRIC = {
75 'comments': [],
76 'name': 'Test.Rappor.Metric2',
77 'type': 'TEST_RAPPOR_TYPE',
78 'owners': ['user1@chromium.org', 'user2@chromium.org'],
79 'summary': 'A fake metric summary.',
80 'strings': [{
81 'comments': [],
82 'name': 'Url',
83 'summary': 'The url of the event.',
84 }],
85 'flags': [{
86 'comments': [],
87 'name': 'Flags',
88 'flags': [
89 'Flag bit #1',
90 'Flag bit #2',
96 class ActionXmlTest(unittest.TestCase):
98 def testIsPretty(self):
99 result = pretty_print.UpdateXML(PRETTY_XML)
100 self.assertMultiLineEqual(PRETTY_XML, result.strip())
102 def testParsing(self):
103 comments, config = pretty_print.RAPPOR_XML_TYPE.Parse(PRETTY_XML)
104 self.assertEqual(BASIC_METRIC, config['metrics']['metrics'][0])
105 self.assertEqual(MULTI_FIELD_METRIC, config['metrics']['metrics'][1])
106 self.assertEqual(set(['TEST_RAPPOR_TYPE']),
107 pretty_print.GetTypeNames(config))
109 def testMissingOwners(self):
110 self.assertFalse(pretty_print.GetMissingOwnerErrors([BASIC_METRIC]))
111 no_owners = BASIC_METRIC.copy()
112 no_owners['owners'] = []
113 self.assertTrue(pretty_print.GetMissingOwnerErrors([no_owners]))
115 def testInvalidTypes(self):
116 self.assertFalse(pretty_print.GetInvalidTypeErrors(
117 set(['TEST_RAPPOR_TYPE']), [BASIC_METRIC]))
118 self.assertTrue(pretty_print.GetInvalidTypeErrors(
119 set(['OTHER_TYPE']), [BASIC_METRIC]))
122 if __name__ == '__main__':
123 unittest.main()