Skip to content

Commit 706e590

Browse files
committed
Merge pull request #9 from tonyroberts/travis-ci
get most of the unit tests working with mono
2 parents b738fe1 + 18af760 commit 706e590

11 files changed

+34
-35
lines changed

pythonnet/src/monoclr/pynetinit.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ void main_thread_handler (gpointer user_data) {
104104
for (ii = 0; ii < PyList_Size(syspath); ++ii) {
105105
const char* pydir = PyString_AsString(PyList_GetItem(syspath, ii));
106106
char* curdir = (char*) malloc(1024);
107-
if (strlen(pydir) == 0) pydir = ".";
108-
109-
strcpy(curdir, pydir);
110-
strcat(curdir, slash);
107+
strncpy(curdir, strlen(pydir) > 0 ? pydir : ".", 1024);
108+
strncat(curdir, slash, 1024);
111109

112110
//look in this directory for the pn_args->pr_file
113111
DIR* dirp = opendir(curdir);

pythonnet/src/runtime/runtime.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ internal static void Initialize() {
7777

7878
if (0 == Runtime.Py_IsInitialized()) {
7979
Runtime.Py_Initialize();
80-
Runtime.PyEval_InitThreads();
8180
}
8281

82+
// make sure threads are initialized even if python was initialized already
83+
Runtime.PyEval_InitThreads();
84+
8385
IntPtr dict = Runtime.PyImport_GetModuleDict();
8486
IntPtr op = Runtime.PyDict_GetItemString(dict, "__builtin__");
8587

pythonnet/src/testing/constructortests.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
using System;
1111
using System.Collections;
12-
using System.Windows.Forms;
1312
using System.IO;
1413

1514
namespace Python.Test {
@@ -53,9 +52,9 @@ public StructConstructorTest(Guid v) {
5352

5453
public class SubclassConstructorTest {
5554

56-
public Control value;
55+
public Exception value;
5756

58-
public SubclassConstructorTest(Control v) {
57+
public SubclassConstructorTest(Exception v) {
5958
this.value = v;
6059
}
6160

pythonnet/src/testing/enumtest.cs

+10
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,14 @@ public enum ULongEnum : ulong {
8888
Five
8989
}
9090

91+
[FlagsAttribute]
92+
public enum FlagsEnum {
93+
Zero,
94+
One,
95+
Two,
96+
Three,
97+
Four,
98+
Five
99+
}
100+
91101
}

pythonnet/src/testing/fieldtest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public void Shutup() {
5757
public decimal DecimalField = 0;
5858
public string StringField;
5959
public ShortEnum EnumField;
60+
public FlagsEnum FlagsField;
6061
public object ObjectField;
6162
public ISpam SpamField;
6263

pythonnet/src/testing/methodtest.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
using System;
1111
using System.IO;
12-
using System.Windows.Forms;
1312
using System.Collections.Generic;
1413

1514
namespace Python.Test {
@@ -71,7 +70,7 @@ public Guid TestStructConversion(Guid v) {
7170
return v;
7271
}
7372

74-
public Control TestSubclassConversion(Control v) {
73+
public Exception TestSubclassConversion(Exception v) {
7574
return v;
7675
}
7776

pythonnet/src/tests/test_constructors.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ def testStructConstructor(self):
4949
def testSubclassConstructor(self):
5050
"""Test subclass constructor args"""
5151
from Python.Test import SubclassConstructorTest
52-
from System.Windows.Forms import Form, Control
5352

54-
class sub(Form):
53+
class sub(System.Exception):
5554
pass
5655

57-
form = sub()
58-
ob = SubclassConstructorTest(form)
59-
self.assertTrue(isinstance(ob.value, Control))
56+
instance = sub()
57+
ob = SubclassConstructorTest(instance)
58+
print ob
59+
self.assertTrue(isinstance(ob.value, System.Exception))
6060

6161

6262

pythonnet/src/tests/test_enum.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,13 @@ def test():
122122

123123
def testEnumWithFlagsAttrConversion(self):
124124
"""Test enumeration conversion with FlagsAttribute set."""
125-
from System.Windows.Forms import Label
126-
127-
# This works because the AnchorStyles enum has FlagsAttribute.
128-
label = Label()
129-
label.Anchor = 99
125+
# This works because the FlagsField enum has FlagsAttribute.
126+
Test.FieldTest().FlagsField = 99
130127

131128
# This should fail because our test enum doesn't have it.
132129
def test():
133130
Test.FieldTest().EnumField = 99
134-
131+
135132
self.assertRaises(ValueError, test)
136133

137134

pythonnet/src/tests/test_event.py

-7
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ def testRandomMultipleHandlers(self):
493493

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

499498
def h(sender, args):
@@ -502,12 +501,6 @@ def h(sender, args):
502501
object.PublicEvent += h
503502
object.PublicEvent -= h
504503

505-
from System.Windows.Forms import Form
506-
f = Form()
507-
f.Click += h
508-
f.Click -= h
509-
f.Dispose()
510-
511504

512505
def testRemoveUnknownHandler(self):
513506
"""Test removing an event handler that was never added."""

pythonnet/src/tests/test_method.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,13 @@ def testMethodCallStructConversion(self):
235235

236236
def testSubclassInstanceConversion(self):
237237
"""Test subclass instance conversion in method call."""
238-
clr.AddReference("System.Windows.Forms")
239-
from System.Windows.Forms import Form, Control
240-
241-
class sub(Form):
238+
class sub(System.Exception):
242239
pass
243240

244241
object = MethodTest()
245-
form = sub()
246-
result = object.TestSubclassConversion(form)
247-
self.assertTrue(isinstance(result, Control))
242+
instance = sub()
243+
result = object.TestSubclassConversion(instance)
244+
self.assertTrue(isinstance(result, System.Exception))
248245

249246

250247
def testNullArrayConversion(self):

pythonnet/src/tests/test_module.py

+3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ def testFromModuleImportStar(self):
204204

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

208211
def test():
209212
# This should fail until System.Windows.Forms has been

0 commit comments

Comments
 (0)