diff --git a/src/core/IronPython.Modules/binascii.cs b/src/core/IronPython.Modules/binascii.cs index 6d7fe0429..c87394721 100644 --- a/src/core/IronPython.Modules/binascii.cs +++ b/src/core/IronPython.Modules/binascii.cs @@ -320,15 +320,19 @@ static void to_hex(char ch, StringBuilder s, int index) { #region hqx + // TODO: removed in 3.11 public static object a2b_hqx(object? data) { throw new NotImplementedException(); } + // TODO: removed in 3.11 public static object rledecode_hqx(object? data) { throw new NotImplementedException(); } + // TODO: removed in 3.11 public static object rlecode_hqx(object? data) { throw new NotImplementedException(); } + // TODO: removed in 3.11 public static object b2a_hqx(object? data) { throw new NotImplementedException(); } diff --git a/src/core/IronPython.Modules/cmath.cs b/src/core/IronPython.Modules/cmath.cs index 5f8207cb3..eb8a4fabd 100644 --- a/src/core/IronPython.Modules/cmath.cs +++ b/src/core/IronPython.Modules/cmath.cs @@ -146,7 +146,7 @@ public static Complex acos([NotNone] object x) { double real = Math.Acos(0.5 * (a - b)); double imag = Math.Log(c + Math.Sqrt(c + 1) * Math.Sqrt(c - 1)); - return new Complex(real, num.Imaginary >= 0 ? imag : -imag); + return new Complex(real, DoubleOps.IsNegative(num.Imaginary) ? imag : -imag); } //asin(x) = -i*ln( i*x + (1-x*x)^1/2) diff --git a/src/core/IronPython.StdLib/lib/test/test_platform.py b/src/core/IronPython.StdLib/lib/test/test_platform.py index b3de43b7a..eac40a35a 100644 --- a/src/core/IronPython.StdLib/lib/test/test_platform.py +++ b/src/core/IronPython.StdLib/lib/test/test_platform.py @@ -59,14 +59,15 @@ def test_processor(self): def setUp(self): self.save_version = sys.version - self.save_mercurial = sys._mercurial + self.save_git = sys._git self.save_platform = sys.platform def tearDown(self): sys.version = self.save_version - sys._mercurial = self.save_mercurial + sys._git = self.save_git sys.platform = self.save_platform + @unittest.skipIf(sys.implementation.name == "ironpython", "not compatible with IronPython platform changes") def test_sys_version(self): # Old test. for input, output in ( @@ -78,7 +79,7 @@ def test_sys_version(self): ('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')), ): # branch and revision are not "parsed", but fetched - # from sys._mercurial. Ignore them + # from sys._git. Ignore them (name, version, branch, revision, buildno, builddate, compiler) \ = platform._sys_version(input) self.assertEqual( @@ -125,10 +126,10 @@ def test_sys_version(self): sys_versions.items(): sys.version = version_tag if subversion is None: - if hasattr(sys, "_mercurial"): - del sys._mercurial + if hasattr(sys, "_git"): + del sys._git else: - sys._mercurial = subversion + sys._git = subversion if sys_platform is not None: sys.platform = sys_platform self.assertEqual(platform.python_implementation(), info[0]) diff --git a/src/core/IronPython.StdLib/lib/test/test_venv.py b/src/core/IronPython.StdLib/lib/test/test_venv.py index b462588e3..a0e8de82c 100644 --- a/src/core/IronPython.StdLib/lib/test/test_venv.py +++ b/src/core/IronPython.StdLib/lib/test/test_venv.py @@ -18,13 +18,6 @@ import unittest import venv -# pip currently requires ssl support, so we ensure we handle -# it being missing (http://bugs.python.org/issue19744) -try: - import ssl -except ImportError: - ssl = None - skipInVenv = unittest.skipIf(sys.prefix != sys.base_prefix, 'Test not appropriate in a venv') @@ -307,18 +300,17 @@ def test_explicit_no_pip(self): self.run_with_capture(venv.create, self.env_dir, with_pip=False) self.assert_pip_not_installed() - @failsOnWindows - def test_devnull_exists_and_is_empty(self): + def test_devnull(self): # Fix for issue #20053 uses os.devnull to force a config file to # appear empty. However http://bugs.python.org/issue20541 means # that doesn't currently work properly on Windows. Once that is # fixed, the "win_location" part of test_with_pip should be restored - self.assertTrue(os.path.exists(os.devnull)) with open(os.devnull, "rb") as f: self.assertEqual(f.read(), b"") + self.assertTrue(os.path.exists(os.devnull)) + # Requesting pip fails without SSL (http://bugs.python.org/issue19744) - @unittest.skipIf(ssl is None, ensurepip._MISSING_SSL_MESSAGE) def test_with_pip(self): rmtree(self.env_dir) with EnvironmentVarGuard() as envvars: diff --git a/src/core/IronPython/Runtime/Operations/FloatOps.cs b/src/core/IronPython/Runtime/Operations/FloatOps.cs index 0ca673710..61df44832 100644 --- a/src/core/IronPython/Runtime/Operations/FloatOps.cs +++ b/src/core/IronPython/Runtime/Operations/FloatOps.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Globalization; using System.Numerics; +using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; @@ -638,6 +639,15 @@ internal static bool IsNegativeZero(double value) { return (value == 0.0) && double.IsNegativeInfinity(1.0 / value); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static bool IsNegative(double value) { +#if NET7_0_OR_GREATER + return double.IsNegative(value); +#else + return value < 0.0 || IsNegativeZero(value); +#endif + } + internal static int Sign(double value) { if (value == 0.0) { return double.IsPositiveInfinity(1.0 / value) ? 1 : -1; diff --git a/src/executables/IronPython.Console/ipy-mono.sh b/src/executables/IronPython.Console/ipy-mono.sh index 11df78b15..b0055c706 100755 --- a/src/executables/IronPython.Console/ipy-mono.sh +++ b/src/executables/IronPython.Console/ipy-mono.sh @@ -1,4 +1,4 @@ #!/bin/sh -BASEDIR=$(dirname "$0") +BASEDIR=$(dirname $(readlink -f "$0")) ABS_PATH=$(cd "$BASEDIR"; pwd) -mono "$ABS_PATH/ipy.exe" "$@" \ No newline at end of file +mono "$ABS_PATH/ipy.exe" "$@" diff --git a/tests/IronPython.Tests/Cases/CPythonCasesManifest.ini b/tests/IronPython.Tests/Cases/CPythonCasesManifest.ini index 98688b1b1..899fd1725 100644 --- a/tests/IronPython.Tests/Cases/CPythonCasesManifest.ini +++ b/tests/IronPython.Tests/Cases/CPythonCasesManifest.ini @@ -105,7 +105,7 @@ Ignore=true RunCondition=$(IS_OSX) Ignore=true -[CPython.test_aifc] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_aifc] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true Reason=ImportError: No module named audioop @@ -115,7 +115,7 @@ IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/489 [CPython.test_ast] Ignore=true -[CPython.test_asynchat] # Module will be removed in 3.12 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_asynchat] # Module has been removed in 3.12 - https://github.com/IronLanguages/ironpython3/issues/1352 RunCondition=NOT $(IS_OSX) # TODO: debug [CPython.test_asyncio.test_base_events] @@ -151,20 +151,20 @@ Ignore=true [CPython.test_asyncio.test_windows_utils] Ignore=true -[CPython.test_asyncore] # Module will be removed in 3.12 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_asyncore] # Module has been removed in 3.12 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true [CPython.test_atexit] Ignore=true -[CPython.test_audioop] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_audioop] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true Reason=ImportError: No module named audioop [CPython.test_bigmem] Ignore=true -[CPython.test_binhex] +[CPython.test_binhex] # Module has been removed in 3.11 Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/673 [CPython.test_builtin] # IronPython.test_builtin_stdlib @@ -188,11 +188,11 @@ Timeout=600000 # 10 minute timeout Ignore=true Reason=ImportError: No module named _testcapi -[CPython.test_cgi] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_cgi] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 RunCondition=NOT $(IS_MONO) Reason=SystemError: The stream does not support seeking -[CPython.test_cgitb] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_cgitb] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true [CPython.test_class] # IronPython.test_class_stdlib @@ -293,7 +293,7 @@ Ignore=true Ignore=true Reason=ImportError: No module named _lsprof -[CPython.test_crypt] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_crypt] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true Reason=ImportError: No module named _crypt @@ -478,7 +478,7 @@ Reason=Blocking [CPython.test_httpservers] Ignore=true -Reason=Blocking +Reason=Blocking # works? [CPython.test_idle] Ignore=true @@ -592,7 +592,7 @@ Ignore=true [CPython.test_modulefinder] Ignore=true -[CPython.test_msilib] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_msilib] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true Reason=ImportError: No module named _msi @@ -616,12 +616,12 @@ Reason=ImportError: No module named _multiprocessing Ignore=true Reason=ImportError: No module named _multiprocessing -[CPython.test_nis] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_nis] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 RunCondition=$(IS_POSIX) Ignore=true Reason=unittest.case.SkipTest: No module named 'nis' -[CPython.test_nntplib] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_nntplib] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true # currently failing during CI RunCondition=NOT $(IS_NETCOREAPP) # https://github.com/IronLanguages/ironpython3/issues/1058 @@ -641,7 +641,7 @@ Reason=unittest.case.SkipTest: os.openpty() not available. Ignore=true Reason=AttributeError: 'module' object has no attribute 'isatty' -[CPython.test_ossaudiodev] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_ossaudiodev] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true Reason=unittest.case.SkipTest: No module named 'ossaudiodev' @@ -682,7 +682,7 @@ Reason=StackOverflowException Ignore=true Reason=StackOverflowException -[CPython.test_pipes] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_pipes] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 RunCondition=$(IS_POSIX) Ignore=true Reason=unittest.case.SkipTest: pipes module only works on posix @@ -694,8 +694,7 @@ Ignore=true Ignore=true [CPython.test_platform] -Ignore=true -Reason=AttributeError: 'module' object has no attribute '_mercurial' +RunCondition=NOT $(IS_OSX) [CPython.test_poll] RunCondition=$(IS_POSIX) @@ -802,7 +801,7 @@ Ignore=true [CPython.test_site] Ignore=true -[CPython.test_smtpd] # Module will be removed in 3.12 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_smtpd] # Module has been removed in 3.12 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true [CPython.test_smtplib] @@ -817,7 +816,7 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/122 [CPython.test_source_encoding] IsolationLevel=ENGINE # source file in a non-UTF-8 encoding -[CPython.test_spwd] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_spwd] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 RunCondition=$(IS_POSIX) [CPython.test_sqlite] @@ -858,7 +857,7 @@ IsolationLevel=PROCESS Redirect=true Ignore=true -[CPython.test_sunau] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_sunau] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 Ignore=true Reason=ImportError: No module named audioop @@ -908,7 +907,7 @@ Ignore=true Ignore=true Reason=ImportError: No module named '_tkinter' -[CPython.test_telnetlib] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 +[CPython.test_telnetlib] # Module has been removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352 RunCondition=NOT $(IS_LINUX) # TODO: debug [CPython.test_tempfile] diff --git a/tests/IronPython.Tests/Cases/CaseExecuter.cs b/tests/IronPython.Tests/Cases/CaseExecuter.cs index b53a7d856..7b34cba44 100644 --- a/tests/IronPython.Tests/Cases/CaseExecuter.cs +++ b/tests/IronPython.Tests/Cases/CaseExecuter.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.ExceptionServices; using System.Text.RegularExpressions; using System.Threading; @@ -290,7 +291,9 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc engine.GetSysModule().SetVariable("argv", PythonList.FromArrayNoCopy(new object[] { source.Path })); var compiledCode = source.Compile(new IronPython.Compiler.PythonCompilerOptions() { ModuleName = "__main__" }); - int res = 0; + ExceptionDispatchInfo exceptionInfo = null; + + int res = -1; int maxStackSize = 2 * 1024 * 1024; // 2 MiB var thread = new Thread(() => { try { @@ -301,12 +304,12 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc #pragma warning disable SYSLIB0006 // 'Thread.ResetAbort is not supported and throws PlatformNotSupportedException.' Thread.ResetAbort(); #pragma warning restore SYSLIB0006 - } catch (Exception ex) when (ex.GetPythonException() is object pex) { - if (DynamicHelpers.GetPythonType(pex).Name == "SkipTest") { + } catch (Exception ex) { + if (ex.GetPythonException() is object pex && DynamicHelpers.GetPythonType(pex).Name == "SkipTest") { NUnit.Framework.TestContext.Progress.WriteLine($"Test {testcase.Name} skipped: {pex}"); res = 0; } else { - throw; + exceptionInfo = ExceptionDispatchInfo.Capture(ex); } } }, maxStackSize) { @@ -324,6 +327,9 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc NUnit.Framework.TestContext.Error.WriteLine($"{testcase.Name} timed out after {testcase.Options.Timeout / 1000.0} seconds."); return -1; } + + exceptionInfo?.Throw(); + return res; } finally { Environment.CurrentDirectory = cwd;