Skip to content

clrmethod working for python 2 #494

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 8 commits into from
Jun 16, 2017
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
Add test_clrmethod.py and update AUTHORS and CHANGELOG
  • Loading branch information
Rickard Holmberg committed Jun 15, 2017
commit d620babe3354d33b8b29ddf505e7ffe8b7087cf8
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- Matthias Dittrich ([@matthid](https://github.com/matthid))
- Patrick Stewart ([@patstew](https://github.com/patstew))
- Raphael Nestler ([@rnestler](https://github.com/rnestler))
- Rickard Holmberg ([@rickardraysearch](https://github.com/rickardraysearch))
- Sam Winstanley ([@swinstanley](https://github.com/swinstanley))
- Sean Freitag ([@cowboygneox](https://github.com/cowboygneox))
- Serge Weinstock ([@sweinst](https://github.com/sweinst))
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
derived from a .NET class has a `__namespace__` or `__assembly__`
attribute (#481)
- Fixed conversion of 'float' and 'double' values (#486)
- Fixed 'clrmethod' for python 2 (#492)


## [2.3.0][] - 2017-03-11
Expand Down
71 changes: 71 additions & 0 deletions src/tests/test_clrmethod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-

"""Test clrmethod and clrproperty support for calling methods and getting/setting python properties from CLR."""

import Python.Test as Test
import System
import pytest
import clr

class ExampleClrClass(System.Object):
__namespace__ = "PyTest"
def __init__(self):
self._x = 3
@clr.clrmethod(int, [int])
def test(self, x):
return x*2

def get_X(self):
return self._x
def set_X(self, value):
self._x = value
X = clr.clrproperty(int, get_X, set_X)

@clr.clrproperty(int)
def Y(self):
return self._x * 2

def test_set_and_get_property_from_py():
"""Test usage of CLR defined reference types."""
t = ExampleClrClass()
assert t.X == 3
assert t.Y == 3 * 2
t.X = 4
assert t.X == 4
assert t.Y == 4 * 2

def test_set_and_get_property_from_clr():
"""Test usage of CLR defined reference types."""
t = ExampleClrClass()
assert t.GetType().GetProperty("X").GetValue(t) == 3
assert t.GetType().GetProperty("Y").GetValue(t) == 3 * 2
t.GetType().GetProperty("X").SetValue(t, 4)
assert t.GetType().GetProperty("X").GetValue(t) == 4
assert t.GetType().GetProperty("Y").GetValue(t) == 4 * 2


def test_set_and_get_property_from_clr_and_py():
"""Test usage of CLR defined reference types."""
t = ExampleClrClass()
assert t.GetType().GetProperty("X").GetValue(t) == 3
assert t.GetType().GetProperty("Y").GetValue(t) == 3 * 2
assert t.X == 3
assert t.Y == 3 * 2
t.GetType().GetProperty("X").SetValue(t, 4)
assert t.GetType().GetProperty("X").GetValue(t) == 4
assert t.GetType().GetProperty("Y").GetValue(t) == 4 * 2
assert t.X == 4
assert t.Y == 4 * 2
t.X = 5
assert t.GetType().GetProperty("X").GetValue(t) == 5
assert t.GetType().GetProperty("Y").GetValue(t) == 5 * 2
assert t.X == 5
assert t.Y == 5 * 2

def test_method_invocation_from_py():
t = ExampleClrClass()
assert t.test(41) == 41*2

def test_method_invocation_from_clr():
t = ExampleClrClass()
assert t.GetType().GetMethod("test").Invoke(t, [37]) == 37*2