From 29a3260f3be21d8eaf40c67b0a9ba0641cd709ae Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Sun, 10 Apr 2022 18:28:18 +0200 Subject: [PATCH 1/5] Move test_codec.py to the right directory --- {src/tests => tests}/test_codec.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src/tests => tests}/test_codec.py (100%) diff --git a/src/tests/test_codec.py b/tests/test_codec.py similarity index 100% rename from src/tests/test_codec.py rename to tests/test_codec.py From 15de5e902baa2acb260a9ddee6ebb35e6f990899 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Sun, 10 Apr 2022 18:48:50 +0200 Subject: [PATCH 2/5] Make PyObjectConversions.Reset public to allow calling it from Python --- src/runtime/Codecs/PyObjectConversions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/Codecs/PyObjectConversions.cs b/src/runtime/Codecs/PyObjectConversions.cs index 94ed4cdc3..0be9ab93e 100644 --- a/src/runtime/Codecs/PyObjectConversions.cs +++ b/src/runtime/Codecs/PyObjectConversions.cs @@ -125,7 +125,7 @@ bool TryDecode(BorrowedReference pyHandle, out object? result) #endregion - internal static void Reset() + public static void Reset() { lock (encoders) lock (decoders) From 58deb60bb9401573dfd9ba40a5ee0f783c657b83 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Fri, 22 Apr 2022 19:26:12 +0200 Subject: [PATCH 3/5] Call Reset by proxy to keep it internal --- src/runtime/Codecs/PyObjectConversions.cs | 2 +- src/testing/CodecTest.cs | 8 +++ tests/test_codec.py | 74 +++++++++++------------ 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/runtime/Codecs/PyObjectConversions.cs b/src/runtime/Codecs/PyObjectConversions.cs index 0be9ab93e..94ed4cdc3 100644 --- a/src/runtime/Codecs/PyObjectConversions.cs +++ b/src/runtime/Codecs/PyObjectConversions.cs @@ -125,7 +125,7 @@ bool TryDecode(BorrowedReference pyHandle, out object? result) #endregion - public static void Reset() + internal static void Reset() { lock (encoders) lock (decoders) diff --git a/src/testing/CodecTest.cs b/src/testing/CodecTest.cs index 74f77531b..db89b218e 100644 --- a/src/testing/CodecTest.cs +++ b/src/testing/CodecTest.cs @@ -44,4 +44,12 @@ public int GetLength2(IList o) return o.Count; } } + + public static class CodecResetter + { + public static void Reset() + { + PyObjectConversions.Reset(); + } + } } diff --git a/tests/test_codec.py b/tests/test_codec.py index 9fdbfbbf5..9744d3856 100644 --- a/tests/test_codec.py +++ b/tests/test_codec.py @@ -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""" - - #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""" + + #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() @@ -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() @@ -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() From 912c7df59c087ea49d696eb1a83d680cbc302cf1 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Fri, 22 Apr 2022 19:44:48 +0200 Subject: [PATCH 4/5] Fix missing using --- src/testing/CodecTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/testing/CodecTest.cs b/src/testing/CodecTest.cs index db89b218e..f3c243dab 100644 --- a/src/testing/CodecTest.cs +++ b/src/testing/CodecTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Python.Runtime; namespace Python.Test { From a6733bae02c7ee6c2d3dc69dde4ed38e1761a555 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Mon, 25 Apr 2022 08:33:13 +0200 Subject: [PATCH 5/5] Sign Python.Test DLL and make Python.Runtime internals visible for it --- src/runtime/Properties/AssemblyInfo.cs | 2 ++ src/testing/Python.Test.csproj | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/runtime/Properties/AssemblyInfo.cs b/src/runtime/Properties/AssemblyInfo.cs index 3417bccc8..b05fcc8bf 100644 --- a/src/runtime/Properties/AssemblyInfo.cs +++ b/src/runtime/Properties/AssemblyInfo.cs @@ -1,3 +1,5 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")] + +[assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")] \ No newline at end of file diff --git a/src/testing/Python.Test.csproj b/src/testing/Python.Test.csproj index 78f3a3169..1f40f4518 100644 --- a/src/testing/Python.Test.csproj +++ b/src/testing/Python.Test.csproj @@ -3,6 +3,8 @@ netstandard2.0;net6.0 true true + ..\pythonnet.snk + true pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy