Skip to content

Commit 26767ee

Browse files
authored
Re-enable some tests (#1457)
* Re-enable test_itertools_stdlib * Re-enable test_sys_stdlib * Re-enable test_codecs_stdlib * Re-enable test_dict_stdlib * Re-enable test_httplib_stdlib * Re-enable test_float_stdlib * Re-enable test_struct_stdlib * Re-enable test_datetime_stdlib * Re-enable test_strptime_stdlib * Re-enable test_functools_stdlib * Fix failing tests * Disable failing tests
1 parent 2ea430f commit 26767ee

18 files changed

Lines changed: 248 additions & 185 deletions

Src/IronPython.Modules/IterTools.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,23 @@ public PythonTuple __reduce__() {
168168
}
169169

170170
public void __setstate__(PythonTuple state) {
171-
// TODO: error handling?
172-
ie = state[0] as IEnumerator;
173-
inner = (state.Count > 1) ? state[1] as IEnumerator : null;
171+
IEnumerator iter;
172+
IEnumerator innerIter;
173+
switch (state.Count) {
174+
case 0: throw PythonOps.TypeError("function takes at least 1 argument (0 given)");
175+
case 1:
176+
iter = state[0] as IEnumerator ?? throw PythonOps.TypeError("Arguments must be iterators.");
177+
innerIter = null;
178+
break;
179+
case 2:
180+
iter = state[0] as IEnumerator ?? throw PythonOps.TypeError("Arguments must be iterators.");
181+
innerIter = state[1] as IEnumerator ?? throw PythonOps.TypeError("Arguments must be iterators.");
182+
break;
183+
default:
184+
throw PythonOps.TypeError("function takes at most 2 argument ({0} given)", state.Count);
185+
}
186+
ie = iter;
187+
inner = innerIter;
174188
InnerEnumerator = LazyYielder();
175189
}
176190

@@ -515,11 +529,14 @@ public void __setstate__(object state) {
515529
private IEnumerator<object> Yielder(IEnumerator iter) {
516530
object curKey = _starterKey;
517531
if (MoveNextHelper(iter)) {
532+
curKey = GetKey(iter.Current);
533+
yield return PythonTuple.MakeTuple(curKey, Grouper(iter, curKey));
534+
518535
while (!_fFinished) {
519536
while (PythonContext.Equal(GetKey(iter.Current), curKey)) {
520-
if (!MoveNextHelper(iter)) {
521-
_fFinished = true;
522-
yield break;
537+
if (!MoveNextHelper(iter)) {
538+
_fFinished = true;
539+
yield break;
523540
}
524541
}
525542
curKey = GetKey(iter.Current);

Src/IronPython.Modules/_datetime.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,15 +1301,6 @@ public PythonTuple __reduce__() {
13011301
);
13021302
}
13031303

1304-
// TODO: get rid of __bool__ in 3.5
1305-
public bool __bool__() {
1306-
return this.UtcTime.TimeSpan.Ticks != 0 || this.UtcTime.LostMicroseconds != 0;
1307-
}
1308-
1309-
public static explicit operator bool(time time) {
1310-
return time.__bool__();
1311-
}
1312-
13131304
// instance methods
13141305
public object replace() {
13151306
return this;

Src/IronPython.Modules/_socket.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,19 @@ public void __init__(CodeContext/*!*/ context, int family = DefaultAddressFamily
135135
throw MakeException(context, new SocketException((int)SocketError.ProtocolNotSupported));
136136
}
137137

138-
Socket? socket;
138+
Socket? socket = null;
139139
if (fileno is socket sock) {
140140
socket = sock._socket;
141141
_hostName = sock._hostName;
142142
// we now own the lifetime of the socket
143143
GC.SuppressFinalize(sock);
144-
} else if (fileno != null && (socket = HandleToSocket((long)fileno)) != null) {
145-
// nothing to do here
144+
} else if (fileno != null) {
145+
if (Converter.TryConvertToInt64(fileno, out long l)) {
146+
socket = HandleToSocket(l);
147+
}
148+
if (socket is null) {
149+
throw PythonOps.OSError("Bad file descriptor");
150+
}
146151
} else {
147152
try {
148153
socket = new Socket(addressFamily, socketType, protocolType);

Src/IronPython.Modules/_struct.cs

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Struct(params object[] args) {
6060
}
6161

6262
[Documentation("creates a new uninitialized struct object - all arguments are ignored")]
63-
public Struct([ParamDictionary]IDictionary<object, object> kwArgs, params object[] args) {
63+
public Struct([ParamDictionary] IDictionary<object, object> kwArgs, params object[] args) {
6464
}
6565

6666
[Documentation("initializes or re-initializes the compiled struct object with a new format")]
@@ -191,9 +191,22 @@ public void __init__(CodeContext/*!*/ context, object fmt) {
191191
break;
192192
case FormatType.Float:
193193
for (int j = 0; j < curFormat.Count; j++) {
194-
WriteFloat(res, _isLittleEndian, (float)GetDoubleValue(context, curObj++, values));
194+
var d = GetDoubleValue(context, curObj++, values);
195+
var val = (float)d;
196+
if (float.IsInfinity(val) && !double.IsInfinity(d)) throw PythonOps.OverflowError("float too large to pack with f format");
197+
WriteFloat(res, _isLittleEndian, val);
195198
}
196199
break;
200+
#if NET6_0_OR_GREATER
201+
case FormatType.Half:
202+
for (int j = 0; j < curFormat.Count; j++) {
203+
var d = GetDoubleValue(context, curObj++, values);
204+
var val = (Half)d;
205+
if (Half.IsInfinity(val) && !double.IsInfinity(d)) throw PythonOps.OverflowError("float too large to pack with e format");
206+
WriteHalf(res, _isLittleEndian, val);
207+
}
208+
break;
209+
#endif
197210
case FormatType.CString:
198211
WriteString(res, curFormat.Count, GetStringValue(context, curObj++, values));
199212
break;
@@ -274,7 +287,7 @@ public void pack_into(CodeContext/*!*/ context, [NotNone] ByteArray/*!*/ buffer,
274287
break;
275288
case FormatType.SignedChar:
276289
for (int j = 0; j < curFormat.Count; j++) {
277-
res[res_idx++] = (int)(sbyte)CreateCharValue(context, ref curIndex, data);
290+
res[res_idx++] = (int)unchecked((sbyte)CreateCharValue(context, ref curIndex, data));
278291
}
279292
break;
280293
case FormatType.UnsignedChar:
@@ -337,7 +350,7 @@ public void pack_into(CodeContext/*!*/ context, [NotNone] ByteArray/*!*/ buffer,
337350
break;
338351
case FormatType.SizeT:
339352
for (int j = 0; j < curFormat.Count; j++) {
340-
res[res_idx++] = CreateUIntValue(context, ref curIndex, _isLittleEndian, data);
353+
res[res_idx++] = BigIntegerOps.__int__(CreateUIntValue(context, ref curIndex, _isLittleEndian, data));
341354
}
342355
break;
343356
case FormatType.LongLong:
@@ -350,9 +363,16 @@ public void pack_into(CodeContext/*!*/ context, [NotNone] ByteArray/*!*/ buffer,
350363
res[res_idx++] = BigIntegerOps.__int__(CreateULongValue(context, ref curIndex, _isLittleEndian, data));
351364
}
352365
break;
366+
#if NET6_0_OR_GREATER
367+
case FormatType.Half:
368+
for (int j = 0; j < curFormat.Count; j++) {
369+
res[res_idx++] = (double)CreateHalfValue(context, ref curIndex, _isLittleEndian, data);
370+
}
371+
break;
372+
#endif
353373
case FormatType.Float:
354374
for (int j = 0; j < curFormat.Count; j++) {
355-
res[res_idx++] = CreateFloatValue(context, ref curIndex, _isLittleEndian, data);
375+
res[res_idx++] = (double)CreateFloatValue(context, ref curIndex, _isLittleEndian, data);
356376
}
357377
break;
358378
case FormatType.Double:
@@ -487,6 +507,12 @@ private static Struct CompileAndCache(CodeContext/*!*/ context, string/*!*/ fmt)
487507
res.Add(new Format(FormatType.UnsignedLongLong, count));
488508
count = 1;
489509
break;
510+
#if NET6_0_OR_GREATER
511+
case 'e': // half
512+
res.Add(new Format(FormatType.Half, count));
513+
count = 1;
514+
break;
515+
#endif
490516
case 'f': // float
491517
res.Add(new Format(FormatType.Float, count));
492518
count = 1;
@@ -725,6 +751,9 @@ private enum FormatType {
725751

726752
Short,
727753
UnsignedShort,
754+
#if NET6_0_OR_GREATER
755+
Half,
756+
#endif
728757

729758
Int,
730759
UnsignedInt,
@@ -758,6 +787,9 @@ private static int GetNativeSize(FormatType c) {
758787
return 1;
759788
case FormatType.Short:
760789
case FormatType.UnsignedShort:
790+
#if NET6_0_OR_GREATER
791+
case FormatType.Half:
792+
#endif
761793
return 2;
762794
case FormatType.Int:
763795
case FormatType.UnsignedInt:
@@ -953,6 +985,18 @@ private static void WriteSignedNetPointer(this MemoryStream res, bool fLittleEnd
953985
res.WritePointer(fLittleEndian, unchecked((ulong)val.ToInt64()));
954986
}
955987

988+
#if NET6_0_OR_GREATER
989+
private static void WriteHalf(this MemoryStream res, bool fLittleEndian, Half val) {
990+
byte[] bytes = BitConverter.GetBytes(val);
991+
if (BitConverter.IsLittleEndian == fLittleEndian) {
992+
res.Write(bytes, 0, bytes.Length);
993+
} else {
994+
res.WriteByte(bytes[1]);
995+
res.WriteByte(bytes[0]);
996+
}
997+
}
998+
#endif
999+
9561000
private static void WriteFloat(this MemoryStream res, bool fLittleEndian, float val) {
9571001
byte[] bytes = BitConverter.GetBytes(val);
9581002
if (BitConverter.IsLittleEndian == fLittleEndian) {
@@ -1176,7 +1220,7 @@ internal static ulong GetULongLongValue(CodeContext/*!*/ context, int index, obj
11761220
internal static double GetDoubleValue(CodeContext/*!*/ context, int index, object[] args) {
11771221
object val = GetValue(context, index, args);
11781222
if (Converter.TryConvertToDouble(val, out double res)) return res;
1179-
throw Error(context, "expected double value");
1223+
throw Error(context, "required argument is not a float");
11801224
}
11811225

11821226
internal static IList<byte> GetStringValue(CodeContext/*!*/ context, int index, object[] args) {
@@ -1236,6 +1280,28 @@ internal static ushort CreateUShortValue(CodeContext/*!*/ context, ref int index
12361280
}
12371281
}
12381282

1283+
#if NET6_0_OR_GREATER
1284+
internal static Half CreateHalfValue(CodeContext/*!*/ context, ref int index, bool fLittleEndian, IList<byte> data) {
1285+
byte[] bytes = new byte[2];
1286+
if (fLittleEndian) {
1287+
bytes[0] = (byte)ReadData(context, ref index, data);
1288+
bytes[1] = (byte)ReadData(context, ref index, data);
1289+
} else {
1290+
bytes[1] = (byte)ReadData(context, ref index, data);
1291+
bytes[0] = (byte)ReadData(context, ref index, data);
1292+
}
1293+
Half res = BitConverter.ToHalf(bytes, 0);
1294+
1295+
if (context.LanguageContext.FloatFormat == FloatFormat.Unknown) {
1296+
if (Half.IsNaN(res) || Half.IsInfinity(res)) {
1297+
throw PythonOps.ValueError("can't unpack IEEE 754 special value on non-IEEE platform");
1298+
}
1299+
}
1300+
1301+
return res;
1302+
}
1303+
#endif
1304+
12391305
internal static float CreateFloatValue(CodeContext/*!*/ context, ref int index, bool fLittleEndian, IList<byte> data) {
12401306
byte[] bytes = new byte[4];
12411307
if (fLittleEndian) {

Src/IronPython.Modules/bz2/dotnetzip/BZip2/BZip2InputStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ private void SetupBlock()
11051105
/* Check: unzftab entries in range. */
11061106
for (i = 0; i <= 255; i++)
11071107
{
1108-
if (s.unzftab[i] < 0 || s.unzftab[i] > this.last)
1108+
if (s.unzftab[i] < 0 || s.unzftab[i] > this.last+1)
11091109
throw new Exception("BZ_DATA_ERROR");
11101110
}
11111111

Src/IronPython/Runtime/DictionaryOps.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ public static class DictionaryOps {
5151
buf.Append(PythonOps.Repr(context, kv.Key));
5252
buf.Append(": ");
5353

54-
buf.Append(PythonOps.Repr(context, kv.Value));
54+
try {
55+
PythonOps.FunctionPushFrame(context.LanguageContext);
56+
buf.Append(PythonOps.Repr(context, kv.Value));
57+
} finally {
58+
PythonOps.FunctionPopFrame();
59+
}
5560
}
5661
buf.Append("}");
5762
return buf.ToString();

Src/IronPython/Runtime/Operations/StringOps.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,14 @@ private class BackslashReplaceFallbackBuffer : EncoderFallbackBuffer {
23672367
private int _index;
23682368

23692369
public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index) {
2370-
return false;
2370+
var val = char.ConvertToUtf32(charUnknownHigh, charUnknownLow);
2371+
_buffer.Add('\\');
2372+
_buffer.Add('U');
2373+
AddCharacter(val >> 24);
2374+
AddCharacter((val >> 16) & 0xFF);
2375+
AddCharacter((val >> 8) & 0xFF);
2376+
AddCharacter(val & 0xFF);
2377+
return true;
23712378
}
23722379

23732380
public override bool Fallback(char charUnknown, int index) {

Src/IronPythonTest/Cases/IronPythonCasesManifest.ini

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ IsolationLevel=PROCESS # requires System.Drawing assembly to be unloaded
1717
[IronPython.test_compiler]
1818
IsolationLevel=PROCESS # TODO: figure out - breaks the sys module in other tests
1919

20+
[IronPython.test_delegate]
21+
RetryCount=2
22+
23+
[IronPython.test_dict_stdlib]
24+
IsolationLevel=ENGINE
25+
MaxRecursion=100
26+
2027
[IronPython.test_dllsite]
2128
Ignore=true
2229
Reason=disabled in IronLanguages/main, needs lots of work
2330

24-
[IronPython.test_delegate]
25-
RetryCount=2
26-
2731
[IronPython.test_doc]
2832
RunCondition=NOT $(IS_OSX) # TODO: figure out
2933
IsolationLevel=PROCESS # required to have quit/exit
@@ -179,33 +183,12 @@ Ignore=true # test_doc
179183
[IronPython.test_builtin_stdlib]
180184
Ignore=true # multiple failures
181185

182-
[IronPython.test_codecs_stdlib]
183-
Ignore=true # multiple failures
184-
185186
[IronPython.test_codeccallbacks_stdlib]
186187
Ignore=true # multiple failures
187188

188-
[IronPython.test_datetime_stdlib]
189-
Ignore=true # multiple failures
190-
191-
[IronPython.test_dict_stdlib]
192-
Ignore=true # blocking
193-
194-
[IronPython.test_float_stdlib]
195-
Ignore=true # 2 failures https://github.com/IronLanguages/ironpython3/issues/105
196-
197-
[IronPython.test_functools_stdlib]
198-
Ignore=true # StackOverflowException
199-
200-
[IronPython.test_httplib_stdlib]
201-
Ignore=true # TypeError: Unable to cast object of type 'System.Int32' to type 'System.Int64'.
202-
203189
[IronPython.test_imp]
204190
Ignore=true # 1 failure
205191

206-
[IronPython.test_itertools_stdlib]
207-
Ignore=true # 4 failures
208-
209192
[IronPython.test_re_stdlib]
210193
Ignore=true # AssertionError: SRE module mismatch
211194

@@ -215,17 +198,8 @@ Ignore=true # multiple failures
215198
[IronPython.test_socket_stdlib]
216199
Ignore=true # blocking
217200

218-
[IronPython.test_strptime_stdlib]
219-
Ignore=true # multiple failures
220-
221-
[IronPython.test_struct_stdlib]
222-
Ignore=true # struct.error: bad char in struct format
223-
224201
[IronPython.test_ssl_stdlib]
225202
Ignore=true # unittest.case.SkipTest: Cannot import name SSLSession
226203

227-
[IronPython.test_sys_stdlib]
228-
Ignore=true # 3 failures
229-
230204
[IronPython.test_types_stdlib]
231205
Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/98

Src/StdLib/Lib/test/test_float.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ def test_float_specials_do_unpack(self):
620620
struct.unpack(fmt, data)
621621

622622
@support.requires_IEEE_754
623+
@support.cpython_only
623624
def test_serialized_float_rounding(self):
624625
from _testcapi import FLT_MAX
625626
self.assertEqual(struct.pack("<f", 3.40282356e38), struct.pack("<f", FLT_MAX))

Tests/modules/misc/test_datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def test_time(self):
985985
#bool
986986
self.assertTrue(datetime.time(0, 0, 0, 1))
987987
#CodePlex Work Item 5139
988-
self.assertTrue(not (datetime.time(0, 0, 0, 0)))
988+
self.assertFalse(not (datetime.time(0, 0, 0, 0))) # __bool__ removed in 3.5
989989

990990
#replace
991991
x = datetime.time(1, 2, 33, 444)

0 commit comments

Comments
 (0)