Home | History | Annotate | Download | only in tests
      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
      3 # found in the LICENSE file.
      4 
      5 import unittest
      6 
      7 # Generated files
      8 # pylint: disable=F0401
      9 import sample_import_mojom
     10 import sample_service_mojom
     11 
     12 
     13 class EnumBindingsTest(unittest.TestCase):
     14 
     15   # Testing enum classes are in the right module.
     16   def testModule(self):
     17     self.assertEquals(sample_import_mojom.Shape.__module__,
     18                       'sample_import_mojom')
     19 
     20   # Testing that enum class have expected constant values.
     21   def testTopLevelEnumGeneration(self):
     22     self.assertEquals(sample_import_mojom.Shape.RECTANGLE, 1)
     23     self.assertEquals(sample_import_mojom.Shape.CIRCLE, 2)
     24     self.assertEquals(sample_import_mojom.Shape.TRIANGLE, 3)
     25     self.assertEquals(sample_import_mojom.Shape.LAST,
     26                       sample_import_mojom.Shape.TRIANGLE)
     27 
     28     self.assertEquals(sample_import_mojom.AnotherShape.RECTANGLE, 10)
     29     self.assertEquals(sample_import_mojom.AnotherShape.CIRCLE, 11)
     30     self.assertEquals(sample_import_mojom.AnotherShape.TRIANGLE, 12)
     31 
     32     self.assertEquals(sample_import_mojom.YetAnotherShape.RECTANGLE, 20)
     33     self.assertEquals(sample_import_mojom.YetAnotherShape.CIRCLE, 21)
     34     self.assertEquals(sample_import_mojom.YetAnotherShape.TRIANGLE, 22)
     35 
     36   # Testing that internal enum class have expected constant values.
     37   def testInternalEnumGeneration(self):
     38     self.assertEquals(sample_service_mojom.Bar.Type.VERTICAL, 1)
     39     self.assertEquals(sample_service_mojom.Bar.Type.HORIZONTAL, 2)
     40     self.assertEquals(sample_service_mojom.Bar.Type.BOTH, 3)
     41     self.assertEquals(sample_service_mojom.Bar.Type.INVALID, 4)
     42 
     43   # Testing an enum class cannot be instantiated.
     44   def testNonInstantiableEnum(self):
     45     with self.assertRaises(TypeError):
     46       sample_import_mojom.Shape()
     47 
     48   # Testing an enum does not contain the VALUES constant.
     49   def testNoVALUESConstant(self):
     50     with self.assertRaises(AttributeError):
     51       # pylint: disable=W0104
     52       sample_import_mojom.Shape.VALUES
     53 
     54   # Testing enum values are frozen.
     55   def testEnumFrozen(self):
     56     with self.assertRaises(AttributeError):
     57       sample_import_mojom.Shape.RECTANGLE = 2
     58     with self.assertRaises(AttributeError):
     59       del sample_import_mojom.Shape.RECTANGLE
     60     with self.assertRaises(AttributeError):
     61       sample_import_mojom.Shape.NewShape = 4
     62