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 self.assertEquals(sample_import_mojom.Shape.LAST, | 20 self.assertEquals(sample_import_mojom.Shape.LAST, |
20 sample_import_mojom.Shape.TRIANGLE) | 21 sample_import_mojom.Shape.TRIANGLE) |
21 | 22 |
22 self.assertEquals(sample_import_mojom.AnotherShape.RECTANGLE, 10) | 23 self.assertEquals(sample_import_mojom.AnotherShape.RECTANGLE, 10) |
23 self.assertEquals(sample_import_mojom.AnotherShape.CIRCLE, 11) | 24 self.assertEquals(sample_import_mojom.AnotherShape.CIRCLE, 11) |
24 self.assertEquals(sample_import_mojom.AnotherShape.TRIANGLE, 12) | 25 self.assertEquals(sample_import_mojom.AnotherShape.TRIANGLE, 12) |
25 | 26 |
26 self.assertEquals(sample_import_mojom.YetAnotherShape.RECTANGLE, 20) | 27 self.assertEquals(sample_import_mojom.YetAnotherShape.RECTANGLE, 20) |
27 self.assertEquals(sample_import_mojom.YetAnotherShape.CIRCLE, 21) | 28 self.assertEquals(sample_import_mojom.YetAnotherShape.CIRCLE, 21) |
28 self.assertEquals(sample_import_mojom.YetAnotherShape.TRIANGLE, 22) | 29 self.assertEquals(sample_import_mojom.YetAnotherShape.TRIANGLE, 22) |
29 | 30 |
| 31 # Testing that internal enum class have expected constant values. |
| 32 def testInternalEnumGeneration(self): |
| 33 self.assertEquals(sample_service_mojom.Bar.Type.VERTICAL, 1) |
| 34 self.assertEquals(sample_service_mojom.Bar.Type.HORIZONTAL, 2) |
| 35 self.assertEquals(sample_service_mojom.Bar.Type.BOTH, 3) |
| 36 self.assertEquals(sample_service_mojom.Bar.Type.INVALID, 4) |
| 37 |
30 # Testing an enum class cannot be instantiated. | 38 # Testing an enum class cannot be instantiated. |
31 def testNonInstantiableEnum(self): | 39 def testNonInstantiableEnum(self): |
32 with self.assertRaises(TypeError): | 40 with self.assertRaises(TypeError): |
33 sample_import_mojom.Shape() | 41 sample_import_mojom.Shape() |
34 | 42 |
35 # Testing an enum does not contain the VALUES constant. | 43 # Testing an enum does not contain the VALUES constant. |
36 def testNoVALUESConstant(self): | 44 def testNoVALUESConstant(self): |
37 with self.assertRaises(AttributeError): | 45 with self.assertRaises(AttributeError): |
38 # pylint: disable=W0104 | 46 # pylint: disable=W0104 |
39 sample_import_mojom.Shape.VALUES | 47 sample_import_mojom.Shape.VALUES |
40 | 48 |
41 # Testing enum values are frozen. | 49 # Testing enum values are frozen. |
42 def testEnumFrozen(self): | 50 def testEnumFrozen(self): |
43 with self.assertRaises(AttributeError): | 51 with self.assertRaises(AttributeError): |
44 sample_import_mojom.Shape.RECTANGLE = 2 | 52 sample_import_mojom.Shape.RECTANGLE = 2 |
45 with self.assertRaises(AttributeError): | 53 with self.assertRaises(AttributeError): |
46 del sample_import_mojom.Shape.RECTANGLE | 54 del sample_import_mojom.Shape.RECTANGLE |
47 with self.assertRaises(AttributeError): | 55 with self.assertRaises(AttributeError): |
48 sample_import_mojom.Shape.NewShape = 4 | 56 sample_import_mojom.Shape.NewShape = 4 |
OLD | NEW |