Thanks to visit codestin.com
Credit goes to github.com

Skip to content

get most of the unit tests working with mono #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2014
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 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 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 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 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 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 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 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 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 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 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 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