8000 Ensure that codec tests are run by filmor · Pull Request #1763 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Ensure that codec tests are run #1763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/runtime/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]

[assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]
9 changes: 9 additions & 0 deletions src/testing/CodecTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Python.Runtime;

namespace Python.Test
{
Expand Down Expand Up @@ -44,4 +45,12 @@ public int GetLength2(IList<ListMember> o)
return o.Count;
}
}

public static class CodecResetter
{
public static void Reset()
{
PyObjectConversions.Reset();
}
}
}
2 changes: 2 additions & 0 deletions src/te 8000 sting/Python.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\runtime\Python.Runtime.csproj" />
Expand Down
74 changes: 37 additions & 37 deletions src/tests/test_codec.py → 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()
0