diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-02-20 14:37:51 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-02-20 18:20:05 -0300 |
commit | 4d89c3d81477a730b7d7ce6c9b5c062ee8cd1ec7 (patch) | |
tree | ad6d249bd8d952bc8db3b31aaa3eb0f9279bcf41 /tests | |
parent | 08acf3d1c3f5fd364ebd29ae00f48b6f6ad2f97d (diff) |
All enums are now extensible to match the C++ casting behaviour.
Now the user can build new values of a particular enum type passing
an integer to its constructor. Thus, the following C++ code:
MyEnum val = (MyEnum) 1;
is the equivalent of this Python code:
val = MyEnum(1)
The enum unit tests were also updated.
Reviewed by Lauro Moura <lauro.neto@openbossa.org>
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/samplebinding/enum_test.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/samplebinding/enum_test.py b/tests/samplebinding/enum_test.py index e282cdc93..bd173d85c 100755 --- a/tests/samplebinding/enum_test.py +++ b/tests/samplebinding/enum_test.py @@ -26,7 +26,6 @@ '''Test cases for Python representation of C++ enums.''' -import sys import unittest from sample import SampleNamespace @@ -38,15 +37,23 @@ class EnumTest(unittest.TestCase): '''Tries to use an integer in place of an enum argument.''' self.assertRaises(TypeError, SampleNamespace.getNumber, 1) - def testExtendingNonExtensibleEnum(self): - '''Tries to create a new enum item for an unextensible enum.''' - self.assertRaises(TypeError, SampleNamespace.InValue, 13) + def testBuildingEnumFromIntegerValue(self): + '''Tries to build the proper enum using an integer.''' + SampleNamespace.getNumber(SampleNamespace.Option(1)) def testEnumConversionToAndFromPython(self): '''Conversion of enum objects from Python to C++ back again.''' enumout = SampleNamespace.enumInEnumOut(SampleNamespace.TwoIn) self.assert_(enumout, SampleNamespace.TwoOut) + def testEnumConstructorWithTooManyParameters(self): + '''Calling the constructor of non-extensible enum with the wrong number of parameters.''' + self.assertRaises(TypeError, SampleNamespace.InValue, 13, 14) + + def testEnumConstructorWithNonNumberParameter(self): + '''Calling the constructor of non-extensible enum with a string.''' + self.assertRaises(TypeError, SampleNamespace.InValue, '1') + if __name__ == '__main__': unittest.main() |