| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 import pretty_print | 8 import pretty_print |
| 9 | 9 |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 <summary> | 21 <summary> |
| 22 Fake type for tests. | 22 Fake type for tests. |
| 23 </summary> | 23 </summary> |
| 24 <parameters num-cohorts="128" bytes="1" hash-functions="2" fake-prob="0.5" | 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" | 25 fake-one-prob="0.5" one-coin-prob="0.75" zero-coin-prob="0.25" |
| 26 reporting-level="COARSE"/> | 26 reporting-level="COARSE"/> |
| 27 </rappor-parameters> | 27 </rappor-parameters> |
| 28 | 28 |
| 29 </rappor-parameter-types> | 29 </rappor-parameter-types> |
| 30 | 30 |
| 31 <flag-sets> |
| 32 <!-- Comment 3.5 --> |
| 33 |
| 34 <flag-set name="TEST_FLAGS"> |
| 35 <flag name="FLAG1" description="The first flag."/> |
| 36 <flag name="FLAG2" description="The second flag."/> |
| 37 </flag-set> |
| 38 |
| 39 </flag-sets> |
| 40 |
| 31 <rappor-metrics> | 41 <rappor-metrics> |
| 32 <!-- Comment4 --> | 42 <!-- Comment4 --> |
| 33 | 43 |
| 34 <rappor-metric name="Test.Rappor.Metric" type="TEST_RAPPOR_TYPE"> | 44 <rappor-metric name="Test.Rappor.Metric" type="TEST_RAPPOR_TYPE" |
| 45 flags="TEST_FLAGS"> |
| 35 <owner>user1@chromium.org</owner> | 46 <owner>user1@chromium.org</owner> |
| 36 <owner>user2@chromium.org</owner> | 47 <owner>user2@chromium.org</owner> |
| 37 <summary> | 48 <summary> |
| 38 A fake metric summary. | 49 A fake metric summary. |
| 39 </summary> | 50 </summary> |
| 40 </rappor-metric> | 51 </rappor-metric> |
| 41 | 52 |
| 42 </rappor-metrics> | 53 </rappor-metrics> |
| 43 | 54 |
| 44 </rappor-configuration> | 55 </rappor-configuration> |
| 45 """.strip() | 56 """.lstrip() |
| 46 | 57 |
| 47 BASIC_METRIC = { | 58 BASIC_METRIC = { |
| 48 'comments': [], | 59 'comments': [], |
| 49 'name': 'Test.Rappor.Metric', | 60 'name': 'Test.Rappor.Metric', |
| 50 'type': 'TEST_RAPPOR_TYPE', | 61 'type': 'TEST_RAPPOR_TYPE', |
| 62 'flags': 'TEST_FLAGS', |
| 51 'owners': ['user1@chromium.org', 'user2@chromium.org'], | 63 'owners': ['user1@chromium.org', 'user2@chromium.org'], |
| 52 'summary': 'A fake metric summary.', | 64 'summary': 'A fake metric summary.', |
| 53 } | 65 } |
| 54 | 66 |
| 55 | 67 |
| 56 class ActionXmlTest(unittest.TestCase): | 68 class ActionXmlTest(unittest.TestCase): |
| 57 | 69 |
| 58 def testIsPretty(self): | 70 def testIsPretty(self): |
| 59 result = pretty_print.UpdateXML(PRETTY_XML) | 71 result = pretty_print.UpdateXML(PRETTY_XML) |
| 60 self.assertEqual(PRETTY_XML, result) | 72 self.assertEqual(PRETTY_XML.split('\n'), result.split('\n')) |
| 61 | 73 |
| 62 def testParsing(self): | 74 def testParsing(self): |
| 63 comments, config = pretty_print.RAPPOR_XML_TYPE.Parse(PRETTY_XML) | 75 comments, config = pretty_print.RAPPOR_XML_TYPE.Parse(PRETTY_XML) |
| 64 self.assertEqual(BASIC_METRIC, config['metrics']['metrics'][0]) | 76 self.assertEqual(BASIC_METRIC, config['metrics']['metrics'][0]) |
| 65 self.assertEqual(set(['TEST_RAPPOR_TYPE']), | 77 self.assertEqual(set(['TEST_RAPPOR_TYPE']), |
| 66 pretty_print.GetTypeNames(config)) | 78 pretty_print.GetTypeNames(config)) |
| 67 | 79 |
| 68 def testMissingOwners(self): | 80 def testMissingOwners(self): |
| 69 self.assertFalse(pretty_print.HasMissingOwners([BASIC_METRIC])) | 81 self.assertFalse(pretty_print.HasMissingOwners([BASIC_METRIC])) |
| 70 no_owners = BASIC_METRIC.copy() | 82 no_owners = BASIC_METRIC.copy() |
| 71 no_owners['owners'] = [] | 83 no_owners['owners'] = [] |
| 72 self.assertTrue(pretty_print.HasMissingOwners([no_owners])) | 84 self.assertTrue(pretty_print.HasMissingOwners([no_owners])) |
| 73 | 85 |
| 74 def testInvalidTypes(self): | 86 def testInvalidTypes(self): |
| 75 self.assertFalse(pretty_print.HasInvalidTypes( | 87 self.assertFalse(pretty_print.HasInvalidTypes( |
| 76 set(['TEST_RAPPOR_TYPE']), [BASIC_METRIC])) | 88 set(['TEST_RAPPOR_TYPE']), [BASIC_METRIC])) |
| 77 self.assertTrue(pretty_print.HasInvalidTypes( | 89 self.assertTrue(pretty_print.HasInvalidTypes( |
| 78 set(['OTHER_TYPE']), [BASIC_METRIC])) | 90 set(['OTHER_TYPE']), [BASIC_METRIC])) |
| 79 | 91 |
| 80 | 92 |
| 81 if __name__ == '__main__': | 93 if __name__ == '__main__': |
| 82 unittest.main() | 94 unittest.main() |
| OLD | NEW |