Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 2 additions & 4 deletions 6 pythonnet/src/monoclr/pynetinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ void main_thread_handler (gpointer user_data) {
for (ii = 0; ii < PyList_Size(syspath); ++ii) {
const char* pydir = PyString_AsString(PyList_GetItem(syspath, ii));
char* curdir = (char*) malloc(1024);
if (strlen(pydir) == 0) pydir = ".";

strcpy(curdir, pydir);
strcat(curdir, slash);
strncpy(curdir, strlen(pydir) > 0 ? pydir : ".", 1024);
strncat(curdir, slash, 1024);

//look in this directory for the pn_args->pr_file
DIR* dirp = opendir(curdir);
Expand Down
4 changes: 3 additions & 1 deletion 4 pythonnet/src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ internal static void Initialize() {

if (0 == Runtime.Py_IsInitialized()) {
Runtime.Py_Initialize();
Runtime.PyEval_InitThreads();
}

// make sure threads are initialized even if python was initialized already
Runtime.PyEval_InitThreads();

IntPtr dict = Runtime.PyImport_GetModuleDict();
IntPtr op = Runtime.PyDict_GetItemString(dict, "__builtin__");

Expand Down
5 changes: 2 additions & 3 deletions 5 pythonnet/src/testing/constructortests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

using System;
using System.Collections;
using System.Windows.Forms;
using System.IO;

namespace Python.Test {
Expand Down Expand Up @@ -53,9 +52,9 @@ public StructConstructorTest(Guid v) {

public class SubclassConstructorTest {

public Control value;
public Exception value;

public SubclassConstructorTest(Control v) {
public SubclassConstructorTest(Exception v) {
this.value = v;
}

Expand Down
10 changes: 10 additions & 0 deletions 10 pythonnet/src/testing/enumtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ public enum ULongEnum : ulong {
Five
}

[FlagsAttribute]
public enum FlagsEnum {
Zero,
One,
Two,
Three,
Four,
Five
}

}
1 change: 1 addition & 0 deletions 1 pythonnet/src/testing/fieldtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void Shutup() {
public decimal DecimalField = 0;
public string StringField;
public ShortEnum EnumField;
public FlagsEnum FlagsField;
public object ObjectField;
public ISpam SpamField;

Expand Down
3 changes: 1 addition & 2 deletions 3 pythonnet/src/testing/methodtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

using System;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic;

namespace Python.Test {
Expand Down Expand Up @@ -71,7 +70,7 @@ public Guid TestStructConversion(Guid v) {
return v;
}

public Control TestSubclassConversion(Control v) {
public Exception TestSubclassConversion(Exception v) {
return v;
}

Expand Down
10 changes: 5 additions & 5 deletions 10 pythonnet/src/tests/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def testStructConstructor(self):
def testSubclassConstructor(self):
"""Test subclass constructor args"""
from Python.Test import SubclassConstructorTest
from System.Windows.Forms import Form, Control

class sub(Form):
class sub(System.Exception):
pass

form = sub()
ob = SubclassConstructorTest(form)
self.assertTrue(isinstance(ob.value, Control))
instance = sub()
ob = SubclassConstructorTest(instance)
print ob
self.assertTrue(isinstance(ob.value, System.Exception))



Expand Down
9 changes: 3 additions & 6 deletions 9 pythonnet/src/tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,13 @@ def test():

def testEnumWithFlagsAttrConversion(self):
"""Test enumeration conversion with FlagsAttribute set."""
from System.Windows.Forms import Label

# This works because the AnchorStyles enum has FlagsAttribute.
label = Label()
label.Anchor = 99
# This works because the FlagsField enum has FlagsAttribute.
Test.FieldTest().FlagsField = 99

# This should fail because our test enum doesn't have it.
def test():
Test.FieldTest().EnumField = 99

self.assertRaises(ValueError, test)


Expand Down
7 changes: 0 additions & 7 deletions 7 pythonnet/src/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ def testRandomMultipleHandlers(self):

def testRemoveInternalCallHandler(self):
"""Test remove on an event sink implemented w/internalcall."""
clr.AddReference('System.Windows.Forms')
object = EventTest()

def h(sender, args):
Expand All @@ -502,12 +501,6 @@ def h(sender, args):
object.PublicEvent += h
object.PublicEvent -= h

from System.Windows.Forms import Form
f = Form()
f.Click += h
f.Click -= h
f.Dispose()


def testRemoveUnknownHandler(self):
"""Test removing an event handler that was never added."""
Expand Down
11 changes: 4 additions & 7 deletions 11 pythonnet/src/tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,13 @@ def testMethodCallStructConversion(self):

def testSubclassInstanceConversion(self):
"""Test subclass instance conversion in method call."""
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Form, Control

class sub(Form):
class sub(System.Exception):
pass

object = MethodTest()
form = sub()
result = object.TestSubclassConversion(form)
self.assertTrue(isinstance(result, Control))
instance = sub()
result = object.TestSubclassConversion(instance)
self.assertTrue(isinstance(result, System.Exception))


def testNullArrayConversion(self):
Expand Down
3 changes: 3 additions & 0 deletions 3 pythonnet/src/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def testFromModuleImportStar(self):

def testImplicitAssemblyLoad(self):
"""Test implicit assembly loading via import."""
# this test only applies to windows
if sys.platform != "win32":
return

def test():
# This should fail until System.Windows.Forms has been
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.