def str_test(self): circle = cast('shape', 'circle') square = cast('shape', 'square') self.assertEqual(str(circle), 'circle') self.assertEqual(str(circle.enum), 'shape') self.assertEqual(str(square), 'square')
def eq_test(self): circle = cast('shape', 'circle') square = cast('shape', 'square') self.assertEqual(circle, 'circle') self.assertNotEqual(circle, 'square') self.assertEqual(square, 'square') self.assertNotEqual(circle, 3)
def cast_test(self): xyz = cast('abc', 'xyz') self.assertEqual(xyz.name, 'xyz') self.assertEqual(xyz.enum.name, 'abc') self.assertEqual(xyz.enum, enum('abc')) self.assertEqual(cast(xyz.enum, 'xyz'), xyz.enum.xyz) self.assertRaisesRegexp(PystaciaException, 'Cannot cast', lambda: cast(2, 'asd')) self.assertRaisesRegexp(PystaciaException, 'Attempted to cast', lambda: cast(xyz.enum, cast('fgh', 'rty'))) self.assertEqual(id(xyz), id(cast(xyz.enum, xyz))) self.assertRaisesRegexp(PystaciaException, 'Cannot cast', lambda: cast('asd', 2)) self.assertRaisesRegexp(PystaciaException, 'Cannot cast', lambda: xyz.enum.cast(1))
def repr_test(self): asd_xyz = cast('asd', 'xyz') self.assertEqual(repr(asd_xyz), "pystacia.lazyenum.enum('asd').xyz")