Skip to content
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
Call Reset by proxy to keep it internal
  • Loading branch information
filmor authored Apr 22, 2022
commit 58deb60bb9401573dfd9ba40a5ee0f783c657b83
2 changes: 1 addition & 1 deletion src/runtime/Codecs/PyObjectConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool TryDecode(BorrowedReference pyHandle, out object? result)

#endregion

public static void Reset()
internal static void Reset()
{
lock (encoders)
lock (decoders)
Expand Down
8 changes: 8 additions & 0 deletions src/testing/CodecTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ public int GetLength2(IList<ListMember> o)
return o.Count;
}
}

public static class CodecResetter
{
public static void Reset()
{
PyObjectConversions.Reset();
}
}
}
74 changes: 37 additions & 37 deletions tests/test_codec.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
# -*- 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
# -*- 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, CodecResetter

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
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()

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()
iterable = int_iterable()
assert 3 == ob.GetLength(iterable)

iterable2 = obj_iterable()
assert 3 == ob.GetLength2(iterable2)

Python.Runtime.PyObjectConversions.Reset()
CodecResetter.Reset()

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

Python.Runtime.PyObjectConversions.Reset()
CodecResetter.Reset()

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

Python.Runtime.PyObjectConversions.Reset()
CodecResetter.Reset()