From d284deebd5e6aed162608605931ce30ee138c533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Thu, 12 May 2022 08:14:40 -0400 Subject: [PATCH 01/17] Re-enable test_range --- Src/IronPython/Runtime/PythonRange.cs | 6 +++--- Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Src/IronPython/Runtime/PythonRange.cs b/Src/IronPython/Runtime/PythonRange.cs index 750791250..d5cde273d 100644 --- a/Src/IronPython/Runtime/PythonRange.cs +++ b/Src/IronPython/Runtime/PythonRange.cs @@ -83,9 +83,9 @@ public PythonTuple __reduce__() { ); } - public int __len__() { - return (int)_length; - } + public int __len__() => (int)_length; + + public bool __bool__() => _length != 0; public object this[int index] => this[(BigInteger)index]; diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index 8dc0b64ae..cffe596c8 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1251,9 +1251,6 @@ Ignore=true # StackOverflowException [CPython.test_print] Ignore=true # 7 failures -[CPython.test_range] -Ignore=true # OverflowError: Arithmetic operation resulted in an overflow. - [CPython.test_regrtest] Ignore=true # lots of failures From 9229e4d109063b58f9f73b073f687a0720428103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Thu, 12 May 2022 08:57:18 -0400 Subject: [PATCH 02/17] Re-enable test_richcmp --- Src/IronPython/Runtime/Operations/PythonOps.cs | 2 +- Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Src/IronPython/Runtime/Operations/PythonOps.cs b/Src/IronPython/Runtime/Operations/PythonOps.cs index 4da2fa404..f641fc2f2 100644 --- a/Src/IronPython/Runtime/Operations/PythonOps.cs +++ b/Src/IronPython/Runtime/Operations/PythonOps.cs @@ -4012,7 +4012,7 @@ internal static Exception TypeErrorForBadInstance(string template, object? insta } public static Exception TypeErrorForBinaryOp(string opSymbol, object? x, object? y) { - throw PythonOps.TypeError("unsupported operand type(s) for {0}: '{1}' and '{2}'", + throw PythonOps.TypeError("'{0}' not supported between instances of '{1}' and '{2}'", opSymbol, GetPythonTypeName(x), GetPythonTypeName(y)); } diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index cffe596c8..d3239c79b 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1254,9 +1254,6 @@ Ignore=true # 7 failures [CPython.test_regrtest] Ignore=true # lots of failures -[CPython.test_richcmp] -Ignore=true # error message changed? - [CPython.test_set] Ignore=true # test_hash_effectiveness From 7bbce645c0022a9ee994ef037dae586a42c421d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Thu, 12 May 2022 16:26:39 -0400 Subject: [PATCH 03/17] Re-enable test_mmap --- Src/IronPython.Modules/mmap.cs | 13 ++++++++----- Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 3 --- Src/StdLib/Lib/test/test_mmap.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Src/IronPython.Modules/mmap.cs b/Src/IronPython.Modules/mmap.cs index 38535165c..c85bb825b 100644 --- a/Src/IronPython.Modules/mmap.cs +++ b/Src/IronPython.Modules/mmap.cs @@ -727,20 +727,23 @@ public object tell() { } } - public void write([BytesLike] IList s) { + public int write([NotNone] IBufferProtocol s) { + using var buffer = s.GetBuffer(); using (new MmapLocker(this)) { EnsureWritable(); long pos = Position; - if (_view.Capacity - pos < s.Count) { + if (_view.Capacity - pos < buffer.AsReadOnlySpan().Length) { throw PythonOps.ValueError("data out of range"); } - byte[] data = s as byte[] ?? (s is Bytes b ? b.UnsafeByteArray : s.ToArray()); - _view.WriteArray(pos, data, 0, s.Count); + byte[] data = buffer.AsUnsafeArray() ?? buffer.ToArray(); + _view.WriteArray(pos, data, 0, data.Length); - Position = pos + s.Count; + Position = pos + data.Length; + + return data.Length; } } diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index d3239c79b..b71e9bcc2 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1233,9 +1233,6 @@ IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/144 [CPython.test_math] Ignore=true # precision? -[CPython.test_mmap] -Ignore=true # 2 failures - [CPython.test_ntpath] Ignore=true # blocked by os.PathLike diff --git a/Src/StdLib/Lib/test/test_mmap.py b/Src/StdLib/Lib/test/test_mmap.py index 604ba7193..92a7b9840 100644 --- a/Src/StdLib/Lib/test/test_mmap.py +++ b/Src/StdLib/Lib/test/test_mmap.py @@ -53,7 +53,7 @@ def test_basic(self): # Shouldn't crash on boundary (Issue #5292) self.assertRaises(IndexError, m.__getitem__, len(m)) - self.assertRaises(IndexError, m.__setitem__, len(m), b'\0') + self.assertRaises(IndexError, m.__setitem__, len(m), 0) # Modify the file's content m[0] = b'3'[0] From 39527cf0c4790eb0743e97f485ca8431629e34b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Thu, 12 May 2022 17:22:49 -0400 Subject: [PATCH 04/17] Add issue numbers --- Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index b71e9bcc2..a8808b327 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1198,7 +1198,7 @@ Ignore=true # two failures Ignore=true # StackOverflowException [CPython.test_fileinput] -Ignore=true # test_errors +Ignore=true # test_errors - https://github.com/IronLanguages/ironpython3/issues/1452 [CPython.test_genericpath] Ignore=true # blocked by os.PathLike @@ -1261,7 +1261,7 @@ Ignore=true # unittest.case.SkipTest: Cannot import name SSLSession Ignore=true # fails on macOS [CPython.test_string] -Ignore=true # test_invalid_placeholders +Ignore=true # test_invalid_placeholders - https://github.com/IronLanguages/ironpython3/issues/1419 [CPython.test_string_literals] Ignore=true # AssertionError: DeprecationWarning not triggered @@ -1279,7 +1279,7 @@ Ignore=true # blocking Ignore=true # blocking [CPython.test_uuid] -Ignore=true # LookupError: unknown encoding: oem +Ignore=true # LookupError: unknown encoding: oem - https://github.com/IronLanguages/ironpython3/issues/1451 [CPython.test_winreg] Ignore=true # 3 failures From b0ddbb97869216406411da55d4cd71e3a38e3e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Thu, 12 May 2022 20:20:03 -0400 Subject: [PATCH 05/17] Fix failing test --- Src/IronPython/Runtime/Operations/PythonOps.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/IronPython/Runtime/Operations/PythonOps.cs b/Src/IronPython/Runtime/Operations/PythonOps.cs index f641fc2f2..41fe506eb 100644 --- a/Src/IronPython/Runtime/Operations/PythonOps.cs +++ b/Src/IronPython/Runtime/Operations/PythonOps.cs @@ -758,7 +758,7 @@ public static object PowerMod(CodeContext/*!*/ context, object? x, object? y, ob } } - throw PythonOps.TypeErrorForBinaryOp("power with modulus", x, y); + throw PythonOps.TypeError("unsupported operand type(s) for pow(): '{0}', '{1}', '{2}'", GetPythonTypeName(x), GetPythonTypeName(y), GetPythonTypeName(y)); } public static long Id(object? o) { From 05917cc45fbb34c6de4b49c29fd88aef6a1a38a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Thu, 12 May 2022 22:50:58 -0400 Subject: [PATCH 06/17] Re-enable test_list --- Src/IronPython/Runtime/Operations/PythonOps.cs | 10 ++++++++-- Src/IronPython/Runtime/PythonList.cs | 5 ++++- Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 7 ++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Src/IronPython/Runtime/Operations/PythonOps.cs b/Src/IronPython/Runtime/Operations/PythonOps.cs index 41fe506eb..073868b35 100644 --- a/Src/IronPython/Runtime/Operations/PythonOps.cs +++ b/Src/IronPython/Runtime/Operations/PythonOps.cs @@ -896,10 +896,16 @@ public static int Length(object? o) { } internal static bool TryInvokeLengthHint(CodeContext context, object? sequence, out int hint) { - if (PythonTypeOps.TryInvokeUnaryOperator(context, sequence, "__len__", out object len_obj) || - PythonTypeOps.TryInvokeUnaryOperator(context, sequence, "__length_hint__", out len_obj)) { + if (PythonTypeOps.TryInvokeUnaryOperator(context, sequence, "__len__", out object len_obj)) { if (!(len_obj is NotImplementedType)) { hint = Converter.ConvertToInt32(len_obj); + if (hint < 0) throw ValueError("__len__() should return >= 0"); + return true; + } + } else if (PythonTypeOps.TryInvokeUnaryOperator(context, sequence, "__length_hint__", out len_obj)) { + if (!(len_obj is NotImplementedType)) { + hint = Converter.ConvertToInt32(len_obj); + if (hint < 0) throw ValueError("__length_hint__() should return >= 0"); return true; } } diff --git a/Src/IronPython/Runtime/PythonList.cs b/Src/IronPython/Runtime/PythonList.cs index bc7a9e6bf..1c0e6c09e 100644 --- a/Src/IronPython/Runtime/PythonList.cs +++ b/Src/IronPython/Runtime/PythonList.cs @@ -740,7 +740,10 @@ public void extend([NotNone] PythonTuple/*!*/ seq) { public void extend(object? seq) { if (PythonOps.TryInvokeLengthHint(DefaultContext.Default, seq, out int len)) { - EnsureSize(len); + // CPython proceeds without resizing if the length overflows + if (int.MaxValue - len >= Count) { + EnsureSize(Count + len); + } } ExtendNoLengthCheck(seq); diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index a8808b327..e0a02fea9 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1224,9 +1224,6 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/105 [CPython.test_linecache] Ignore=true # two failures -[CPython.test_list] -Ignore=true # blocking - [CPython.test_macpath] IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/1440 @@ -1273,10 +1270,10 @@ Ignore=true # lots of failures Ignore=true # 4 failures [CPython.test_userdict] -Ignore=true # blocking +Ignore=true # StackOverflowException [CPython.test_userlist] -Ignore=true # blocking +Ignore=true # test_free_after_iterating [CPython.test_uuid] Ignore=true # LookupError: unknown encoding: oem - https://github.com/IronLanguages/ironpython3/issues/1451 From 0bcd567b08438d1fac5f901e29f01636a81c026b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Fri, 13 May 2022 08:45:48 -0400 Subject: [PATCH 07/17] Re-enable ctypes.test_frombuffer --- Src/IronPython.Modules/_ctypes/CData.cs | 6 ++---- Src/IronPython.Modules/_ctypes/CFuncPtrType.cs | 6 ++++++ Src/IronPython.Modules/_ctypes/PointerType.cs | 6 ++++++ Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 5 +---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Src/IronPython.Modules/_ctypes/CData.cs b/Src/IronPython.Modules/_ctypes/CData.cs index 147061c25..fc004eb53 100644 --- a/Src/IronPython.Modules/_ctypes/CData.cs +++ b/Src/IronPython.Modules/_ctypes/CData.cs @@ -72,8 +72,7 @@ internal void SetAddress(IntPtr address) { internal void InitializeFromBuffer(object? data, int offset, int size) { var bp = data as IBufferProtocol - ?? throw PythonOps.TypeErrorForBadInstance("{0} object does not have the buffer interface", data); - // Python 3.5: PythonOps.TypeErrorForBytesLikeTypeMismatch(data); + ?? throw PythonOps.TypeErrorForBytesLikeTypeMismatch(data); IPythonBuffer buffer = bp.GetBuffer(BufferFlags.FullRO); if (buffer.IsReadOnly) { @@ -97,8 +96,7 @@ internal void InitializeFromBuffer(object? data, int offset, int size) { internal void InitializeFromBufferCopy(object? data, int offset, int size) { var bp = data as IBufferProtocol - ?? throw PythonOps.TypeErrorForBadInstance("{0} object does not have the buffer interface", data); - // Python 3.5: PythonOps.TypeErrorForBytesLikeTypeMismatch(data); + ?? throw PythonOps.TypeErrorForBytesLikeTypeMismatch(data); using IPythonBuffer buffer = bp.GetBuffer(); var span = buffer.AsReadOnlySpan(); diff --git a/Src/IronPython.Modules/_ctypes/CFuncPtrType.cs b/Src/IronPython.Modules/_ctypes/CFuncPtrType.cs index 4e0d81143..bb97ddc34 100644 --- a/Src/IronPython.Modules/_ctypes/CFuncPtrType.cs +++ b/Src/IronPython.Modules/_ctypes/CFuncPtrType.cs @@ -69,6 +69,12 @@ internal static PythonType MakeSystemType(Type underlyingSystemType) { return PythonType.SetPythonType(underlyingSystemType, new CFuncPtrType(underlyingSystemType)); } + public object from_buffer(object obj) + => throw PythonOps.TypeError("abstract class"); + + public object from_buffer_copy(object obj) + => throw PythonOps.TypeError("abstract class"); + /// /// Converts an object into a function call parameter. /// diff --git a/Src/IronPython.Modules/_ctypes/PointerType.cs b/Src/IronPython.Modules/_ctypes/PointerType.cs index 197863398..dba2709ae 100644 --- a/Src/IronPython.Modules/_ctypes/PointerType.cs +++ b/Src/IronPython.Modules/_ctypes/PointerType.cs @@ -47,6 +47,12 @@ private PointerType(Type underlyingSystemType) : base(underlyingSystemType) { } + public object from_buffer(object obj) + => throw PythonOps.TypeError("abstract class"); + + public object from_buffer_copy(object obj) + => throw PythonOps.TypeError("abstract class"); + public object from_param([NotNone] CData obj) { return new NativeArgument((CData)PythonCalls.Call(this, obj), "P"); } diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index e0a02fea9..202dea737 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1161,14 +1161,11 @@ Ignore=true # AssertionError: 'xbd' not found in "" [CPython.ctypes.test_cast] Ignore=true # SystemError: Object reference not set to an instance of an object. -[CPython.ctypes.test_frombuffer] -Ignore=true # 2 failures - [CPython.ctypes.test_structures] Ignore=true # 2 failures [CPython.test_abc] -Ignore=true # test_works_with_init_subclass +Ignore=true # test_works_with_init_subclass - https://github.com/IronLanguages/ironpython3/issues/1448 [CPython.test_array] Ignore=true # test_free_after_iterating/test_type_error From 2c57c8f28423e43a7ae5a6b71348587a22dd5e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Fri, 13 May 2022 10:04:18 -0400 Subject: [PATCH 08/17] Re-enable ctypes.test_cast --- Src/IronPython.Modules/_ctypes/_ctypes.cs | 30 ++++++++----------- .../Cases/CPythonCasesManifest.ini | 3 -- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Src/IronPython.Modules/_ctypes/_ctypes.cs b/Src/IronPython.Modules/_ctypes/_ctypes.cs index 4191cf01b..2fc944378 100644 --- a/Src/IronPython.Modules/_ctypes/_ctypes.cs +++ b/Src/IronPython.Modules/_ctypes/_ctypes.cs @@ -101,27 +101,21 @@ private static IntPtr Cast(IntPtr data, IntPtr obj, IntPtr type) { GCHandle typeHandle = GCHandle.FromIntPtr(type); try { CData cdata = objHandle.Target as CData; - PythonType pt = (PythonType)typeHandle.Target; + PythonType pt = typeHandle.Target as PythonType; - CData res = (CData)pt.CreateInstance(pt.Context.SharedContext); - if (IsPointer(pt)) { - res.MemHolder = new MemoryHolder(IntPtr.Size); - if (IsPointer(DynamicHelpers.GetPythonType(cdata))) { - res.MemHolder.WriteIntPtr(0, cdata.MemHolder.ReadIntPtr(0)); - } else { - res.MemHolder.WriteIntPtr(0, data); - } + if (!IsPointer(pt)) throw PythonOps.TypeError("cast() argument 2 must be a pointer type, not {0}", PythonOps.GetPythonTypeName(typeHandle.Target)); - if (cdata != null) { - res.MemHolder.Objects = cdata.MemHolder.Objects; - res.MemHolder.AddObject(IdDispenser.GetId(cdata), cdata); - } + CData res = (CData)pt.CreateInstance(pt.Context.SharedContext); + res.MemHolder = new MemoryHolder(IntPtr.Size); + if (IsPointer(DynamicHelpers.GetPythonType(cdata))) { + res.MemHolder.WriteIntPtr(0, cdata.MemHolder.ReadIntPtr(0)); } else { - if (cdata != null) { - res.MemHolder = new MemoryHolder(data, ((INativeType)pt).Size, cdata.MemHolder); - } else { - res.MemHolder = new MemoryHolder(data, ((INativeType)pt).Size); - } + res.MemHolder.WriteIntPtr(0, data); + } + + if (cdata != null) { + res.MemHolder.Objects = cdata.MemHolder.Objects; + res.MemHolder.AddObject(IdDispenser.GetId(cdata), cdata); } return GCHandle.ToIntPtr(GCHandle.Alloc(res)); diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index 202dea737..8f672f1be 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1158,9 +1158,6 @@ RunCondition=NOT $(IS_MONO) # TODO: debug [CPython.ctypes.test_bytes] Ignore=true # AssertionError: 'xbd' not found in "" -[CPython.ctypes.test_cast] -Ignore=true # SystemError: Object reference not set to an instance of an object. - [CPython.ctypes.test_structures] Ignore=true # 2 failures From 335cb93b7fb388c85617ba133d699a24959664f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Fri, 13 May 2022 20:28:55 -0400 Subject: [PATCH 09/17] Disable ctypes.test_cast on Linux --- Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index 8f672f1be..3b7edde0b 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1158,6 +1158,9 @@ RunCondition=NOT $(IS_MONO) # TODO: debug [CPython.ctypes.test_bytes] Ignore=true # AssertionError: 'xbd' not found in "" +[CPython.ctypes.test_cast] +RunCondition=NOT $(IS_POSIX) # https://github.com/IronLanguages/ironpython3/issues/1455 + [CPython.ctypes.test_structures] Ignore=true # 2 failures From 80015df9d44666ac3dea821d28fc713980fe3acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 14 May 2022 09:34:18 -0400 Subject: [PATCH 10/17] Re-enable test_deque --- Src/IronPython.Modules/_collections.cs | 21 +++++++-------------- Src/StdLib/Lib/test/test_deque.py | 2 -- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/Src/IronPython.Modules/_collections.cs b/Src/IronPython.Modules/_collections.cs index f0f838ba4..77067c319 100644 --- a/Src/IronPython.Modules/_collections.cs +++ b/Src/IronPython.Modules/_collections.cs @@ -551,20 +551,13 @@ public void __delitem__(CodeContext/*!*/ context, object index) { } } - public PythonTuple __reduce__() { - lock (_lockObj) { - object[] items = new object[_itemCnt]; - int curItem = 0; - WalkDeque(delegate(int curIndex) { - items[curItem++] = _data[curIndex]; - return true; - }); - - return PythonTuple.MakeTuple( - DynamicHelpers.GetPythonType(this), - PythonTuple.MakeTuple(PythonList.FromArrayNoCopy(items)) - ); - } + public PythonTuple __reduce__(CodeContext context) { + return PythonTuple.MakeTuple( + DynamicHelpers.GetPythonType(this), + _maxLen == -1 ? PythonTuple.EMPTY : PythonTuple.MakeTuple(PythonTuple.EMPTY, maxlen), + GetType() == typeof(deque) ? null : PythonOps.GetBoundAttr(context, this, "__dict__"), + PythonOps.GetEnumeratorObject(context, this) + ); } public int __len__() { diff --git a/Src/StdLib/Lib/test/test_deque.py b/Src/StdLib/Lib/test/test_deque.py index f4c5e205f..2193885c8 100644 --- a/Src/StdLib/Lib/test/test_deque.py +++ b/Src/StdLib/Lib/test/test_deque.py @@ -8,7 +8,6 @@ from io import StringIO import random import struct -import sys BIG = 100000 @@ -735,7 +734,6 @@ def test_gc_doesnt_blowup(self): d.append(1) gc.collect() - @unittest.skipIf(sys.implementation.name == "ironpython", "https://github.com/IronLanguages/ironpython3/issues/544") def test_container_iterator(self): # Bug #3680: tp_traverse was not implemented for deque iterator objects class C(object): From 0ac240ed80893a9fd56532ad55ea1b7da2036eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 14 May 2022 09:47:10 -0400 Subject: [PATCH 11/17] Disable on test_deque Mono --- Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index 3b7edde0b..bdd103055 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -339,7 +339,7 @@ Ignore=true [CPython.test_deque] IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/489 -RetryCount=2 +RunCondition=NOT $(IS_MONO) # https://github.com/IronLanguages/ironpython3/issues/544 [CPython.test_descr] IsolationLevel=ENGINE @@ -1191,9 +1191,6 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/98 [CPython.test_csv] Ignore=true # two failures -[CPython.test_deque] -Ignore=true # StackOverflowException - [CPython.test_fileinput] Ignore=true # test_errors - https://github.com/IronLanguages/ironpython3/issues/1452 From 32396a6b2af4c2a30eca33738ec533eb6c58b962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 14 May 2022 15:18:12 -0400 Subject: [PATCH 12/17] Re-enable test_bytes --- Src/IronPython/Modules/Builtin.cs | 2 +- Src/IronPython/Runtime/ByteArray.cs | 27 +++++++++++++------ Src/IronPython/Runtime/Bytes.cs | 22 ++++++++++++--- Src/IronPython/Runtime/Converter.cs | 22 +++++++++------ .../Runtime/Types/TypeCache.Generated.cs | 8 ++++++ .../Cases/CPythonCasesManifest.ini | 3 --- Src/Scripts/generate_typecache.py | 1 + 7 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Src/IronPython/Modules/Builtin.cs b/Src/IronPython/Modules/Builtin.cs index 50a65aca7..337aae583 100644 --- a/Src/IronPython/Modules/Builtin.cs +++ b/Src/IronPython/Modules/Builtin.cs @@ -135,7 +135,7 @@ public static string bin(object? number) { public static PythonType bytes => DynamicHelpers.GetPythonTypeFromType(typeof(Bytes)); - public static PythonType bytearray => DynamicHelpers.GetPythonTypeFromType(typeof(ByteArray)); + public static PythonType bytearray => TypeCache.ByteArray; [Documentation("callable(object) -> bool\n\nReturn whether the object is callable (i.e., some kind of function).")] public static bool callable(CodeContext/*!*/ context, object? o) { diff --git a/Src/IronPython/Runtime/ByteArray.cs b/Src/IronPython/Runtime/ByteArray.cs index ef3f6a2a0..38e54bb6a 100644 --- a/Src/IronPython/Runtime/ByteArray.cs +++ b/Src/IronPython/Runtime/ByteArray.cs @@ -9,16 +9,16 @@ using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Text; -using Microsoft.Scripting.Runtime; -using Microsoft.Scripting.Utils; - using IronPython.Runtime.Exceptions; using IronPython.Runtime.Operations; using IronPython.Runtime.Types; +using Microsoft.Scripting; +using Microsoft.Scripting.Runtime; +using Microsoft.Scripting.Utils; + namespace IronPython.Runtime { /// /// bytearray(string, encoding[, errors]) -> bytearray @@ -56,6 +56,12 @@ internal ByteArray(IEnumerable bytes) { _bytes = new ArrayData(bytes); } + [StaticExtensionMethod] + public static object __new__(CodeContext context, [NotNone] PythonType cls, [ParamDictionary, NotNone] IDictionary dict, [NotNone] params object[] args) { + if (cls == TypeCache.ByteArray) return new ByteArray(); + return cls.CreateInstance(context); + } + public void __init__() { lock (this) { _bytes.Clear(); @@ -74,7 +80,7 @@ public void __init__(int source) { } public void __init__([NotNone] IBufferProtocol source) { - if (Converter.TryConvertToIndex(source, out int size, throwNonInt: false)) { + if (Converter.TryConvertToIndex(source, out int size, throwTypeError: false)) { __init__(size); } else { lock (this) { @@ -86,7 +92,7 @@ public void __init__([NotNone] IBufferProtocol source) { } public void __init__(CodeContext context, object? source) { - if (Converter.TryConvertToIndex(source, out int size, throwNonInt: false)) { + if (Converter.TryConvertToIndex(source, out int size, throwTypeError: false)) { __init__(size); } else if (source is IEnumerable en) { lock (this) { @@ -466,8 +472,13 @@ public int find(BigInteger @byte, object? start, object? end) { } } - public static ByteArray fromhex([NotNone] string @string) { - return new ByteArray(IListOfByteOps.FromHex(@string)); + [ClassMethod] + public static object fromhex(CodeContext context, [NotNone] PythonType cls, [NotNone] string @string) { + var hex = IListOfByteOps.FromHex(@string); + if (cls == TypeCache.ByteArray) { + return new ByteArray(hex); + } + return PythonTypeOps.CallParams(context, cls, new Bytes(hex)); } public string hex() => Bytes.ToHex(_bytes.AsByteSpan()); // new in CPython 3.5 diff --git a/Src/IronPython/Runtime/Bytes.cs b/Src/IronPython/Runtime/Bytes.cs index 3da022503..310849da3 100644 --- a/Src/IronPython/Runtime/Bytes.cs +++ b/Src/IronPython/Runtime/Bytes.cs @@ -61,7 +61,7 @@ public static object __new__(CodeContext context, [NotNone] PythonType cls, [Not return source; } else if (TryInvokeBytesOperator(context, source, out Bytes? res)) { return res; - } else if (Converter.TryConvertToIndex(source, out int size, throwNonInt: false)) { + } else if (Converter.TryConvertToIndex(source, out int size, throwTypeError: false)) { if (size < 0) throw PythonOps.ValueError("negative count"); return new Bytes(new byte[size]); } else { @@ -79,7 +79,7 @@ public static object __new__(CodeContext context, [NotNone] PythonType cls, obje return @object; } else if (TryInvokeBytesOperator(context, @object, out Bytes? res)) { return res; - } else if (Converter.TryConvertToIndex(@object, out int size, throwNonInt: false)) { + } else if (Converter.TryConvertToIndex(@object, out int size, throwTypeError: false)) { if (size < 0) throw PythonOps.ValueError("negative count"); return new Bytes(new byte[size]); } else { @@ -367,8 +367,13 @@ public int find(BigInteger @byte, object? start, object? end) { } [ClassMethod] - public static object fromhex(CodeContext context, [NotNone] PythonType cls, [NotNone] string @string) - => __new__(context, cls, IListOfByteOps.FromHex(@string)); + public static object fromhex(CodeContext context, [NotNone] PythonType cls, [NotNone] string @string) { + var hex = IListOfByteOps.FromHex(@string); + if (cls == TypeCache.Bytes) { + return new Bytes(hex); + } + return PythonTypeOps.CallParams(context, cls, new Bytes(hex)); + } public string hex() => ToHex(_bytes.AsSpan()); // new in CPython 3.5 @@ -1181,6 +1186,13 @@ public bool __eq__(CodeContext context, [NotNone] string value) { public bool __eq__(CodeContext context, [NotNone] Extensible value) => __eq__(context, value.Value); + public bool __eq__(CodeContext context, [NotNone] int value) { + if (context.LanguageContext.PythonOptions.BytesWarning != Microsoft.Scripting.Severity.Ignore) { + PythonOps.Warn(context, PythonExceptions.BytesWarning, "Comparison between bytes and int"); + } + return false; + } + [return: MaybeNotImplemented] public NotImplementedType __eq__(CodeContext context, object? value) => NotImplementedType.Value; @@ -1190,6 +1202,8 @@ public bool __eq__(CodeContext context, [NotNone] string value) { public bool __ne__(CodeContext context, [NotNone] Extensible value) => !__eq__(context, value); + public bool __ne__(CodeContext context, [NotNone] int value) => !__eq__(context, value); + [return: MaybeNotImplemented] public NotImplementedType __ne__(CodeContext context, object? value) => NotImplementedType.Value; diff --git a/Src/IronPython/Runtime/Converter.cs b/Src/IronPython/Runtime/Converter.cs index fd414e5e5..992b0ea83 100644 --- a/Src/IronPython/Runtime/Converter.cs +++ b/Src/IronPython/Runtime/Converter.cs @@ -335,28 +335,34 @@ public static IEnumerable ConvertToIEnumerable(object o) { /// If throwOverflowError is true then BigInteger's outside the normal range of integers will /// result in an OverflowError. /// - /// When throwNonInt is true, a TypeError will be thrown if __index__ returned a non-int. + /// When throwTypeError is true, a TypeError will be thrown if __index__ throw a TypeError or + /// returned a non-int. /// - internal static bool TryConvertToIndex(object? value, out int index, bool throwOverflowError = true, bool throwNonInt = true) { + internal static bool TryConvertToIndex(object? value, out int index, bool throwOverflowError = true, bool throwTypeError = true) { if (TryGetInt(value, out index, throwOverflowError, value)) { return true; } - if (PythonTypeOps.TryInvokeUnaryOperator(DefaultContext.Default, value, "__index__", out object indexObj)) { - if (TryGetInt(indexObj, out index, throwOverflowError, value)) { - return true; - } + if (throwTypeError) { + if (PythonTypeOps.TryInvokeUnaryOperator(DefaultContext.Default, value, "__index__", out object indexObj)) { + if (TryGetInt(indexObj, out index, throwOverflowError, value)) { + return true; + } - if (throwNonInt) { throw PythonOps.TypeError("__index__ returned non-int (type {0})", PythonOps.GetPythonTypeName(indexObj)); } + } else { + try { + return PythonTypeOps.TryInvokeUnaryOperator(DefaultContext.Default, value, "__index__", out object indexObj) && + TryGetInt(indexObj, out index, throwOverflowError, value); + } catch (Exceptions.TypeErrorException) { } } return false; } public static int ConvertToIndex(object? value, bool throwOverflowError = false) { - if (TryConvertToIndex(value, out int index, throwOverflowError: throwOverflowError, throwNonInt: true)) + if (TryConvertToIndex(value, out int index, throwOverflowError: throwOverflowError)) return index; throw PythonOps.TypeError("expected integer value, got {0}", PythonOps.GetPythonTypeName(value)); diff --git a/Src/IronPython/Runtime/Types/TypeCache.Generated.cs b/Src/IronPython/Runtime/Types/TypeCache.Generated.cs index 31185b5e0..a1c36d561 100644 --- a/Src/IronPython/Runtime/Types/TypeCache.Generated.cs +++ b/Src/IronPython/Runtime/Types/TypeCache.Generated.cs @@ -29,6 +29,7 @@ public static class TypeCache { private static PythonType pythontype; private static PythonType str; private static PythonType bytes; + private static PythonType bytearray; private static PythonType pythontuple; private static PythonType weakreference; private static PythonType pythonlist; @@ -131,6 +132,13 @@ public static PythonType Bytes { } } + public static PythonType ByteArray { + get { + if (bytearray == null) bytearray = DynamicHelpers.GetPythonTypeFromType(typeof(ByteArray)); + return bytearray; + } + } + public static PythonType PythonTuple { get { if (pythontuple == null) pythontuple = DynamicHelpers.GetPythonTypeFromType(typeof(PythonTuple)); diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index bdd103055..ce857e9f9 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1176,9 +1176,6 @@ Ignore=true # blocking [CPython.test_base64] Ignore=true # https://github.com/IronLanguages/ironpython3/issues/1135 -[CPython.test_bytes] -Ignore=true # 5 failures - [CPython.test_call] Ignore=true # test_kwargs_order diff --git a/Src/Scripts/generate_typecache.py b/Src/Scripts/generate_typecache.py index 7a9a3ae47..32eca2a36 100644 --- a/Src/Scripts/generate_typecache.py +++ b/Src/Scripts/generate_typecache.py @@ -45,6 +45,7 @@ def __init__(self, type, name=None, typeType='PythonType', entryName=None): TypeData('PythonType'), TypeData('String', 'str'), TypeData('Bytes'), + TypeData('ByteArray'), TypeData('PythonTuple'), TypeData('WeakReference'), TypeData('PythonList'), From 3dad2af118d788e4d71cc17e196767b32e3d5070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 14 May 2022 15:42:25 -0400 Subject: [PATCH 13/17] Re-enable test_long_stdlib --- Src/IronPython/Runtime/Operations/BigIntegerOps.cs | 5 ++--- Src/IronPythonTest/Cases/IronPythonCasesManifest.ini | 3 --- Tests/test_long_stdlib.py | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Src/IronPython/Runtime/Operations/BigIntegerOps.cs b/Src/IronPython/Runtime/Operations/BigIntegerOps.cs index 0884c8ca7..696fb2253 100644 --- a/Src/IronPython/Runtime/Operations/BigIntegerOps.cs +++ b/Src/IronPython/Runtime/Operations/BigIntegerOps.cs @@ -924,10 +924,9 @@ public static object from_bytes(CodeContext context, PythonType type, object? by var val = new BigInteger(bytesArr); #endif - // prevents a TypeError: int.__new__(bool) is not safe - if (type == TypeCache.Boolean) return val == 0 ? ScriptingRuntimeHelpers.False : ScriptingRuntimeHelpers.True; + if (type == TypeCache.BigInteger) return val; - return __new__(context, type, val); + return PythonTypeOps.CallParams(context, type, val); } #endregion diff --git a/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini b/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini index faea25131..8cffe82d2 100644 --- a/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini @@ -209,9 +209,6 @@ Ignore=true # 1 failure [IronPython.test_itertools_stdlib] Ignore=true # 4 failures -[IronPython.test_long_stdlib] -Ignore=true # 2 failures - [IronPython.test_re_stdlib] Ignore=true # AssertionError: SRE module mismatch diff --git a/Tests/test_long_stdlib.py b/Tests/test_long_stdlib.py index c86afd04b..e2c6d5639 100644 --- a/Tests/test_long_stdlib.py +++ b/Tests/test_long_stdlib.py @@ -16,7 +16,7 @@ def load_tests(loader, standard_tests, pattern): if sys.implementation.name == 'ironpython': suite = unittest.TestSuite() - suite.addTest(test.test_long.LongTest('test__format__')) + suite.addTest(unittest.expectedFailure(test.test_long.LongTest('test__format__'))) # https://github.com/IronLanguages/ironpython3/issues/105 suite.addTest(test.test_long.LongTest('test_access_to_nonexistent_digit_0')) suite.addTest(test.test_long.LongTest('test_bit_length')) suite.addTest(test.test_long.LongTest('test_bitop_identities')) From 6be50e375c5c56ec41c38ab995c4bd228e2bf4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 14 May 2022 15:42:44 -0400 Subject: [PATCH 14/17] Re-enable test_complex_stdlib --- .../Cases/CPythonCasesManifest.ini | 16 +++++++--------- .../Cases/IronPythonCasesManifest.ini | 3 --- Tests/test_complex_stdlib.py | 4 ++-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index ce857e9f9..6d996c7ef 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -13,6 +13,9 @@ Ignore=true [CPython.ctypes.test_bitfields] # IronPython.modules.type_related.test_bitfields_ctypes_stdlib Ignore=true +[CPython.ctypes.test_cast] +RunCondition=NOT $(IS_POSIX) # https://github.com/IronLanguages/ironpython3/issues/1455 + [CPython.ctypes.test_errno] Ignore=true Reason=Current implementation of get_last_error needs to be debugged @@ -508,6 +511,9 @@ IsolationLevel=PROCESS # use app.config - https://docs.microsoft.com/en-us/dotne RunCondition=$(IS_POSIX) Reason=Only valid for Unix +[CPython.test_gzip] +IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/1440 + [CPython.test_heapq] Ignore=true Reason=TypeError: __next__() takes exactly 1 argument (1 given) # https://github.com/IronLanguages/ironpython3/issues/547 @@ -603,6 +609,7 @@ Reason=ImportError: No module named _lzma [CPython.test_macpath] RunCondition=NOT $(IS_MONO) # https://github.com/IronLanguages/ironpython3/issues/1102 +IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/1440 [CPython.test_mailbox] Ignore=true @@ -1158,9 +1165,6 @@ RunCondition=NOT $(IS_MONO) # TODO: debug [CPython.ctypes.test_bytes] Ignore=true # AssertionError: 'xbd' not found in "" -[CPython.ctypes.test_cast] -RunCondition=NOT $(IS_POSIX) # https://github.com/IronLanguages/ironpython3/issues/1455 - [CPython.ctypes.test_structures] Ignore=true # 2 failures @@ -1203,9 +1207,6 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/98 [CPython.test_grp] Ignore=true # 2 failures -[CPython.test_gzip] -IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/1440 - [CPython.test_hashlib] Ignore=true # AttributeError: 'module' object has no attribute 'shake_128' @@ -1215,9 +1216,6 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/105 [CPython.test_linecache] Ignore=true # two failures -[CPython.test_macpath] -IsolationLevel=PROCESS # https://github.com/IronLanguages/ironpython3/issues/1440 - [CPython.test_math] Ignore=true # precision? diff --git a/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini b/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini index 8cffe82d2..7bd8c54cb 100644 --- a/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini @@ -185,9 +185,6 @@ Ignore=true # multiple failures [IronPython.test_codeccallbacks_stdlib] Ignore=true # multiple failures -[IronPython.test_complex_stdlib] -Ignore=true # 1 failure https://github.com/IronLanguages/ironpython3/issues/105 - [IronPython.test_datetime_stdlib] Ignore=true # multiple failures diff --git a/Tests/test_complex_stdlib.py b/Tests/test_complex_stdlib.py index e35aec0b2..43e698181 100644 --- a/Tests/test_complex_stdlib.py +++ b/Tests/test_complex_stdlib.py @@ -24,7 +24,7 @@ def load_tests(loader, standard_tests, pattern): suite.addTest(test.test_complex.ComplexTest('test_divmod')) suite.addTest(test.test_complex.ComplexTest('test_file')) suite.addTest(test.test_complex.ComplexTest('test_floordiv')) - suite.addTest(unittest.expectedFailure(test.test_complex.ComplexTest('test_format'))) + suite.addTest(unittest.expectedFailure(test.test_complex.ComplexTest('test_format'))) # https://github.com/IronLanguages/ironpython2/issues/102 suite.addTest(test.test_complex.ComplexTest('test_getnewargs')) suite.addTest(test.test_complex.ComplexTest('test_hash')) suite.addTest(test.test_complex.ComplexTest('test_mod')) @@ -39,7 +39,7 @@ def load_tests(loader, standard_tests, pattern): suite.addTest(test.test_complex.ComplexTest('test_richcompare')) suite.addTest(test.test_complex.ComplexTest('test_richcompare_boundaries')) suite.addTest(test.test_complex.ComplexTest('test_truediv')) - suite.addTest(test.test_complex.ComplexTest('test_underscores')) + suite.addTest(unittest.expectedFailure(test.test_complex.ComplexTest('test_underscores'))) # https://github.com/IronLanguages/ironpython3/issues/105 return suite else: From bcb8ac60bd35096d5961d229073454373b170615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 14 May 2022 17:06:21 -0400 Subject: [PATCH 15/17] Re-enable test_unicode_stdlib --- Src/IronPythonTest/Cases/IronPythonCasesManifest.ini | 3 --- Src/StdLib/Lib/test/test_unicode.py | 1 + Tests/test_unicode_stdlib.py | 6 +++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini b/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini index 7bd8c54cb..5c103078c 100644 --- a/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini @@ -232,6 +232,3 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/98 [IronPython.test_unpack] Ignore=true # test_assign_to_empty - -[IronPython.test_unicode_stdlib] -Ignore=true # 3 failures diff --git a/Src/StdLib/Lib/test/test_unicode.py b/Src/StdLib/Lib/test/test_unicode.py index 9dd8e7a90..c5e88e7ea 100644 --- a/Src/StdLib/Lib/test/test_unicode.py +++ b/Src/StdLib/Lib/test/test_unicode.py @@ -2456,6 +2456,7 @@ def test_free_after_iterating(self): class CAPITest(unittest.TestCase): # Test PyUnicode_FromFormat() + @support.cpython_only def test_from_format(self): support.import_module('ctypes') from ctypes import ( diff --git a/Tests/test_unicode_stdlib.py b/Tests/test_unicode_stdlib.py index d150035af..b61dfa1e5 100644 --- a/Tests/test_unicode_stdlib.py +++ b/Tests/test_unicode_stdlib.py @@ -94,13 +94,13 @@ def load_tests(loader, standard_tests, pattern): suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_isprintable'))) suite.addTest(test.test_unicode.UnicodeTest('test_isspace')) suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_issue18183'))) - suite.addTest(test.test_unicode.UnicodeTest('test_issue28598_strsubclass_rhs')) + suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_issue28598_strsubclass_rhs'))) suite.addTest(test.test_unicode.UnicodeTest('test_issue8271')) suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_istitle'))) suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_isupper'))) suite.addTest(test.test_unicode.UnicodeTest('test_iterators')) suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_join'))) - suite.addTest(test.test_unicode.UnicodeTest('test_join_overflow')) + suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_join_overflow'))) # ValueError: capacity was less than the current size. suite.addTest(test.test_unicode.UnicodeTest('test_literals')) suite.addTest(test.test_unicode.UnicodeTest('test_ljust')) suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_lower'))) @@ -122,7 +122,7 @@ def load_tests(loader, standard_tests, pattern): suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_rpartition'))) suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_rsplit'))) suite.addTest(test.test_unicode.UnicodeTest('test_slice')) - suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_split'))) + suite.addTest(unittest.expectedFailure(test.test_unicode.UnicodeTest('test_split'))) # https://github.com/IronLanguages/ironpython3/issues/252 suite.addTest(test.test_unicode.UnicodeTest('test_splitlines')) suite.addTest(test.test_unicode.UnicodeTest('test_startswith')) suite.addTest(test.test_unicode.UnicodeTest('test_startswith_endswith_errors')) From 45f38a57203cae72b6cdf06ff4a27caa0bd735e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 14 May 2022 17:11:06 -0400 Subject: [PATCH 16/17] Re-enable test_unpack --- Src/IronPython/Compiler/Ast/TupleExpression.cs | 7 ------- Src/IronPythonTest/Cases/CPythonCasesManifest.ini | 3 --- .../Cases/IronPythonCasesManifest.ini | 3 --- Tests/test_unpack.py | 13 +++++-------- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/Src/IronPython/Compiler/Ast/TupleExpression.cs b/Src/IronPython/Compiler/Ast/TupleExpression.cs index eeda8c3da..82f34cebf 100644 --- a/Src/IronPython/Compiler/Ast/TupleExpression.cs +++ b/Src/IronPython/Compiler/Ast/TupleExpression.cs @@ -17,17 +17,10 @@ public TupleExpression(bool expandable, params Expression[] items) } internal override string? CheckAssign() { - if (Items.Count == 0) { - // TODO: remove this when we get to 3.6 - return "can't assign to ()"; - } - return base.CheckAssign(); } internal override string? CheckDelete() { - if (Items.Count == 0) - return "can't delete ()"; // TODO: remove this when we get to 3.6 return base.CheckDelete(); } diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index 6d996c7ef..b375bb00d 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -1255,9 +1255,6 @@ Ignore=true # AssertionError: DeprecationWarning not triggered [CPython.test_support] Ignore=true # lots of failures -[CPython.test_unpack] -Ignore=true # 4 failures - [CPython.test_userdict] Ignore=true # StackOverflowException diff --git a/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini b/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini index 5c103078c..43bdb268d 100644 --- a/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/IronPythonCasesManifest.ini @@ -229,6 +229,3 @@ Ignore=true # 3 failures [IronPython.test_types_stdlib] Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/98 - -[IronPython.test_unpack] -Ignore=true # test_assign_to_empty diff --git a/Tests/test_unpack.py b/Tests/test_unpack.py index 8a6a3bda9..f1fc55a3a 100644 --- a/Tests/test_unpack.py +++ b/Tests/test_unpack.py @@ -22,7 +22,7 @@ def test_unpack_into_exprlist_2(self): self.assertEqual(a, [0, 1, 2, 3]) self.assertEqual(b, 4) self.assertEqual(c, 5) - + def test_unpack_into_exprlist_3(self): a, *b, c = range(6) self.assertEqual(a, 0) @@ -46,7 +46,7 @@ def test_unpack_into_exprlist_5(self): self.assertEqual(f, [1, 2, 3]) self.assertEqual(g, 4) self.assertEqual(h, 5) - + def test_unpack_into_list_1(self): [*a] = range(2) self.assertEqual(a, [0, 1]) @@ -75,7 +75,7 @@ def test_unpack_into_for_target_2(self): self.assertEqual(b, index) self.assertEqual(a, [index]) index = index + 1 - + def test_unpack_into_for_target_3(self): index = 0 expected_a = [1, 4] @@ -120,11 +120,8 @@ def test_too_many_expressions_in_star_unpack(self): self.assertRaisesSyntaxError(body, "too many expressions in star-unpacking assignment") def test_assign_to_empty(self): - if sys.version_info >= (3,6): - exec("() = []") # TODO: remove exec once our baseline is >= 3.6 - else: - self.assertRaisesSyntaxError('() = []', "can't assign to ()") - [] = () # OK + () = [] # new in 3.6 + [] = () def test_assign_trailing_comma_list_to_list(self): [a, *b,] = [1, 2, 3] From 11dcd60827fa5b1960998a8a1a90e3f75d66b871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 14 May 2022 19:09:26 -0400 Subject: [PATCH 17/17] Fix test_tuple --- Tests/test_tuple.py | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Tests/test_tuple.py b/Tests/test_tuple.py index 61d73a2b7..30c3f27da 100644 --- a/Tests/test_tuple.py +++ b/Tests/test_tuple.py @@ -9,11 +9,11 @@ class TupleTest(IronPythonTestCase): def test_assign_to_empty(self): - """Disallow assignment to empty tuple""" + """Allow assignment to empty tuple (new in 3.6)""" y = () - self.assertRaises(SyntaxError, compile, "() = y", "Error", "exec") - self.assertRaises(SyntaxError, compile, "(), t = y, 0", "Error", "exec") - self.assertRaises(SyntaxError, compile, "((()))=((y))", "Error", "exec") + () = y + (), t = y, 0 + ((()))=((y)) del y def test_unpack(self): @@ -52,11 +52,11 @@ class mylong(int): pass self.assertEqual((3, 4).__mul__(mylong(2)), (3, 4, 3, 4)) self.assertEqual((5, 6).__rmul__(mylong(2)), (5, 6, 5, 6)) self.assertEqual(mylong(2) * (7,8) , (7, 8, 7, 8)) - + class mylong2(int): def __rmul__(self, other): return 42 - + self.assertEqual((1,2) * mylong2(2), 42) # this one uses __rmul__ self.assertEqual((3, 4).__mul__(mylong2(2)), (3, 4, 3, 4)) self.assertEqual((5, 6).__rmul__(mylong2(2)), (5, 6, 5, 6)) @@ -71,12 +71,12 @@ def __hash__(self): return 42 def __eq__(self, other): return type(self) == type(other) - - + + test = (myhashable(), myhashable(), myhashable()) - + hash(test) - + self.assertEqual(test[0].hashcalls, 1) self.assertEqual(test[1].hashcalls, 1) self.assertEqual(test[2].hashcalls, 1) @@ -94,7 +94,7 @@ def test_tuple_hash_none(self): import clr # Make sure .GetHashCode() is available example = (1, None) expected = 1625286227 - + self.assertEqual(hash(example), expected) self.assertEqual(hash(example), example.GetHashCode()) @@ -103,9 +103,9 @@ def test_tuple_cli_interactions(self): # verify you can call ToString on a tuple after importing clr import clr a = (0,) - + self.assertEqual(str(a), a.ToString()) - + def test_sequence_assign(self): try: @@ -125,7 +125,7 @@ def test_sort(self): def test_indexing(self): t = (2,3,4) self.assertRaises(TypeError, lambda : t[2.0]) - + class mytuple(tuple): def __getitem__(self, index): return tuple.__getitem__(self, int(index)) @@ -145,11 +145,11 @@ def __getitem__(self): for x in T((1,)): self.assertEqual(x, 1) - + def test_mul_subclass(self): class subclass(tuple): pass - + u = subclass([0,1]) self.assertTrue(u is not u*1) @@ -179,7 +179,7 @@ def test_wacky_contains(self): class x(tuple): def __contains__(self, other): return retval - + self.assertEqual('abc' in x(), False) class x2(tuple): @@ -191,10 +191,10 @@ def test_tuple_equality(self): class x(object): def __eq__(self, other): return False def __ne__(self, other): return True - + a = x() self.assertEqual((a, ), (a, )) - + def test_tuple_reuse(self): t = (2,4,6) self.assertEqual(id(t), id(tuple(t))) @@ -206,9 +206,8 @@ def test_index_error(self): x = () def delindex(): del x[42] def setindex(): x[42] = 42 - + self.assertRaisesMessage(TypeError, "'tuple' object doesn't support item deletion", delindex) self.assertRaisesMessage(TypeError, "'tuple' object does not support item assignment", setindex) - -run_test(__name__) \ No newline at end of file +run_test(__name__)