From 8d43dbe9db29d2365c4fa1c7e2ff73e0842f5534 Mon Sep 17 00:00:00 2001 From: Victor Nova Date: Wed, 22 Sep 2021 10:11:38 -0700 Subject: [PATCH] ensure all unit tests have similar SetUp and TearDown procedures when a running PythonEngine is needed --- src/embed_tests/References.cs | 10 ++++------ src/embed_tests/TestNativeTypeOffset.cs | 10 ++++------ src/embed_tests/TestPythonException.cs | 8 ++------ src/embed_tests/dynamic.cs | 20 ++++---------------- src/embed_tests/pyimport.cs | 8 ++------ src/embed_tests/pyrunstring.cs | 10 ++++------ 6 files changed, 20 insertions(+), 46 deletions(-) diff --git a/src/embed_tests/References.cs b/src/embed_tests/References.cs index 417e743c0..36e1698c1 100644 --- a/src/embed_tests/References.cs +++ b/src/embed_tests/References.cs @@ -5,18 +5,16 @@ namespace Python.EmbeddingTest public class References { - private Py.GILState _gs; - - [SetUp] + [OneTimeSetUp] public void SetUp() { - _gs = Py.GIL(); + PythonEngine.Initialize(); } - [TearDown] + [OneTimeTearDown] public void Dispose() { - _gs.Dispose(); + PythonEngine.Shutdown(); } [Test] diff --git a/src/embed_tests/TestNativeTypeOffset.cs b/src/embed_tests/TestNativeTypeOffset.cs index 8efd16e02..2d31fe506 100644 --- a/src/embed_tests/TestNativeTypeOffset.cs +++ b/src/embed_tests/TestNativeTypeOffset.cs @@ -13,18 +13,16 @@ namespace Python.EmbeddingTest { public class TestNativeTypeOffset { - private Py.GILState _gs; - - [SetUp] + [OneTimeSetUp] public void SetUp() { - _gs = Py.GIL(); + PythonEngine.Initialize(); } - [TearDown] + [OneTimeTearDown] public void Dispose() { - _gs.Dispose(); + PythonEngine.Shutdown(); } /// diff --git a/src/embed_tests/TestPythonException.cs b/src/embed_tests/TestPythonException.cs index a4b28906c..a7cf05c83 100644 --- a/src/embed_tests/TestPythonException.cs +++ b/src/embed_tests/TestPythonException.cs @@ -6,19 +6,15 @@ namespace Python.EmbeddingTest { public class TestPythonException { - private IntPtr _gs; - - [SetUp] + [OneTimeSetUp] public void SetUp() { PythonEngine.Initialize(); - _gs = PythonEngine.AcquireLock(); } - [TearDown] + [OneTimeTearDown] public void Dispose() { - PythonEngine.ReleaseLock(_gs); PythonEngine.Shutdown(); } diff --git a/src/embed_tests/dynamic.cs b/src/embed_tests/dynamic.cs index 81345cee7..827782a5c 100644 --- a/src/embed_tests/dynamic.cs +++ b/src/embed_tests/dynamic.cs @@ -7,28 +7,16 @@ namespace Python.EmbeddingTest { public class DynamicTest { - private Py.GILState _gs; - - [SetUp] + [OneTimeSetUp] public void SetUp() { - try { - _gs = Py.GIL(); - } catch (Exception e) { - Console.WriteLine($"exception in SetUp: {e}"); - throw; - } + PythonEngine.Initialize(); } - [TearDown] + [OneTimeTearDown] public void Dispose() { - try { - _gs.Dispose(); - } catch(Exception e) { - Console.WriteLine($"exception in TearDown: {e}"); - throw; - } + PythonEngine.Shutdown(); } /// diff --git a/src/embed_tests/pyimport.cs b/src/embed_tests/pyimport.cs index de8a06bf8..26dc91ff7 100644 --- a/src/embed_tests/pyimport.cs +++ b/src/embed_tests/pyimport.cs @@ -19,13 +19,10 @@ namespace Python.EmbeddingTest /// public class PyImportTest { - private IntPtr _gs; - - [SetUp] + [OneTimeSetUp] public void SetUp() { PythonEngine.Initialize(); - _gs = PythonEngine.AcquireLock(); /* Append the tests directory to sys.path * using reflection to circumvent the private @@ -41,10 +38,9 @@ public void SetUp() Runtime.Runtime.XDecref(str); } - [TearDown] + [OneTimeTearDown] public void Dispose() { - PythonEngine.ReleaseLock(_gs); PythonEngine.Shutdown(); } diff --git a/src/embed_tests/pyrunstring.cs b/src/embed_tests/pyrunstring.cs index 07875a2a8..4a83afa9a 100644 --- a/src/embed_tests/pyrunstring.cs +++ b/src/embed_tests/pyrunstring.cs @@ -6,18 +6,16 @@ namespace Python.EmbeddingTest { public class RunStringTest { - private Py.GILState _gs; - - [SetUp] + [OneTimeSetUp] public void SetUp() { - _gs = Py.GIL(); + PythonEngine.Initialize(); } - [TearDown] + [OneTimeTearDown] public void Dispose() { - _gs.Dispose(); + PythonEngine.Shutdown(); } [Test] 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