# 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()


import copy
import ctypes
import pickle
        import array
        import array
from java import (cast, jarray, jboolean, jbyte, jchar, jclass, jdouble, jfloat, jint,
                  jlong, jshort)
from .test_utils import FilterWarningsCase
from com.chaquo.python import TestArray as TA
from java.lang import String, System
    from .test_utils import assertTimeLimit
        from java.lang import Object
        from collections import abc
        b = jarray(jint)(500000)
        with self.assertTimeLimit(0.5):
            a[:] = b

    def test_invalid_index(self):
        a = jarray(jint)(SLICE_DATA)
        for index in ["", "hello", 0.0, 1.0]:
            with self.subTest(index=index):
                error = self.assertRaisesRegex(
                    TypeError, fr"array indices must be integers or slices, not "
                    fr"{type(index).__name__}")
                with error:
                    a[index]
                with error:
                    a[index] = 99
                self.assertEqual(SLICE_DATA, a)

    # Most of the positive tests are in test_conversion, but here are some error tests.
    def test_modify(self):
        Object = jclass("java.lang.Object")
        array_Z = jarray(jboolean)([True, False])
        with self.assertRaisesRegex(TypeError, "Cannot convert int object to boolean"):
            array_Z[0] = 1
        with self.assertRaisesRegex(TypeError, "Cannot convert Object object to boolean"):
            array_Z[0] = Object()

        Boolean = jclass("java.lang.Boolean")
        array_Boolean = jarray(Boolean)([True, False])
        with self.assertRaisesRegex(TypeError, "Cannot convert int object to java.lang.Boolean"):
            array_Boolean[0] = 1

# 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_array.py
import copy
import ctypes
import pickle
        import array
        import array
from java import (cast, jarray, jboolean, jbyte, jchar, jclass, jdouble, jfloat, jint,
                  jlong, jshort)
from .test_utils import FilterWarningsCase
from com.chaquo.python import TestArray as TA
from java.lang import String, System
    from .test_utils import assertTimeLimit
        from java.lang import Object
        from collections import abc

        b = jarray(jint)(500000)
        with self.assertTimeLimit(0.5):
            a[:] = b

    def test_invalid_index(self):
        a = jarray(jint)(SLICE_DATA)
        for index in ["", "hello", 0.0, 1.0]:
            with self.subTest(index=index):
                error = self.assertRaisesRegex(
                    TypeError, fr"array indices must be integers or slices, not "
                    fr"{type(index).__name__}")
                with error:
                    a[index]
                with error:
                    a[index] = 99
                self.assertEqual(SLICE_DATA, a)

    # Most of the positive tests are in test_conversion, but here are some error tests.
    def test_modify(self):
        Object = jclass("java.lang.Object")
        array_Z = jarray(jboolean)([True, False])
        with self.assertRaisesRegex(TypeError, "Cannot convert int object to boolean"):
            array_Z[0] = 1
        with self.assertRaisesRegex(TypeError, "Cannot convert Object object to boolean"):
            array_Z[0] = Object()

        Boolean = jclass("java.lang.Boolean")
        array_Boolean = jarray(Boolean)([True, False])
        with self.assertRaisesRegex(TypeError, "Cannot convert int object to java.lang.Boolean"):
            array_Boolean[0] = 1

        with self.assertRaisesRegex(TypeError, "Cannot convert int object to java.lang.Boolean"):