forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_codec.py
More file actions
70 lines (54 loc) · 1.92 KB
/
test_codec.py
File metadata and controls
70 lines (54 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""Test conversions using codecs from client python code"""
import clr
import System
import pytest
import Python.Runtime
from Python.Test import ListConversionTester, ListMember
class int_iterable():
def __init__(self):
self.counter = 0
def __iter__(self):
return self
def __next__(self):
if self.counter == 3:
raise StopIteration
self.counter = self.counter + 1
return self.counter
class obj_iterable():
def __init__(self):
self.counter = 0
def __iter__(self):
return self
def __next__(self):
if self.counter == 3:
raise StopIteration
self.counter = self.counter + 1
return ListMember(self.counter, "Number " + str(self.counter))
def test_iterable():
"""Test that a python iterable can be passed into a function that takes an IEnumerable<object>"""
#Python.Runtime.Codecs.ListDecoder.Register()
#Python.Runtime.Codecs.SequenceDecoder.Register()
Python.Runtime.Codecs.IterableDecoder.Register()
ob = ListConversionTester()
iterable = int_iterable()
assert 3 == ob.GetLength(iterable)
iterable2 = obj_iterable()
assert 3 == ob.GetLength2(iterable2)
Python.Runtime.PyObjectConversions.Reset()
def test_sequence():
Python.Runtime.Codecs.SequenceDecoder.Register()
ob = ListConversionTester()
tup = (1,2,3)
assert 3 == ob.GetLength(tup)
tup2 = (ListMember(1, "one"), ListMember(2, "two"), ListMember(3, "three"))
assert 3 == ob.GetLength(tup2)
Python.Runtime.PyObjectConversions.Reset()
def test_list():
Python.Runtime.Codecs.SequenceDecoder.Register()
ob = ListConversionTester()
l = [1,2,3]
assert 3 == ob.GetLength(l)
l2 = [ListMember(1, "one"), ListMember(2, "two"), ListMember(3, "three")]
assert 3 == ob.GetLength(l2)
Python.Runtime.PyObjectConversions.Reset()