Skip to content

Commit d620bab

Browse files
author
Rickard Holmberg
committed
Add test_clrmethod.py and update AUTHORS and CHANGELOG
1 parent 6bfef31 commit d620bab

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- Matthias Dittrich ([@matthid](https://github.com/matthid))
3232
- Patrick Stewart ([@patstew](https://github.com/patstew))
3333
- Raphael Nestler ([@rnestler](https://github.com/rnestler))
34+
- Rickard Holmberg ([@rickardraysearch](https://github.com/rickardraysearch))
3435
- Sam Winstanley ([@swinstanley](https://github.com/swinstanley))
3536
- Sean Freitag ([@cowboygneox](https://github.com/cowboygneox))
3637
- Serge Weinstock ([@sweinst](https://github.com/sweinst))

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2121
derived from a .NET class has a `__namespace__` or `__assembly__`
2222
attribute (#481)
2323
- Fixed conversion of 'float' and 'double' values (#486)
24+
- Fixed 'clrmethod' for python 2 (#492)
2425

2526

2627
## [2.3.0][] - 2017-03-11

src/tests/test_clrmethod.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""Test clrmethod and clrproperty support for calling methods and getting/setting python properties from CLR."""
4+
5+
import Python.Test as Test
6+
import System
7+
import pytest
8+
import clr
9+
10+
class ExampleClrClass(System.Object):
11+
__namespace__ = "PyTest"
12+
def __init__(self):
13+
self._x = 3
14+
@clr.clrmethod(int, [int])
15+
def test(self, x):
16+
return x*2
17+
18+
def get_X(self):
19+
return self._x
20+
def set_X(self, value):
21+
self._x = value
22+
X = clr.clrproperty(int, get_X, set_X)
23+
24+
@clr.clrproperty(int)
25+
def Y(self):
26+
return self._x * 2
27+
28+
def test_set_and_get_property_from_py():
29+
"""Test usage of CLR defined reference types."""
30+
t = ExampleClrClass()
31+
assert t.X == 3
32+
assert t.Y == 3 * 2
33+
t.X = 4
34+
assert t.X == 4
35+
assert t.Y == 4 * 2
36+
37+
def test_set_and_get_property_from_clr():
38+
"""Test usage of CLR defined reference types."""
39+
t = ExampleClrClass()
40+
assert t.GetType().GetProperty("X").GetValue(t) == 3
41+
assert t.GetType().GetProperty("Y").GetValue(t) == 3 * 2
42+
t.GetType().GetProperty("X").SetValue(t, 4)
43+
assert t.GetType().GetProperty("X").GetValue(t) == 4
44+
assert t.GetType().GetProperty("Y").GetValue(t) == 4 * 2
45+
46+
47+
def test_set_and_get_property_from_clr_and_py():
48+
"""Test usage of CLR defined reference types."""
49+
t = ExampleClrClass()
50+
assert t.GetType().GetProperty("X").GetValue(t) == 3
51+
assert t.GetType().GetProperty("Y").GetValue(t) == 3 * 2
52+
assert t.X == 3
53+
assert t.Y == 3 * 2
54+
t.GetType().GetProperty("X").SetValue(t, 4)
55+
assert t.GetType().GetProperty("X").GetValue(t) == 4
56+
assert t.GetType().GetProperty("Y").GetValue(t) == 4 * 2
57+
assert t.X == 4
58+
assert t.Y == 4 * 2
59+
t.X = 5
60+
assert t.GetType().GetProperty("X").GetValue(t) == 5
61+
assert t.GetType().GetProperty("Y").GetValue(t) == 5 * 2
62+
assert t.X == 5
63+
assert t.Y == 5 * 2
64+
65+
def test_method_invocation_from_py():
66+
t = ExampleClrClass()
67+
assert t.test(41) == 41*2
68+
69+
def test_method_invocation_from_clr():
70+
t = ExampleClrClass()
71+
assert t.GetType().GetMethod("test").Invoke(t, [37]) == 37*2

0 commit comments

Comments
 (0)