Beispiel #1
0
    def test_repr(self):
        def test_handler(
                transformable_exception: base_exceptions.BaseFlexception
        ) -> dict:
            return transformable_exception.__dict__

        self.assertEqual(
            repr(base_exceptions.BaseFlexception(handler=test_handler)),
            f"<BaseFlexception ({{'handler': {str(test_handler)}}})>")
Beispiel #2
0
    def test_str(self):
        def test_handler(
                transformable_exception: base_exceptions.BaseFlexception
        ) -> dict:
            return transformable_exception.__dict__

        self.assertEqual(
            str(base_exceptions.BaseFlexception(handler=test_handler)),
            str({"handler": test_handler}))
Beispiel #3
0
    def test_handler_getter_only_member_defined(self):
        def test_member_handler(
                transformable_exception: base_exceptions.BaseFlexception
        ) -> dict:
            return transformable_exception.__dict__

        exception: base_exceptions.BaseFlexception = base_exceptions.BaseFlexception(
            handler=test_member_handler)

        self.assertEqual(exception.handler, test_member_handler)
Beispiel #4
0
    def test_handler_getter_only_default_defined(self):
        def test_default_handler(
                transformable_exception: base_exceptions.BaseFlexception
        ) -> dict:
            return transformable_exception.__dict__

        base_exceptions.BaseFlexception.DEFAULT_HANDLER = test_default_handler
        exception: base_exceptions.BaseFlexception = base_exceptions.BaseFlexception(
        )

        self.assertEqual(exception.handler, test_default_handler)
Beispiel #5
0
    def test_transform_without_handler_as_parameter_without_member_handler(
            self):
        def test_default_handler(
                _transformable_exception: base_exceptions.BaseFlexception
        ) -> int:
            return 1

        base_exceptions.BaseFlexception.DEFAULT_HANDLER = test_default_handler
        exception: base_exceptions.BaseFlexception = base_exceptions.BaseFlexception(
        )

        self.assertEqual(exception.handle(), 1)
Beispiel #6
0
    def test_handler_setter(self):
        exception: base_exceptions.BaseFlexception = base_exceptions.BaseFlexception(
        )
        self.assertIsNone(exception._handler)

        def test_handler(
                transformable_exception: base_exceptions.BaseFlexception
        ) -> dict:
            return transformable_exception.__dict__

        exception.handler = test_handler

        self.assertEqual(exception._handler, test_handler)
Beispiel #7
0
    def test_initialisation(self):
        def test_handler(
                transformable_exception: base_exceptions.BaseFlexception
        ) -> dict:
            return transformable_exception.__dict__

        exception: base_exceptions.BaseFlexception = base_exceptions.BaseFlexception(
            handler=test_handler, data={})
        self.assertIsNone(exception.DEFAULT_HANDLER)
        self.assertEqual(exception._handler, test_handler)
        self.assertEqual(exception.__dict__, {
            "_handler": test_handler,
            "data": {}
        })
Beispiel #8
0
 def test_transform_without_handlers(self):
     with self.assertRaises(base_exceptions.BaseFlexception) as error:
         base_exceptions.BaseFlexception().handle()
     self.assertIs(type(error.exception), WrappedFlexception)