8000 Call Reset by proxy to keep it internal · pythonnet/pythonnet@58deb60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 58deb60

Browse files
authored
Call Reset by proxy to keep it internal
1 parent 15de5e9 commit 58deb60

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

src/runtime/Codecs/PyObjectConversions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool TryDecode(BorrowedReference pyHandle, out object? result)
125125

126126
#endregion
127127

128-
public static void Reset()
128+
internal static void Reset()
129129
{
130130
lock (encoders)
131131
lock (decoders)

src/testing/CodecTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ public int GetLength2(IList<ListMember> o)
4444
return o.Count;
4545
}
4646
}
47+
48+
public static class CodecResetter
49+
{
50+
public static void Reset()
51+
{
52+
PyObjectConversions.Reset();
53+
}
54+
}
4755
}

tests/test_codec.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
# -*- coding: utf-8 -*-
2-
3-
"""Test conversions using codecs from client python code"""
4-
import clr
5-
import System
6-
import pytest
7-
import Python.Runtime
8-
from Python.Test import ListConversionTester, ListMember
9-
10-
class int_iterable():
11-
def __init__(self):
12-
self.counter = 0
13-
def __iter__(self):
14-
return self
15-
def __next__(self):
16-
if self.counter == 3:
17-
raise StopIteration
18-
self.counter = self.counter + 1
19-
return self.counter
1+
# -*- coding: utf-8 -*-
2+
3+
"""Test conversions using codecs from client python code"""
4+
import clr
5+
import System
6+
import pytest
7+
import Python.Runtime
8+
from Python.Test import ListConversionTester, ListMember, CodecResetter
9+
10+
class int_iterable():
11+
def __init__(self):
12+
self.counter = 0
13+
def __iter__(self):
14+
return self
15+
def __next__(self):
16+
if self.counter == 3:
17+
raise StopIteration
18+
self.counter = self.counter + 1
19+
return self.counter
2020

2121
class obj_iterable():
22-
def __init__(self):
23-
self.counter = 0
24-
def __iter__(self):
25-
return self
26-
def __next__(self):
27-
if self.counter == 3:
28-
raise StopIteration
22+
def __init__(self):
23+
self.counter = 0
24+
def __iter__(self):
25+
return self
26+
def __next__(self):
27+
if self.counter == 3:
28+
raise StopIteration
2929
self.counter = self.counter + 1
3030
return ListMember(self.counter, "Number " + str(self.counter))
31-
32-
def test_iterable():
33-
"""Test that a python iterable can be passed into a function that takes an IEnumerable<object>"""
34-
35-
#Python.Runtime.Codecs.ListDecoder.Register()
36-
#Python.Runtime.Codecs.SequenceDecoder.Register()
37-
Python.Runtime.Codecs.IterableDecoder.Register()
31+
32+
def test_iterable():
33+
"""Test that a python iterable can be passed into a function that takes an IEnumerable<object>"""
34+
35+
#Python.Runtime.Codecs.ListDecoder.Register()
36+
#Python.Runtime.Codecs.SequenceDecoder.Register()
37+
Python.Runtime.Codecs.IterableDecoder.Register()
3838
ob = ListConversionTester()
3939

40-
iterable = int_iterable()
40+
iterable = int_iterable()
4141
assert 3 == ob.GetLength(iterable)
4242

4343
iterable2 = obj_iterable()
4444
assert 3 == ob.GetLength2(iterable2)
4545

46-
Python.Runtime.PyObjectConversions.Reset()
46+
CodecResetter.Reset()
4747

4848
def test_sequence():
4949
Python.Runtime.Codecs.SequenceDecoder.Register()
@@ -55,7 +55,7 @@ def test_sequence():
5555
tup2 = (ListMember(1, "one"), ListMember(2, "two"), ListMember(3, "three"))
5656
assert 3 == ob.GetLength(tup2)
5757

58-
Python.Runtime.PyObjectConversions.Reset()
58+
CodecResetter.Reset()
5959

6060
def test_list():
6161
Python.Runtime.Codecs.SequenceDecoder.Register()
@@ -67,4 +67,4 @@ def test_list():
6767
l2 = [ListMember(1, "one"), ListMember(2, "two"), ListMember(3, "three")]
6868
assert 3 == ob.GetLength(l2)
6969

70-
Python.Runtime.PyObjectConversions.Reset()
70+
CodecResetter.Reset()

0 commit comments

Comments
 (0)
0