# Path: app/src/main/python/chaquopy/test/test_utils.py
# class FilterWarningsCase(TestCase):
# 
#     def setUp(self):
#         super().setUp()
#         self.cw = catch_warnings()
#         self.cw.__enter__()
#         filterwarnings("error")
# 
#     def tearDown(self):
#         self.cw.__exit__(None, None, None)
#         super().tearDown()


from java import cast, dynamic_proxy, jarray, jfloat, jint
from .test_utils import FilterWarningsCase
from com.chaquo.python import PyException, TestProxy as TP
    from .test_utils import assertDir
        from java.lang import Object, Runnable
        from java.lang import Object, Runnable
        from .test_utils import Object_names
        from .pyobjecttest import DelTrigger as DT
        from java.lang import Object
        from java.lang import IllegalMonitorStateException
        from java.lang import Runnable, ClassCastException, NullPointerException
        from java.lang import String
        from java.io import FileNotFoundException, EOFException
        from java.lang import RuntimeException
        from java.lang.reflect import UndeclaredThrowableException
        from com.chaquo.python import PyException
        from java.lang import Integer, NumberFormatException
        from java.lang import Runnable
                from . import exception_in_init  # noqa: F401
        from java.lang import RuntimeException
        from java.lang import Runnable
import traceback
            @property
            def data(self):
                return 42

        a = Add()
        self.assertEqual("classmethod", a.non_data())
        a.non_data = lambda: "instance override"
        self.assertEqual("instance override", a.non_data())
        del a.non_data
        self.assertEqual("classmethod", a.non_data())

        self.assertEqual(42, a.data)
        with self.assertRaisesRegex(AttributeError, "can't set attribute"):
            a.data = 99
        with self.assertRaisesRegex(AttributeError, "can't delete attribute"):
            del a.data

    def test_unimplemented(self):
        class A(dynamic_proxy(TP.Adder)):
            pass
        with self.assertRaisesRegex(PyException, r"TestProxy\$Adder.add is abstract"):
            cast(TP.Adder, A()).add(5)

    def test_object_methods_unimplemented(self):
        class Unimplemented(dynamic_proxy(TP.Adder)):
            pass
        a1, a2 = Unimplemented(), Unimplemented()

        ts = cast(TP.Adder, a1).toString()
        self.assertRegex(ts, r"\$Proxy.*@")

# Path: app/src/main/python/chaquopy/test/test_utils.py
# class FilterWarningsCase(TestCase):
# 
#     def setUp(self):
#         super().setUp()
#         self.cw = catch_warnings()
#         self.cw.__enter__()
#         filterwarnings("error")
# 
#     def tearDown(self):
#         self.cw.__exit__(None, None, None)
#         super().tearDown()


# Path: app/src/main/python/chaquopy/test/test_proxy.py
from java import cast, dynamic_proxy, jarray, jfloat, jint
from .test_utils import FilterWarningsCase
from com.chaquo.python import PyException, TestProxy as TP
    from .test_utils import assertDir
        from java.lang import Object, Runnable
        from java.lang import Object, Runnable
        from .test_utils import Object_names
        from .pyobjecttest import DelTrigger as DT
        from java.lang import Object
        from java.lang import IllegalMonitorStateException
        from java.lang import Runnable, ClassCastException, NullPointerException
        from java.lang import String
        from java.io import FileNotFoundException, EOFException
        from java.lang import RuntimeException
        from java.lang.reflect import UndeclaredThrowableException
        from com.chaquo.python import PyException
        from java.lang import Integer, NumberFormatException
        from java.lang import Runnable
                from . import exception_in_init  # noqa: F401
        from java.lang import RuntimeException
        from java.lang import Runnable
import traceback

            @property
            def data(self):
                return 42

        a = Add()
        self.assertEqual("classmethod", a.non_data())
        a.non_data = lambda: "instance override"
        self.assertEqual("instance override", a.non_data())
        del a.non_data
        self.assertEqual("classmethod", a.non_data())

        self.assertEqual(42, a.data)
        with self.assertRaisesRegex(AttributeError, "can't set attribute"):
            a.data = 99
        with self.assertRaisesRegex(AttributeError, "can't delete attribute"):
            del a.data

    def test_unimplemented(self):
        class A(dynamic_proxy(TP.Adder)):
            pass
        with self.assertRaisesRegex(PyException, r"TestProxy\$Adder.add is abstract"):
            cast(TP.Adder, A()).add(5)

    def test_object_methods_unimplemented(self):
        class Unimplemented(dynamic_proxy(TP.Adder)):
            pass
        a1, a2 = Unimplemented(), Unimplemented()

        ts = cast(TP.Adder, a1).toString()
        self.assertRegex(ts, r"\$Proxy.*@")

        self.assertEqual(ts, str(a1))