OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
7 # Generated files | 7 # Generated files |
8 # pylint: disable=F0401 | 8 # pylint: disable=F0401 |
9 import sample_import_mojom | 9 import sample_import_mojom |
| 10 import sample_service_mojom |
10 | 11 |
11 | 12 |
12 class EnumBindingsTest(unittest.TestCase): | 13 class EnumBindingsTest(unittest.TestCase): |
13 | 14 |
14 # Testing that enum class have expected constant values. | 15 # Testing that enum class have expected constant values. |
15 def testTopLevelEnumGeneration(self): | 16 def testTopLevelEnumGeneration(self): |
16 self.assertEquals(sample_import_mojom.Shape.RECTANGLE, 1) | 17 self.assertEquals(sample_import_mojom.Shape.RECTANGLE, 1) |
17 self.assertEquals(sample_import_mojom.Shape.CIRCLE, 2) | 18 self.assertEquals(sample_import_mojom.Shape.CIRCLE, 2) |
18 self.assertEquals(sample_import_mojom.Shape.TRIANGLE, 3) | 19 self.assertEquals(sample_import_mojom.Shape.TRIANGLE, 3) |
19 | 20 |
20 self.assertEquals(sample_import_mojom.AnotherShape.RECTANGLE, 10) | 21 self.assertEquals(sample_import_mojom.AnotherShape.RECTANGLE, 10) |
21 self.assertEquals(sample_import_mojom.AnotherShape.CIRCLE, 11) | 22 self.assertEquals(sample_import_mojom.AnotherShape.CIRCLE, 11) |
22 self.assertEquals(sample_import_mojom.AnotherShape.TRIANGLE, 12) | 23 self.assertEquals(sample_import_mojom.AnotherShape.TRIANGLE, 12) |
23 | 24 |
24 self.assertEquals(sample_import_mojom.YetAnotherShape.RECTANGLE, 20) | 25 self.assertEquals(sample_import_mojom.YetAnotherShape.RECTANGLE, 20) |
25 self.assertEquals(sample_import_mojom.YetAnotherShape.CIRCLE, 21) | 26 self.assertEquals(sample_import_mojom.YetAnotherShape.CIRCLE, 21) |
26 self.assertEquals(sample_import_mojom.YetAnotherShape.TRIANGLE, 22) | 27 self.assertEquals(sample_import_mojom.YetAnotherShape.TRIANGLE, 22) |
27 | 28 |
| 29 # Testing that internal enum class have expected constant values. |
| 30 def testInternalEnumGeneration(self): |
| 31 self.assertEquals(sample_service_mojom.Bar.Type.VERTICAL, 1) |
| 32 self.assertEquals(sample_service_mojom.Bar.Type.HORIZONTAL, 2) |
| 33 self.assertEquals(sample_service_mojom.Bar.Type.BOTH, 3) |
| 34 self.assertEquals(sample_service_mojom.Bar.Type.INVALID, 4) |
| 35 |
28 # Testing an enum class cannot be instantiated. | 36 # Testing an enum class cannot be instantiated. |
29 def testNonInstantiableEnum(self): | 37 def testNonInstantiableEnum(self): |
30 with self.assertRaises(TypeError): | 38 with self.assertRaises(TypeError): |
31 sample_import_mojom.Shape() | 39 sample_import_mojom.Shape() |
32 | 40 |
33 # Testing an enum does not contain the VALUES constant. | 41 # Testing an enum does not contain the VALUES constant. |
34 def testNoVALUESConstant(self): | 42 def testNoVALUESConstant(self): |
35 with self.assertRaises(AttributeError): | 43 with self.assertRaises(AttributeError): |
36 # pylint: disable=W0104 | 44 # pylint: disable=W0104 |
37 sample_import_mojom.Shape.VALUES | 45 sample_import_mojom.Shape.VALUES |
38 | 46 |
39 # Testing enum values are frozen. | 47 # Testing enum values are frozen. |
40 def testEnumFrozen(self): | 48 def testEnumFrozen(self): |
41 with self.assertRaises(AttributeError): | 49 with self.assertRaises(AttributeError): |
42 sample_import_mojom.Shape.RECTANGLE = 2 | 50 sample_import_mojom.Shape.RECTANGLE = 2 |
43 with self.assertRaises(AttributeError): | 51 with self.assertRaises(AttributeError): |
44 del sample_import_mojom.Shape.RECTANGLE | 52 del sample_import_mojom.Shape.RECTANGLE |
45 with self.assertRaises(AttributeError): | 53 with self.assertRaises(AttributeError): |
46 sample_import_mojom.Shape.NewShape = 4 | 54 sample_import_mojom.Shape.NewShape = 4 |
OLD | NEW |