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

Skip to content

Simplify Embedded tests & Add new tests #369

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 4 commits into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Simplify embed_tests
Since the previous bug involving initialize/finalize have been solved,
we can confidently upgrade these test to use simpler format.

Also Remove Assert fail messages
NUnit already says the name of which test failed.
  • Loading branch information
vmuriart committed Feb 8, 2017
commit 368d4d175c55d79c896295a8aaec371520403d8e
30 changes: 16 additions & 14 deletions src/embed_tests/pyimport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

namespace Python.EmbeddingTest
{
/// <summary>
/// Test Import unittests and regressions
/// </summary>
/// <remarks>
/// Keeping in old-style SetUp/TearDown due to required SetUp.
/// The required directory structure was added to .\pythonnet\src\tests\ directory:
/// + PyImportTest/
/// | - __init__.py
/// | + test/
/// | | - __init__.py
/// | | - one.py
/// </remarks>
[TestFixture]
public class PyImportTest
{
Expand All @@ -18,10 +30,8 @@ public void SetUp()

/* Append the tests directory to sys.path
* using reflection to circumvent the private
* modifiers placed on most Runtime methods.
*/
const string s = @"../../tests";

* modifiers placed on most Runtime methods. */
const string s = "../../tests";
string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, s);

IntPtr str = Runtime.Runtime.PyString_FromString(testPath);
Expand All @@ -39,19 +49,11 @@ public void TearDown()
/// <summary>
/// Test subdirectory import
/// </summary>
/// <remarks>
/// The required directory structure was added to .\pythonnet\src\tests\ directory:
/// + PyImportTest/
/// | - __init__.py
/// | + test/
/// | | - __init__.py
/// | | - one.py
/// </remarks>
[Test]
public void TestDottedName()
{
PyObject module = PythonEngine.ImportModule("PyImportTest.test.one");
Assert.IsNotNull(module, ">>> import PyImportTest.test.one # FAILED");
Assert.IsNotNull(module);
}

/// <summary>
Expand All @@ -61,7 +63,7 @@ public void TestDottedName()
public void TestSysArgsImportException()
{
PyObject module = PythonEngine.ImportModule("PyImportTest.sysargv");
Assert.IsNotNull(module, ">>> import PyImportTest.sysargv # FAILED");
Assert.IsNotNull(module);
}
}
}
43 changes: 14 additions & 29 deletions src/embed_tests/pyiter.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,30 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Python.Runtime;

namespace Python.EmbeddingTest
{
[TestFixture]
public class PyIterTest
{
private IntPtr gs;

[SetUp]
public void SetUp()
{
PythonEngine.Initialize();
gs = PythonEngine.AcquireLock();
}

[TearDown]
public void TearDown()
{
PythonEngine.ReleaseLock(gs);
PythonEngine.Shutdown();
}

[Test]
public void TestOnPyList()
{
var list = new PyList();
list.Append(new PyString("foo"));
list.Append(new PyString("bar"));
list.Append(new PyString("baz"));
var result = new List<string>();
foreach (PyObject item in list)
using (Py.GIL())
{
result.Add(item.ToString());
var list = new PyList();
list.Append(new PyString("foo"));
list.Append(new PyString("bar"));
list.Append(new PyString("baz"));
var result = new List<string>();
foreach (PyObject item in list)
{
result.Add(item.ToString());
}
Assert.AreEqual(3, result.Count);
Assert.AreEqual("foo", result[0]);
Assert.AreEqual("bar", result[1]);
Assert.AreEqual("baz", result[2]);
}
Assert.AreEqual(3, result.Count);
Assert.AreEqual("foo", result[0]);
Assert.AreEqual("bar", result[1]);
Assert.AreEqual("baz", result[2]);
}
}
}
27 changes: 6 additions & 21 deletions src/embed_tests/pylong.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
using System;
using NUnit.Framework;
using Python.Runtime;

namespace Python.EmbeddingTest
{
[TestFixture]
public class PyLongTest
{
private IntPtr gs;

[SetUp]
public void SetUp()
{
PythonEngine.Initialize();
gs = PythonEngine.AcquireLock();
}

[TearDown]
public void TearDown()
{
PythonEngine.ReleaseLock(gs);
PythonEngine.Shutdown();
}

[Test]
public void TestToInt64()
{
long largeNumber = 8L * 1024L * 1024L * 1024L; // 8 GB
var pyLargeNumber = new PyLong(largeNumber);
Assert.AreEqual(largeNumber, pyLargeNumber.ToInt64());
using (Py.GIL())
{
long largeNumber = 8L * 1024L * 1024L * 1024L; // 8 GB
var pyLargeNumber = new PyLong(largeNumber);
Assert.AreEqual(largeNumber, pyLargeNumber.ToInt64());
}
}
}
}
25 changes: 5 additions & 20 deletions src/embed_tests/pyobject.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
using System;
using NUnit.Framework;
using Python.Runtime;

namespace Python.EmbeddingTest
{
[TestFixture]
public class PyObjectTest
{
private IntPtr gs;

[SetUp]
public void SetUp()
{
PythonEngine.Initialize();
gs = PythonEngine.AcquireLock();
}

[TearDown]
public void TearDown()
{
PythonEngine.ReleaseLock(gs);
PythonEngine.Shutdown();
}

[Test]
public void TestUnicode()
{
PyObject s = new PyString("foo\u00e9");
Assert.AreEqual("foo\u00e9", s.ToString());
using (Py.GIL())
{
PyObject s = new PyString("foo\u00e9");
Assert.AreEqual("foo\u00e9", s.ToString());
}
}
}
}
7 changes: 7 additions & 0 deletions src/embed_tests/pythonexception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Python.EmbeddingTest
{
/// <summary>
/// Test Python Exceptions
/// </summary>
/// <remarks>
/// Keeping this in the old-style SetUp/TearDown
/// to ensure that setup still works.
/// </remarks>
[TestFixture]
public class PythonExceptionTest
{
Expand Down