Visitar URL original
Update NUnit by filmor · Pull Request #2724 · pythonnet/pythonnet · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Drop some obsolete comments and reenable some tests
  • Loading branch information
filmor committed May 12, 2026
commit e73e7c172518c7aa72c9d6660178245e8d442b0e
10 changes: 0 additions & 10 deletions src/embed_tests/Dynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,9 @@ public void AssignNone()
/// Check whether we can get the attr of a python object when the
/// value of attr is a PyObject.
/// </summary>
/// <remarks>
/// FIXME: Issue on Travis PY27: Error : Python.EmbeddingTest.dynamicTest.AssignPyObject
/// Python.Runtime.PythonException : ImportError : /home/travis/virtualenv/python2.7.9/lib/python2.7/lib-dynload/_io.so: undefined symbol: _PyLong_AsInt
/// </remarks>
[Test]
public void AssignPyObject()
{
if (Environment.GetEnvironmentVariable("TRAVIS") == "true" &&
Environment.GetEnvironmentVariable("TRAVIS_PYTHON_VERSION") == "2.7")
{
Assert.Ignore("Fails on Travis/PY27: ImportError: ... undefined symbol: _PyLong_AsInt");
}

dynamic sys = Py.Import("sys");
dynamic io = Py.Import("io");
sys.testattr = io.StringIO();
Expand Down
2 changes: 0 additions & 2 deletions src/embed_tests/TestPyString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void TestEmptyStringCtor()
}

[Test]
[Ignore("Ambiguous behavior between PY2/PY3. Needs remapping")]
public void TestPyObjectCtor()
{
const string expected = "Foo";
Expand Down Expand Up @@ -58,7 +57,6 @@ public void TestCtorBorrowed()
}

[Test]
[Ignore("Ambiguous behavior between PY2/PY3. Needs remapping")]
public void IsStringTrue()
{
var t = new PyString("foo");
Expand Down
2 changes: 0 additions & 2 deletions src/embed_tests/TestPyTuple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ public void TestPyTupleCtorArray()
/// Test has second purpose. Currently it generated an Exception
/// that the GC failed to remove often and caused AppDomain unload
/// errors at the end of tests. See GH#397 for more info.
/// <para />
/// Curious, on PY27 it gets a Unicode on the ex.Message. On PY3+ its string.
/// </remarks>
[Test]
public void TestPyTupleInvalidAppend()
Expand Down
25 changes: 4 additions & 21 deletions src/runtime/Native/CustomMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static ICustomMarshaler GetInstance(string cookie)
return Instance;
}

public static string? PtrToStringUni(IntPtr p)
public static string? PtrToString(IntPtr p)
{
if (p == IntPtr.Zero)
{
Expand Down Expand Up @@ -106,36 +106,19 @@ public static int GetUnicodeByteLength(IntPtr p)
}

/// <summary>
/// Utility function for Marshaling Unicode on PY3 and AnsiStr on PY2.
/// Use on functions whose Input signatures changed between PY2/PY3.
/// Ex. Py_SetPythonHome
/// Utility function for Marshaling Unicode
/// </summary>
/// <param name="s">Managed String</param>
/// <returns>
/// Ptr to Native String ANSI(PY2)/Unicode(PY3/UCS2)/UTF32(PY3/UCS4.
/// Ptr to Native String
/// </returns>
/// <remarks>
/// You MUST deallocate the IntPtr of the Return when done with it.
/// </remarks>
public static IntPtr Py3UnicodePy2StringtoPtr(string s)
public static IntPtr StringToPtr(string s)
{
return Instance.MarshalManagedToNative(s);
}

/// <summary>
/// Utility function for Marshaling Unicode IntPtr on PY3 and
/// AnsiStr IntPtr on PY2 to Managed Strings. Use on Python functions
/// whose return type changed between PY2/PY3.
/// Ex. Py_GetPythonHome
/// </summary>
/// <param name="p">Native Ansi/Unicode/UTF32 String</param>
/// <returns>
/// Managed String
/// </returns>
public static string? PtrToPy3UnicodePy2String(IntPtr p)
{
return PtrToStringUni(p);
}
}


Expand Down
12 changes: 6 additions & 6 deletions src/runtime/PythonEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public static string ProgramName
get
{
IntPtr p = Runtime.TryUsingDll(() => Runtime.Py_GetProgramName());
return UcsMarshaler.PtrToPy3UnicodePy2String(p) ?? "";
return UcsMarshaler.PtrToString(p) ?? "";
}
set
{
Marshal.FreeHGlobal(_programName);
_programName = Runtime.TryUsingDll(
() => UcsMarshaler.Py3UnicodePy2StringtoPtr(value)
() => UcsMarshaler.StringToPtr(value)
);
Runtime.Py_SetProgramName(_programName);
}
Expand All @@ -106,13 +106,13 @@ public static string PythonHome
{
EnsureInitialized();
IntPtr p = Runtime.TryUsingDll(() => Runtime.Py_GetPythonHome());
return UcsMarshaler.PtrToPy3UnicodePy2String(p) ?? "";
return UcsMarshaler.PtrToString(p) ?? "";
}
set
{
// this value is null in the beginning
Marshal.FreeHGlobal(_pythonHome);
_pythonHome = UcsMarshaler.Py3UnicodePy2StringtoPtr(value);
_pythonHome = UcsMarshaler.StringToPtr(value);
Runtime.TryUsingDll(() => Runtime.Py_SetPythonHome(_pythonHome));
}
}
Expand All @@ -122,13 +122,13 @@ public static string PythonPath
get
{
IntPtr p = Runtime.TryUsingDll(() => Runtime.Py_GetPath());
return UcsMarshaler.PtrToPy3UnicodePy2String(p) ?? "";
return UcsMarshaler.PtrToString(p) ?? "";
}
set
{
Marshal.FreeHGlobal(_pythonPath);
_pythonPath = Runtime.TryUsingDll(
() => UcsMarshaler.Py3UnicodePy2StringtoPtr(value)
() => UcsMarshaler.StringToPtr(value)
);
Runtime.Py_SetPath(_pythonPath);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# TODO: move tests one out of src to project root.
# TODO: travis has numpy on their workers. Maybe add tests?

"""Helpers for testing."""

Expand Down
7 changes: 3 additions & 4 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ def test_array_contains():
assert 3 in items
assert 4 in items

assert not (5 in items) # "H:\Python27\Lib\unittest\case.py", line 592, in deprecated_func,
assert not (-1 in items) # TypeError: int() argument must be a string or a number, not 'NoneType'
assert not (None in items) # which threw ^ here which is a little odd.
# But when run from runtests.py. Not when this module ran by itself.
assert not (5 in items)
assert not (-1 in items)
assert not (None in items)


def test_boolean_array():
Expand Down
1 change: 0 additions & 1 deletion tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def test_field_descriptor_abuse():

def test_boolean_field():
"""Test boolean fields."""
# change this to true / false later for Python 2.3?
ob = FieldTest()
assert ob.BooleanField is False

Expand Down
Loading