# 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 math import isnan
from java import jarray, jboolean, jbyte, jchar, jclass, jdouble, jfloat, jint, jlong, jshort
from .test_utils import FilterWarningsCase

    def setUp(self):
        super().setUp()
        self.obj = jclass('com.chaquo.python.TestBasics')()
        self.conv_error = self.assertRaisesRegex(TypeError, "Cannot convert")
        self.too_big = self.assertRaisesRegex(OverflowError, "too (big|large) to convert")

    def conv_error_unless(self, flag):
        return None if flag else self.conv_error

    def test_unrelated(self):
        String = jclass("java.lang.String")
        for value in ["hello", String, String("hello")]:
            self.verify_value(self.obj, "Boolean", value, context=self.conv_error)

    def test_parent_to_child(self):
        Object = jclass("java.lang.Object")
        for name in ["Boolean", "ZArray"]:
            self.verify_value(self.obj, name, Object(), context=self.conv_error)

    def test_boolean(self):
        self.verify_boolean(self.obj, "Z")
        self.verify_boolean(self.obj, "Boolean", allow_null=True)
        self.verify_boolean(self.obj, "Object", allow_int=True, allow_null=True)

    def verify_boolean(self, obj, name, allow_int=False, allow_null=False):
        self.verify_value(obj, name, True, wrapper=jboolean)

        # Wrapper type and bounds checks are tested in test_signatures.
        self.verify_value(obj, name, 1, context=self.conv_error_unless(allow_int))

# 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_conversion.py
from math import isnan
from java import jarray, jboolean, jbyte, jchar, jclass, jdouble, jfloat, jint, jlong, jshort
from .test_utils import FilterWarningsCase


    def setUp(self):
        super().setUp()
        self.obj = jclass('com.chaquo.python.TestBasics')()
        self.conv_error = self.assertRaisesRegex(TypeError, "Cannot convert")
        self.too_big = self.assertRaisesRegex(OverflowError, "too (big|large) to convert")

    def conv_error_unless(self, flag):
        return None if flag else self.conv_error

    def test_unrelated(self):
        String = jclass("java.lang.String")
        for value in ["hello", String, String("hello")]:
            self.verify_value(self.obj, "Boolean", value, context=self.conv_error)

    def test_parent_to_child(self):
        Object = jclass("java.lang.Object")
        for name in ["Boolean", "ZArray"]:
            self.verify_value(self.obj, name, Object(), context=self.conv_error)

    def test_boolean(self):
        self.verify_boolean(self.obj, "Z")
        self.verify_boolean(self.obj, "Boolean", allow_null=True)
        self.verify_boolean(self.obj, "Object", allow_int=True, allow_null=True)

    def verify_boolean(self, obj, name, allow_int=False, allow_null=False):
        self.verify_value(obj, name, True, wrapper=jboolean)

        # Wrapper type and bounds checks are tested in test_signatures.
        self.verify_value(obj, name, 1, context=self.conv_error_unless(allow_int))

        self.verify_value(obj, name, None, context=self.conv_error_unless(allow_null))