Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 090ff9f

Browse files
authored
Ensure that codec tests are run (pythonnet#1763)
* Move test_codec.py to the right directory * Call PyObjectConversions.Reset from Python via a proxy to keep it internal * Sign Python.Test DLL and make Python.Runtime internals visible for it
1 parent 80dc9f0 commit 090ff9f

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
using System.Runtime.CompilerServices;
22

33
[assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]
4+
5+
[assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]

src/testing/CodecTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using Python.Runtime;
56

67
namespace Python.Test
78
{
@@ -44,4 +45,12 @@ public int GetLength2(IList<ListMember> o)
4445
return o.Count;
4546
}
4647
}
48+
49+
public static class CodecResetter
50+
{
51+
public static void Reset()
52+
{
53+
PyObjectConversions.Reset();
54+
}
55+
}
4756
}

src/testing/Python.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
55
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
6+
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
7+
<SignAssembly>true</SignAssembly>
68
</PropertyGroup>
79
<ItemGroup>
810
<ProjectReference Include="..\runtime\Python.Runtime.csproj" />
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)