Beispiel #1
0
    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')
Beispiel #2
0
    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)
Beispiel #3
0
    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))
Beispiel #4
0
 def repr_test(self):
     asd_xyz = cast('asd', 'xyz')
     self.assertEqual(repr(asd_xyz), "pystacia.lazyenum.enum('asd').xyz")