8000 Add unit test for enum encoder · pythonnet/pythonnet@9e70b8f · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e70b8f

Browse files
committed
Add unit test for enum encoder
1 parent df3b569 commit 9e70b8f

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

tests/test_codec.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
11
# -*- coding: utf-8 -*-
22

33
"""Test conversions using codecs from client python code"""
4-
import clr
5-
import System
4+
65
import pytest
76
import Python.Runtime
7+
import Python.Test as Test
88
from Python.Test import ListConversionTester, ListMember, CodecResetter
99

10-
class int_iterable():
10+
11+
@pytest.fixture(autouse=True)
12+
def reset():
13+
yield
14+
CodecResetter.Reset()
15+
16+
17+
class int_iterable:
1118
def __init__(self):
1219
self.counter = 0
20+
1321
def __iter__(self):
1422
return self
23+
1524
def __next__(self):
1625
if self.counter == 3:
1726
raise StopIteration
1827
self.counter = self.counter + 1
1928
return self.counter
2029

21-
class obj_iterable():
30+
31+
class obj_iterable:
2232
def __init__(self):
2333
self.counter = 0
34+
2435
def __iter__(self):
2536
return self
37+
2638
def __next__(self):
2739
if self.counter == 3:
2840
raise StopIteration
2941
self.counter = self.counter + 1
3042
return ListMember(self.counter, "Number " + str(self.counter))
3143

44+
3245
def test_iterable():
33-
"""Test that a python iterable can be passed into a function that takes an IEnumerable<object>"""
46+
"""Test that a python iterable can be passed into a function that takes an
47+
IEnumerable<object>"""
3448

35-
#Python.Runtime.Codecs.ListDecoder.Register()
36-
#Python.Runtime.Codecs.SequenceDecoder.Register()
49+
# Python.Runtime.Codecs.ListDecoder.Register()
50+
# Python.Runtime.Codecs.SequenceDecoder.Register()
3751
Python.Runtime.Codecs.IterableDecoder.Register()
3852
ob = ListConversionTester()
3953

@@ -43,28 +57,33 @@ def test_iterable():
4357
iterable2 = obj_iterable()
4458
assert 3 == ob.GetLength2(iterable2)
4559

46-
CodecResetter.Reset()
4760

4861
def test_sequence():
4962
Python.Runtime.Codecs.SequenceDecoder.Register()
5063
ob = ListConversionTester()
5164

52-
tup = (1,2,3)
65+
tup = (1, 2, 3)
5366
assert 3 == ob.GetLength(tup)
5467

5568
tup2 = (ListMember(1, "one"), ListMember(2, "two"), ListMember(3, "three"))
5669
assert 3 == ob.GetLength(tup2)
5770

58-
CodecResetter.Reset()
5971

6072
def test_list():
6173
Python.Runtime.Codecs.SequenceDecoder.Register()
6274
ob = ListConversionTester()
6375

64-
l = [1,2,3]
76+
l = [1, 2, 3]
6577
assert 3 == ob.GetLength(l)
6678

6779
l2 = [ListMember(1, "one"), ListMember(2, "two"), ListMember(3, "three")]
6880
assert 3 == ob.GetLength(l2)
6981

70-
CodecResetter.Reset()
82+
83+
def test_enum():
84+
Python.Runtime.PyObjectConversions.RegisterEncoder(
85+
Python.Runtime.Codecs.EnumPyIntCodec.Instance
86+
)
87+
88+
assert Test.LongEnum.Max == 9223372036854775807
89+
assert Test.LongEnum.Min == -9223372036854775808

0 commit comments

Comments
 (0)
0