Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / tools / metrics / rappor / pretty_print_test.py
blob428158a9ccf9c883ca6cc75784f8dcdfc1faaeb9
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-metrics>
44 </rappor-configuration>
45 """.strip()
47 BASIC_METRIC = {
48 'comments': [],
49 'name': 'Test.Rappor.Metric',
50 'type': 'TEST_RAPPOR_TYPE',
51 'owners': ['user1@chromium.org', 'user2@chromium.org'],
52 'summary': 'A fake metric summary.',
56 class ActionXmlTest(unittest.TestCase):
58 def testIsPretty(self):
59 result = pretty_print.UpdateXML(PRETTY_XML)
60 self.assertEqual(PRETTY_XML, result)
62 def testParsing(self):
63 comments, config = pretty_print.RAPPOR_XML_TYPE.Parse(PRETTY_XML)
64 self.assertEqual(BASIC_METRIC, config['metrics']['metrics'][0])
65 self.assertEqual(set(['TEST_RAPPOR_TYPE']),
66 pretty_print.GetTypeNames(config))
68 def testMissingOwners(self):
69 self.assertFalse(pretty_print.HasMissingOwners([BASIC_METRIC]))
70 no_owners = BASIC_METRIC.copy()
71 no_owners['owners'] = []
72 self.assertTrue(pretty_print.HasMissingOwners([no_owners]))
74 def testInvalidTypes(self):
75 self.assertFalse(pretty_print.HasInvalidTypes(
76 set(['TEST_RAPPOR_TYPE']), [BASIC_METRIC]))
77 self.assertTrue(pretty_print.HasInvalidTypes(
78 set(['OTHER_TYPE']), [BASIC_METRIC]))
81 if __name__ == '__main__':
82 unittest.main()