diff --git a/test/jpypetest/test_non_ascii_paths.py b/test/jpypetest/test_non_ascii_paths.py deleted file mode 100644 index ddaf526f2..000000000 --- a/test/jpypetest/test_non_ascii_paths.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -Regression test for https://github.com/jpype-project/jpype/issues/1194 -""" - -import unittest -import jpype -from pathlib import Path -import shutil -from multiprocessing import get_context, Queue, Process - - -class TestNonAsciiPaths(unittest.TestCase): - # This class does not inherit from ``common.JPypeTestCase`` on purpose - # because it tests starting the JVM with non-ASCII paths. Sub-processes are - # used because restarting the JVM is not supported. - - def setUp(self): - # Create a copy of the mrjar.jar file with a non-ASCII path. - mrjar_path = Path("test/jar/mrjar.jar") - self.mrjar_non_ascii = Path("test/jar/à_non_ascii/mrjar.jar") - self.mrjar_non_ascii.parent.mkdir(exist_ok=True) - shutil.copy(mrjar_path, self.mrjar_non_ascii) - - def tearDown(self): - # Clean up the non-ASCII path. - self.mrjar_non_ascii.unlink() - self.mrjar_non_ascii.parent.rmdir() - - @staticmethod - def _subproc_test_non_ascii_paths(path: str, queue: Queue): - # Can `dir` be called on a package with a non-ASCII path? - jpype.addClassPath(path) - jpype.startJVM(jpype.getDefaultJVMPath()) - queue.put(dir(jpype.JPackage("org.jpype.mrjar"))) - jpype.shutdownJVM() - - def test_non_ascii_paths(self): - # Uses a separate process to avoid polluting the main process with - # a JVM instance, since restarting the JVM is not supported. - ctx = get_context("spawn") - queue: Queue = ctx.Queue() - path = self.mrjar_non_ascii.absolute().as_posix() - proc: Process = ctx.Process( - target=self._subproc_test_non_ascii_paths, args=(path, queue) - ) - proc.start() - proc.join(5) - assert queue.get() == ["A", "B", "sub"] diff --git a/test/jpypetest/test_startup.py b/test/jpypetest/test_startup.py index 350971f09..953c77fba 100644 --- a/test/jpypetest/test_startup.py +++ b/test/jpypetest/test_startup.py @@ -21,6 +21,8 @@ import os from pathlib import Path import unittest +from tempfile import TemporaryDirectory +import shutil root = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) cp = os.path.join(root, 'classes').replace('\\', '/') @@ -146,3 +148,13 @@ def testPathTwice(self): def testBadKeyword(self): with self.assertRaises(TypeError): jpype.startJVM(invalid=True) # type: ignore + + def testNonASCIIPath(self): + """Test that paths with non-ASCII characters are handled correctly. + Regression test for https://github.com/jpype-project/jpype/issues/1194 + """ + with TemporaryDirectory(suffix="à", delete_on_close=False) as tmp_dir: + tmp_jar = os.path.join(tmp_dir, "mrjar.jar") + shutil.copyfile("test/jar/mrjar.jar", tmp_jar) + jpype.startJVM(jvmpath=Path(self.jvmpath), classpath=tmp_jar, convertStrings=False) + assert jpype.JClass('org.jpype.mrjar.A') is not None