# 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 jclass, set_import_enabled
from .test_utils import FilterWarningsCase
        from java.lang import String  # noqa: F401
            from java.lang import String  # noqa: F811
        from java.lang import String  # noqa: F401, F811
        from java.lang import String
        from javax.xml import XMLConstants
        from java.lang import Integer, Float
        from java.lang import Integer, Integer
            from java.lang import Nonexistent  # noqa: F401
            from package1 import wildcard_java_lang  # noqa: F401
            from javax.xml import Nonexistent  # noqa: F401, F811
            from package1 import wildcard_javax_xml  # noqa: F401
            from java.lang import String, Nonexistent  # noqa: F401, F811
            from sys import path, Nonexistent  # noqa: F401, F811
            from package1 import syntax_error  # noqa: F401
            from package1 import recursive_import_error  # noqa: F401
            from java import lang  # noqa: F401
            from javax import xml  # noqa: F401
        from package1 import java, python, both
            from package1 import java, Nonexistent, python  # noqa: F401, F811
        from module1 import test_relative
        from package1 import test_relative
        from package1.package11 import test_relative
        from namespace import mod1
import sys
            import java.lang.String  # noqa: F401
            import javax.xml.XMLConstants  # noqa: F401
            import java.lang  # noqa: F401
            import javax.xml  # noqa: F401
        import package1.python
        import package1.both
        with self.no_module_error("javax"):

        # A Java name and a nonexistent one.
        with self.no_name_error("Nonexistent"):

        # A Python name and a nonexistent one.
        with self.no_name_error("Nonexistent"):

        # These test files are also used in test_android.py.
        with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
        with self.no_name_error("nonexistent"):

    def test_package(self):
        # See note above about "java" sub-packages.
        with self.no_module_error("java.lang"):
        with self.no_name_error("lang"):

        with self.no_module_error("javax"):
        with self.no_module_error("javax"):

    def test_multi_language(self):
        self.assertEqual("java 1", java.x)
        self.assertEqual("python 1", python.x)
        self.assertEqual("both python 1", both.x)
        self.assertEqual("both java 1", jclass("package1.both").x)

        self.assertIs(python, package1.python)
        self.assertIs(both, package1.both)

        # A name from each language, and a nonexistent one.

# 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_import.py
from java import jclass, set_import_enabled
from .test_utils import FilterWarningsCase
        from java.lang import String  # noqa: F401
            from java.lang import String  # noqa: F811
        from java.lang import String  # noqa: F401, F811
        from java.lang import String
        from javax.xml import XMLConstants
        from java.lang import Integer, Float
        from java.lang import Integer, Integer
            from java.lang import Nonexistent  # noqa: F401
            from package1 import wildcard_java_lang  # noqa: F401
            from javax.xml import Nonexistent  # noqa: F401, F811
            from package1 import wildcard_javax_xml  # noqa: F401
            from java.lang import String, Nonexistent  # noqa: F401, F811
            from sys import path, Nonexistent  # noqa: F401, F811
            from package1 import syntax_error  # noqa: F401
            from package1 import recursive_import_error  # noqa: F401
            from java import lang  # noqa: F401
            from javax import xml  # noqa: F401
        from package1 import java, python, both
            from package1 import java, Nonexistent, python  # noqa: F401, F811
        from module1 import test_relative
        from package1 import test_relative
        from package1.package11 import test_relative
        from namespace import mod1
import sys
            import java.lang.String  # noqa: F401
            import javax.xml.XMLConstants  # noqa: F401
            import java.lang  # noqa: F401
            import javax.xml  # noqa: F401
        import package1.python
        import package1.both

        with self.no_module_error("javax"):

        # A Java name and a nonexistent one.
        with self.no_name_error("Nonexistent"):

        # A Python name and a nonexistent one.
        with self.no_name_error("Nonexistent"):

        # These test files are also used in test_android.py.
        with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
        with self.no_name_error("nonexistent"):

    def test_package(self):
        # See note above about "java" sub-packages.
        with self.no_module_error("java.lang"):
        with self.no_name_error("lang"):

        with self.no_module_error("javax"):
        with self.no_module_error("javax"):

    def test_multi_language(self):
        self.assertEqual("java 1", java.x)
        self.assertEqual("python 1", python.x)
        self.assertEqual("both python 1", both.x)
        self.assertEqual("both java 1", jclass("package1.both").x)

        self.assertIs(python, package1.python)
        self.assertIs(both, package1.both)

        # A name from each language, and a nonexistent one.

        with self.no_name_error("Nonexistent"):