Skip to content

Ensure tests, that need running PythonEngine have similar SetUp and TearDown #1564

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 1 commit into from
Sep 22, 2021
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
10 changes: 4 additions & 6 deletions src/embed_tests/References.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 4 additions & 6 deletions src/embed_tests/TestNativeTypeOffset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
Expand Down
8 changes: 2 additions & 6 deletions src/embed_tests/TestPythonException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
20 changes: 4 additions & 16 deletions src/embed_tests/dynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
Expand Down
8 changes: 2 additions & 6 deletions src/embed_tests/pyimport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ namespace Python.EmbeddingTest
/// </remarks>
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
Expand All @@ -41,10 +38,9 @@ public void SetUp()
Runtime.Runtime.XDecref(str);
}

[TearDown]
[OneTimeTearDown]
public void Dispose()
{
PythonEngine.ReleaseLock(_gs);
PythonEngine.Shutdown();
}

Expand Down
10 changes: 4 additions & 6 deletions src/embed_tests/pyrunstring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down