# Path: app/src/main/python/chaquopy/test/test_utils.py
# API_LEVEL = None
# 
# 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()


import copy
import pickle
from java import cast, jarray, jclass
from unittest import skipIf
from .test_utils import API_LEVEL, FilterWarningsCase
from com.chaquo.python import TestReflect as TR
from java.lang import Boolean, Object, String, System
    from .test_utils import assertDir
        from .test_utils import Object_names
        from com.chaquo.python import TestReflectKt as TRK
        with self.assertRaises(jclass("java.lang.NoClassDefFoundError")):
            jclass("java.lang.Nonexistent")

    def test_cast(self):
        b = Boolean(True)
        b_Object = cast(Object, b)
        self.assertIsNot(b, b_Object)
        self.assertEqual(b, b_Object)
        self.assertIs(Boolean.getClass(), b.getClass())
        self.assertIs(Boolean.getClass(), b_Object.getClass())
        self.assertIsNot(Object.getClass(), b_Object.getClass())
        self.assertIs(b_Object, cast(Object, b))
        self.assertIs(b, cast(Boolean, b_Object))

        for obj in [Boolean, "Ljava/lang/Boolean;"]:
            with self.subTest(obj=obj):
                with self.assertRaisesRegex(TypeError, "cannot create java.lang.Boolean "
                                            "proxy from java.lang.Object instance"):
                    cast(obj, Object())

        with self.assertRaisesRegex(jclass("java.lang.NoClassDefFoundError"),
                                    "java.lang.Nonexistent"):
            cast("Ljava/lang/Nonexistent;", Object())

        with self.assertRaisesRegex(ValueError, "Invalid JNI signature: 'java.lang.Object'"):
            cast("java.lang.Object", Object())

        for obj in [0, True, None, int, str]:
            with self.subTest(obj=obj):
                with self.assertRaisesRegex(TypeError, f"{obj!r} is not a Java type"):

# Path: app/src/main/python/chaquopy/test/test_utils.py
# API_LEVEL = None
# 
# 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_reflect.py
import copy
import pickle
from java import cast, jarray, jclass
from unittest import skipIf
from .test_utils import API_LEVEL, FilterWarningsCase
from com.chaquo.python import TestReflect as TR
from java.lang import Boolean, Object, String, System
    from .test_utils import assertDir
        from .test_utils import Object_names
        from com.chaquo.python import TestReflectKt as TRK

        with self.assertRaises(jclass("java.lang.NoClassDefFoundError")):
            jclass("java.lang.Nonexistent")

    def test_cast(self):
        b = Boolean(True)
        b_Object = cast(Object, b)
        self.assertIsNot(b, b_Object)
        self.assertEqual(b, b_Object)
        self.assertIs(Boolean.getClass(), b.getClass())
        self.assertIs(Boolean.getClass(), b_Object.getClass())
        self.assertIsNot(Object.getClass(), b_Object.getClass())
        self.assertIs(b_Object, cast(Object, b))
        self.assertIs(b, cast(Boolean, b_Object))

        for obj in [Boolean, "Ljava/lang/Boolean;"]:
            with self.subTest(obj=obj):
                with self.assertRaisesRegex(TypeError, "cannot create java.lang.Boolean "
                                            "proxy from java.lang.Object instance"):
                    cast(obj, Object())

        with self.assertRaisesRegex(jclass("java.lang.NoClassDefFoundError"),
                                    "java.lang.Nonexistent"):
            cast("Ljava/lang/Nonexistent;", Object())

        with self.assertRaisesRegex(ValueError, "Invalid JNI signature: 'java.lang.Object'"):
            cast("java.lang.Object", Object())

        for obj in [0, True, None, int, str]:
            with self.subTest(obj=obj):
                with self.assertRaisesRegex(TypeError, f"{obj!r} is not a Java type"):

                    cast(obj, Object())