OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
Alexei Svitkine (slow)
2015/02/17 01:36:54
2015
Steven Holte
2015/02/17 19:33:38
Done.
| |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import unittest | |
7 | |
8 import pretty_print | |
9 | |
10 | |
11 PRETTY_XML = """ | |
12 <!-- Comment1 --> | |
13 | |
14 <rappor-configuration> | |
15 <!-- Comment2 --> | |
16 | |
17 <rappor-parameter-types> | |
18 <!-- Comment3 --> | |
19 | |
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> | |
28 | |
29 </rappor-parameter-types> | |
30 | |
31 <rappor-metrics> | |
32 <!-- Comment4 --> | |
33 | |
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> | |
41 | |
42 </rappor-metrics> | |
43 | |
44 </rappor-configuration> | |
45 """.strip() | |
46 | |
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.', | |
53 } | |
54 | |
55 | |
56 class ActionXmlTest(unittest.TestCase): | |
57 | |
58 def testIsPretty(self): | |
59 result = pretty_print.UpdateXML(PRETTY_XML) | |
60 self.assertEqual(PRETTY_XML, result) | |
61 | |
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)) | |
67 | |
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])) | |
73 | |
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])) | |
79 | |
80 | |
81 if __name__ == '__main__': | |
82 unittest.main() | |
OLD | NEW |