Skip to content

Commit dd24a8b

Browse files
authored
Re-enable some tests (#1525)
* Re-enable test_global * Re-enable test_grp * Re-enable test_uuid
1 parent bcd87cb commit dd24a8b

5 files changed

Lines changed: 58 additions & 31 deletions

File tree

Src/IronPython.Modules/_codecs.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ public static PythonTuple mbcs_encode(CodeContext/*!*/ context, [NotNone] string
227227

228228
#endregion
229229

230+
#region OEM Functions
231+
232+
[SupportedOSPlatform("windows"), PythonHidden(PlatformsAttribute.PlatformFamily.Unix)]
233+
public static PythonTuple oem_decode(CodeContext/*!*/ context, [NotNone] IBufferProtocol input, string? errors = null, bool final = false) {
234+
using IPythonBuffer buffer = input.GetBuffer();
235+
return DoDecode(context, "oem", StringOps.CodecsInfo.OemEncoding, buffer, errors).ToPythonTuple();
236+
}
237+
238+
[SupportedOSPlatform("windows"), PythonHidden(PlatformsAttribute.PlatformFamily.Unix)]
239+
public static PythonTuple oem_encode(CodeContext/*!*/ context, [NotNone] string input, string? errors = null)
240+
=> DoEncode(context, "oem", StringOps.CodecsInfo.OemEncoding, input, errors).ToPythonTuple();
241+
242+
#endregion
243+
230244
#region Code Page Functions
231245

232246
[SupportedOSPlatform("windows"), PythonHidden(PlatformsAttribute.PlatformFamily.Unix)]

Src/IronPython.Modules/grp.cs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66

77
using System;
88
using System.Collections.Generic;
9+
using System.Numerics;
910
using System.Runtime.InteropServices;
1011

1112
using Microsoft.Scripting.Runtime;
1213

1314
using IronPython.Runtime;
1415
using IronPython.Runtime.Operations;
15-
16-
using System.Numerics;
16+
using IronPython.Runtime.Exceptions;
17+
using IronPython.Runtime.Types;
1718

1819
[assembly: PythonModule("grp", typeof(IronPython.Modules.PythonGrp), PlatformsAttribute.PlatformFamily.Unix)]
1920
namespace IronPython.Modules {
20-
21+
2122
public static class PythonGrp {
2223
public const string __doc__ = @"Access to the Unix group database.
2324
@@ -79,13 +80,10 @@ private static struct_group Make(IntPtr pwd) {
7980
return new struct_group(g.gr_name, g.gr_passwd, g.gr_gid, new PythonList(MarshalStringArray(g.gr_mem)));
8081
}
8182

82-
private static IEnumerable<string> MarshalStringArray(IntPtr arrayPtr)
83-
{
84-
if (arrayPtr != IntPtr.Zero)
85-
{
83+
private static IEnumerable<string> MarshalStringArray(IntPtr arrayPtr) {
84+
if (arrayPtr != IntPtr.Zero) {
8685
IntPtr ptr = Marshal.ReadIntPtr(arrayPtr);
87-
while (ptr != IntPtr.Zero)
88-
{
86+
while (ptr != IntPtr.Zero) {
8987
string key = Marshal.PtrToStringAnsi(ptr);
9088
yield return key;
9189
arrayPtr = new IntPtr(arrayPtr.ToInt64() + IntPtr.Size);
@@ -96,16 +94,27 @@ private static IEnumerable<string> MarshalStringArray(IntPtr arrayPtr)
9694

9795
public static struct_group getgrgid(int gid) {
9896
var grp = _getgrgid(gid);
99-
if(grp == IntPtr.Zero) {
97+
if (grp == IntPtr.Zero) {
10098
throw PythonOps.KeyError($"getgrgid(): gid not found: {gid}");
10199
}
102100

103101
return Make(grp);
104102
}
105103

104+
public static struct_group getgrgid(CodeContext context, object gid) {
105+
var g = BigIntegerOps.__new__(context, TypeCache.BigInteger, gid);
106+
PythonOps.Warn(context, PythonExceptions.DeprecationWarning, $"group id must be int, not {PythonOps.GetPythonTypeName(gid)}");
107+
return g switch {
108+
int i => getgrgid(i),
109+
BigInteger bi => getgrgid((int)bi),
110+
_ => throw new InvalidOperationException(),
111+
};
112+
}
113+
106114
public static struct_group getgrnam(string name) {
115+
if (name is not null && name.IndexOf((char)0) != -1) throw PythonOps.ValueError("embedded null byte");
107116
var grp = _getgrnam(name);
108-
if(grp == IntPtr.Zero) {
117+
if (grp == IntPtr.Zero) {
109118
throw PythonOps.KeyError($"getgrnam()): name not found: {name}");
110119
}
111120

@@ -116,31 +125,32 @@ public static PythonList getgrall() {
116125
var res = new PythonList();
117126
setgrent();
118127
IntPtr val = getgrent();
119-
while(val != IntPtr.Zero) {
128+
while (val != IntPtr.Zero) {
120129
res.Add(Make(val));
121130
val = getgrent();
122131
}
123-
132+
124133
return res;
125134
}
126135

127136

128137
#region P/Invoke Declarations
129138

130-
[DllImport("libc", EntryPoint="getgrgid", CallingConvention=CallingConvention.Cdecl)]
139+
[DllImport("libc", EntryPoint = "getgrgid", CallingConvention = CallingConvention.Cdecl)]
131140
private static extern IntPtr _getgrgid(int uid);
132141

133-
[DllImport("libc", EntryPoint="getgrnam", CallingConvention=CallingConvention.Cdecl)]
142+
[DllImport("libc", EntryPoint = "getgrnam", CallingConvention = CallingConvention.Cdecl)]
134143
private static extern IntPtr _getgrnam([MarshalAs(UnmanagedType.LPStr)] string name);
135144

136-
[DllImport("libc", CallingConvention=CallingConvention.Cdecl)]
145+
[DllImport("libc", CallingConvention = CallingConvention.Cdecl)]
137146
private static extern void setgrent();
138147

139-
[DllImport("libc", CallingConvention=CallingConvention.Cdecl)]
148+
[DllImport("libc", CallingConvention = CallingConvention.Cdecl)]
140149
private static extern IntPtr getgrent();
141150

142151
#endregion
143152

144153
}
145154
}
155+
146156
#endif

Src/IronPython/Runtime/Operations/StringOps.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,17 +1991,28 @@ private static string UserDecode(CodeContext context, PythonTuple codecInfo, obj
19911991

19921992
internal static partial class CodecsInfo {
19931993
internal static readonly Encoding MbcsEncoding;
1994+
internal static readonly Encoding OemEncoding;
19941995
internal static readonly Encoding RawUnicodeEscapeEncoding = new UnicodeEscapeEncoding(raw: true);
19951996
internal static readonly Encoding UnicodeEscapeEncoding = new UnicodeEscapeEncoding(raw: false);
19961997
internal static readonly IDictionary<string, Lazy<Encoding?>> Codecs;
19971998

1999+
[DllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
2000+
private static extern int GetOEMCP();
2001+
19982002
static CodecsInfo() {
19992003
#if NETCOREAPP || NETSTANDARD
20002004
// This ensures that Encoding.GetEncoding(0) will return the default Windows ANSI code page
20012005
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
20022006
#endif
2003-
// Use Encoding.GetEncoding(0) instead of Encoding.Default (which returns UTF-8 with .NET Core)
2004-
MbcsEncoding = Encoding.GetEncoding(0);
2007+
2008+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
2009+
// Use Encoding.GetEncoding(0) instead of Encoding.Default (which returns UTF-8 with .NET Core)
2010+
MbcsEncoding = Encoding.GetEncoding(0);
2011+
OemEncoding = Encoding.GetEncoding(GetOEMCP());
2012+
} else {
2013+
MbcsEncoding = null!;
2014+
OemEncoding = null!;
2015+
}
20052016
Codecs = MakeCodecsDict();
20062017
}
20072018

@@ -2030,6 +2041,7 @@ static CodecsInfo() {
20302041

20312042
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
20322043
d["mbcs"] = makeEncodingProxy(() => MbcsEncoding);
2044+
d["oem"] = makeEncodingProxy(() => OemEncoding);
20332045
}
20342046

20352047
// TODO: revisit the exceptions to rules below once _codecs_cn, _codecs_hk, _codecs_jp, and _codecs_kr are implemented

Src/IronPythonTest/Cases/CPythonCasesManifest.ini

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,12 +1200,6 @@ Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/98
12001200
[CPython.test_fileinput]
12011201
Ignore=true # test_errors - https://github.com/IronLanguages/ironpython3/issues/1452
12021202

1203-
[CPython.test_global]
1204-
Ignore=true # AssertionError: 5 != 4
1205-
1206-
[CPython.test_grp]
1207-
Ignore=true # 2 failures
1208-
12091203
[CPython.test_int]
12101204
Ignore=true # blocked by https://github.com/IronLanguages/ironpython3/issues/105
12111205

@@ -1241,6 +1235,3 @@ Ignore=true # lots of failures
12411235

12421236
[CPython.test_userlist]
12431237
Ignore=true # test_free_after_iterating
1244-
1245-
[CPython.test_uuid]
1246-
Ignore=true # LookupError: unknown encoding: oem - https://github.com/IronLanguages/ironpython3/issues/1451

Src/StdLib/Lib/test/test_global.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ def wrong1():
2424
global a
2525
global b
2626
"""
27-
check_syntax_error(self, prog_text_1, lineno=4, offset=4)
27+
check_syntax_error(self, prog_text_1, lineno=4, offset=5)
2828

2929
def test2(self):
3030
prog_text_2 = """\
3131
def wrong2():
3232
print(x)
3333
global x
3434
"""
35-
check_syntax_error(self, prog_text_2, lineno=3, offset=4)
35+
check_syntax_error(self, prog_text_2, lineno=3, offset=5)
3636

3737
def test3(self):
3838
prog_text_3 = """\
@@ -41,7 +41,7 @@ def wrong3():
4141
x = 2
4242
global x
4343
"""
44-
check_syntax_error(self, prog_text_3, lineno=4, offset=4)
44+
check_syntax_error(self, prog_text_3, lineno=4, offset=5)
4545

4646
def test4(self):
4747
prog_text_4 = """\

0 commit comments

Comments
 (0)