8000 Incorrectly using a non-generic type with type parameters now produces a helpful Python error instead of throwing NullReferenceException by tminka · Pull Request #1326 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Incorrectly using a non-generic type with type parameters now produces a helpful Python error instead of throwing NullReferenceException #1326

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
Dec 18, 2020
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
Next Next commit
Moved the test to Python.
Added EmbeddedPythonTest with the capability to run any desired Python tests within NUnit.
  • Loading branch information
tminka committed Dec 18, 2020
commit 612c0ccdbed557f731669cf24e4124d8de3ed71e
22 changes: 15 additions & 7 deletions src/embed_tests/TestList.cs → src/embed_tests/TestPythonTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
Expand All @@ -8,7 +9,7 @@

namespace Python.EmbeddingTest
{
public class TestList
public class TestPythonTests
{
[OneTimeSetUp]
public void SetUp()
Expand All @@ -22,14 +23,21 @@ public void Dispose()
PythonEngine.Shutdown();
}

[Test]
public void MissingGenericTypeTest()
static IEnumerable<string[]> MyTestCases()
{
Assert.Throws<PythonException>(() =>
yield return new[] { "test_generic", "test_missing_generic_type" };
}

[TestCaseSource(nameof(MyTestCases))]
public void EmbeddedPythonTest(string testFile, string testName)
{
string folder = @"..\\..\\..\\..\\tests";
PythonEngine.Exec($@"
from System.Collections import IList
IList[bool]
"));
import sys
sys.path.insert(0, '{folder}')
from {testFile} import *
{testName}()
");
}
}
}
5 changes: 5 additions & 0 deletions src/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,8 @@ def test_nested_generic_class():
"""Check nested generic classes."""
# TODO NotImplemented
pass

def test_missing_generic_type():
from System.Collections import IList
with pytest.raises(TypeError):
IList[bool]
0