Skip to content

Fixed #296 Converter support for PyObject #297

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 7 commits into from
Dec 16, 2016
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
Next Next commit
Added test for #296
  • Loading branch information
rmadsen-ks committed Nov 30, 2016
commit bb73ed1600f8b9d9b5850bf45a0292382a10c703
14 changes: 14 additions & 0 deletions src/testing/callbacktest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,19 @@ public string Call_simpleDefaultArg_WithEmptyArgs(string moduleName)
return module.simpleDefaultArg();
}
}
}

//==========================================================================
// Tests calling from Python into C# and back into Python using a PyObject.
// SelfCallbackTest should be inherited from a Python class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor nitpick, but shouldn't that read "inherited by a Python class"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment has been changed.

// Used in test_class.py / testCallback
//==========================================================================
public class SelfCallbackTest
{
public void Callback(Runtime.PyObject self)
{
using (Runtime.Py.GIL())
((dynamic)self).PyCallback(self);
}
}
}
16 changes: 16 additions & 0 deletions src/tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Python.Test as Test
import System
import six
import Python.Runtime

if six.PY3:
DictProxyType = type(object.__dict__)
Expand Down Expand Up @@ -198,6 +199,21 @@ def __setitem__(self, key, value):

self.assertTrue(table.Count == 3)

def testSelfCallback(self):
""" Test calling back and forth between this and a c# baseclass."""
class CallbackUser(Test.SelfCallbackTest):
def DoCallback(self):
self.PyCallbackWasCalled = False
self.SameReference = False
return self.Callback(self)
def PyCallback(self, self2):
self.PyCallbackWasCalled = True
self.SameReference = self == self2

testobj = CallbackUser()
testobj.DoCallback()
self.assertTrue(testobj.PyCallbackWasCalled)
self.assertTrue(testobj.SameReference)

class ClassicClass:
def kind(self):
Expand Down