Skip to content

Commit dd03adb

Browse files
authored
Re-enable some tests (#1544)
* Re-enable test_super * Try to re-enable test_spwd * Disable test_spwd on macOS * Increase test_socket_stdlib timeout * Unblock test_selector_events using test from 3.7.13 * Re-enable test_collections * Re-enable ctypes.test_bytes * Re-enable test_math * Re-enable on Mono * Remove _heapq methods * Update test_class_stdlib
1 parent a1011ab commit dd03adb

12 files changed

Lines changed: 348 additions & 348 deletions

File tree

Src/DLR

Src/IronPython.Modules/_ctypes/NativeArgument.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
#if FEATURE_CTYPES
66

7-
using System;
8-
9-
using Microsoft.Scripting.Runtime;
10-
117
using IronPython.Runtime;
128
using IronPython.Runtime.Types;
9+
using IronPython.Runtime.Operations;
1310

1411
namespace IronPython.Modules {
1512
/// <summary>
@@ -35,11 +32,8 @@ public CData _obj {
3532

3633
#region ICodeFormattable Members
3734

38-
public string __repr__(CodeContext context) {
39-
return String.Format("<cparam '{0}' ({1})>",
40-
_type,
41-
IdDispenser.GetId(__obj));// TODO: should be a real address
42-
}
35+
public string __repr__(CodeContext context)
36+
=> $"<cparam '{_type}' ({PythonOps.Repr(context, __obj)})>";
4337

4438
#endregion
4539
}

Src/IronPython.Modules/_heapq.cs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -76,70 +76,6 @@ public static object heapreplace(CodeContext/*!*/ context, PythonList list, obje
7676
}
7777
}
7878

79-
[Documentation("Find the n largest elements in a dataset.\n\n"
80-
+ "Equivalent to: sorted(iterable, reverse=True)[:n]\n"
81-
)]
82-
public static PythonList nlargest(CodeContext/*!*/ context, int n, object iterable) {
83-
if (n <= 0) {
84-
return new PythonList();
85-
}
86-
87-
PythonList ret = new PythonList(Math.Min(n, 4000)); // don't allocate anything too huge
88-
IEnumerator en = PythonOps.GetEnumerator(iterable);
89-
90-
// populate list with first n items
91-
for (int i = 0; i < n; i++) {
92-
if (!en.MoveNext()) {
93-
// fewer than n items; finish up here
94-
HeapSort(context, ret, true);
95-
return ret;
96-
}
97-
ret.append(en.Current);
98-
}
99-
100-
// go through the remainder of the iterator, maintaining a min-heap of the n largest values
101-
DoHeapify(context, ret);
102-
while (en.MoveNext()) {
103-
DoPushPop(context, ret, en.Current);
104-
}
105-
106-
// return the largest items, in descending order
107-
HeapSort(context, ret, true);
108-
return ret;
109-
}
110-
111-
[Documentation("Find the n smallest elements in a dataset.\n\n"
112-
+ "Equivalent to: sorted(iterable)[:n]\n"
113-
)]
114-
public static PythonList nsmallest(CodeContext/*!*/ context, int n, object iterable) {
115-
if (n <= 0) {
116-
return new PythonList();
117-
}
118-
119-
PythonList ret = new PythonList(Math.Min(n, 4000)); // don't allocate anything too huge
120-
IEnumerator en = PythonOps.GetEnumerator(iterable);
121-
122-
// populate list with first n items
123-
for (int i = 0; i < n; i++) {
124-
if (!en.MoveNext()) {
125-
// fewer than n items; finish up here
126-
HeapSort(context, ret);
127-
return ret;
128-
}
129-
ret.append(en.Current);
130-
}
131-
132-
// go through the remainder of the iterator, maintaining a max-heap of the n smallest values
133-
DoHeapifyMax(context, ret);
134-
while (en.MoveNext()) {
135-
DoPushPopMax(context, ret, en.Current);
136-
}
137-
138-
// return the smallest items, in ascending order
139-
HeapSort(context, ret);
140-
return ret;
141-
}
142-
14379
#endregion
14480

14581
#region private implementation details (NOTE: thread-unsafe)

Src/IronPython.Modules/math.cs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,22 @@ public static double expm1(double v0) {
333333
return Check(v0, Math.Tanh(v0 / 2.0) * (Math.Exp(v0) + 1.0));
334334
}
335335

336-
public static double asinh(double v0) {
337-
if (v0 == 0.0 || double.IsInfinity(v0)) {
338-
return v0;
336+
public static double asinh(double x) {
337+
if (x == 0.0 || double.IsInfinity(x)) {
338+
return x;
339339
}
340-
// rewrote ln(v0 + sqrt(v0**2 + 1)) for precision
341-
if (Math.Abs(v0) > 1.0) {
342-
return Math.Sign(v0) * (Math.Log(Math.Abs(v0)) + Math.Log(1.0 + MathUtils.Hypot(1.0, 1.0 / v0)));
340+
341+
#if NETCOREAPP
342+
return Math.Asinh(x);
343+
#else
344+
// rewrote ln(x + sqrt(x**2 + 1)) for precision
345+
if (Math.Abs(x) > 1.0) {
346+
return Math.Sign(x) * (Math.Log(Math.Abs(x)) + Math.Log(1.0 + MathUtils.Hypot(1.0, 1.0 / x)));
343347
} else {
344-
return Math.Log(v0 + MathUtils.Hypot(1.0, v0));
348+
var x2 = x * x;
349+
return log1p(x + x2 / (Math.Sqrt(x2 + 1) + 1));
345350
}
351+
#endif
346352
}
347353

348354
public static double asinh(object value) {
@@ -356,15 +362,25 @@ public static double asinh(object value) {
356362
}
357363
}
358364

359-
public static double acosh(double v0) {
360-
if (v0 < 1.0) {
365+
public static double acosh(double x) {
366+
if (x < 1.0) {
361367
throw PythonOps.ValueError("math domain error");
362-
} else if (double.IsPositiveInfinity(v0)) {
368+
} else if (double.IsPositiveInfinity(x)) {
363369
return double.PositiveInfinity;
364370
}
365-
// rewrote ln(v0 + sqrt(v0**2 - 1)) for precision
366-
double c = Math.Sqrt(v0 + 1.0);
367-
return Math.Log(c) + Math.Log(v0 / c + Math.Sqrt(v0 - 1.0));
371+
372+
#if NETCOREAPP
373+
return Math.Acosh(x);
374+
#else
375+
if (x < 2) {
376+
var c = x - 1;
377+
return log1p(c + Math.Sqrt(c * c + 2 * c));
378+
} else {
379+
// rewrote ln(x + sqrt(x**2 - 1)) for precision
380+
double c = Math.Sqrt(x + 1.0);
381+
return Math.Log(c) + Math.Log(x / c + Math.Sqrt(x - 1.0));
382+
}
383+
#endif
368384
}
369385

370386
public static double acosh(object value) {
@@ -378,15 +394,20 @@ public static double acosh(object value) {
378394
}
379395
}
380396

381-
public static double atanh(double v0) {
382-
if (v0 >= 1.0 || v0 <= -1.0) {
397+
public static double atanh(double x) {
398+
if (x >= 1.0 || x <= -1.0) {
383399
throw PythonOps.ValueError("math domain error");
384-
} else if (v0 == 0.0) {
400+
} else if (x == 0.0) {
385401
// preserve +/-0.0
386-
return v0;
402+
return x;
387403
}
388404

389-
return Math.Log((1.0 + v0) / (1.0 - v0)) * 0.5;
405+
#if NETCOREAPP
406+
return Math.Atanh(x);
407+
#else
408+
return (log1p(x) - log1p(-x)) * 0.5;
409+
#endif
410+
390411
}
391412

392413
public static double atanh(BigInteger value) {

Src/IronPython.Modules/nt.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ public static void closerange(CodeContext/*!*/ context, int fd_low, int fd_high)
379379
}
380380
}
381381

382+
public static object? cpu_count() => null; // TODO: implement me!
383+
382384
private static bool IsValidFd(CodeContext/*!*/ context, int fd) {
383385
PythonContext pythonContext = context.LanguageContext;
384386
if (pythonContext.FileManager.TryGetFileFromId(pythonContext, fd, out PythonIOModule.FileIO _)) {

Src/IronPythonTest/Cases/CPythonCasesManifest.ini

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/122
866866
IsolationLevel=ENGINE # source file in a non-UTF-8 encoding
867867

868868
[CPython.test_spwd] # Module will be removed in 3.13 - https://github.com/IronLanguages/ironpython3/issues/1352
869-
RunCondition=$(IS_POSIX)
869+
RunCondition=$(IS_POSIX) AND NOT $(IS_OSX) # https://github.com/IronLanguages/ironpython3/issues/1545
870870

871871
[CPython.test_sqlite]
872872
Ignore=true
@@ -926,8 +926,8 @@ Reason=ImportError: No module named audioop
926926
Ignore=true
927927
Reason=ImportError: No module named _msi
928928

929-
[CPython.test_super]
930-
Ignore=false # will have to be ignored again in 3.6
929+
[CPython.test_super] # IronPython.test_super_stdlib
930+
Ignore=true
931931

932932
[CPython.test_support] # IronPython.test_support_stdlib
933933
Ignore=true
@@ -1175,18 +1175,12 @@ RunCondition=NOT $(IS_MONO) # TODO: debug
11751175

11761176
# -------------------- The following worked in 3.4 ---------------------------
11771177

1178-
[CPython.ctypes.test_bytes]
1179-
Ignore=true # AssertionError: 'xbd' not found in "<cparam 'c' (43)>"
1180-
11811178
[CPython.ctypes.test_structures]
11821179
Ignore=true # 2 failures
11831180

11841181
[CPython.test_abc]
11851182
Ignore=true # test_works_with_init_subclass - https://github.com/IronLanguages/ironpython3/issues/1448
11861183

1187-
[CPython.test_asyncio.test_selector_events]
1188-
Ignore=true # blocking
1189-
11901184
[CPython.test_base64]
11911185
Ignore=true # https://github.com/IronLanguages/ironpython3/issues/1135
11921186

@@ -1196,9 +1190,6 @@ Ignore=true # test_kwargs_order - https://github.com/IronLanguages/ironpython3/i
11961190
[CPython.test_code_module]
11971191
Ignore=true # test_context_tb
11981192

1199-
[CPython.test_collections]
1200-
Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/98
1201-
12021193
[CPython.test_fileinput]
12031194
Ignore=true # test_errors - https://github.com/IronLanguages/ironpython3/issues/1452
12041195

@@ -1208,9 +1199,6 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/105
12081199
[CPython.test_linecache]
12091200
Ignore=true # two failures
12101201

1211-
[CPython.test_math]
1212-
Ignore=true # precision?
1213-
12141202
[CPython.test_opcodes]
12151203
Ignore=true # __annotations__
12161204

@@ -1220,8 +1208,5 @@ Ignore=true # multiple failures
12201208
[CPython.test_regrtest]
12211209
Ignore=true # lots of failures
12221210

1223-
[CPython.test_spwd]
1224-
Ignore=true # fails on macOS
1225-
12261211
[CPython.test_userlist]
12271212
Ignore=true # test_free_after_iterating

Src/IronPythonTest/Cases/IronPythonCasesManifest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ IsolationLevel=PROCESS # Also weakref failures; https://github.com/IronLanguages
103103

104104
[IronPython.test_socket_stdlib]
105105
RunCondition=NOT $(IS_MONO) # TODO: figure out
106+
Timeout=300000 # 5 minute timeout - sometimes slow
106107

107108
[IronPython.test_sqlite3_stdlib]
108109
IsolationLevel=PROCESS

Src/StdLib/Lib/test/test_asyncio/test_selector_events.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,17 @@ def test_sock_connect_timeout(self):
407407
def test_sock_connect_resolve_using_socket_params(self, m_gai):
408408
addr = ('need-resolution.com', 8080)
409409
sock = test_utils.mock_nonblocking_socket()
410-
m_gai.side_effect = (None, None, None, None, ('127.0.0.1', 0))
411-
m_gai._is_coroutine = False
410+
411+
m_gai.side_effect = \
412+
lambda *args: [(None, None, None, None, ('127.0.0.1', 0))]
413+
412414
con = self.loop.create_task(self.loop.sock_connect(sock, addr))
413-
while not m_gai.called:
414-
self.loop._run_once()
415+
self.loop.run_until_complete(con)
415416
m_gai.assert_called_with(
416417
addr[0], addr[1], sock.family, sock.type, sock.proto, 0)
417418

418-
con.cancel()
419-
with self.assertRaises(asyncio.CancelledError):
420-
self.loop.run_until_complete(con)
419+
self.loop.run_until_complete(con)
420+
sock.connect.assert_called_with(('127.0.0.1', 0))
421421

422422
def test__sock_connect(self):
423423
f = asyncio.Future(loop=self.loop)

0 commit comments

Comments
 (0)