- Notifications
You must be signed in to change notification settings - Fork768
Implement named arguments and With semantics in C# embedding side#461
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
73c40fc500d3d335a7dc6c3c1c566c27e84a31c59066864ad93b1bda9f1c378File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| using System; | ||
| using NUnit.Framework; | ||
| using Python.Runtime; | ||
| namespace Python.EmbeddingTest | ||
| { | ||
| public class TestPyWith | ||
| { | ||
| [OneTimeSetUp] | ||
| public void SetUp() | ||
| { | ||
| PythonEngine.Initialize(); | ||
| } | ||
| [OneTimeTearDown] | ||
| public void Dispose() | ||
| { | ||
| PythonEngine.Shutdown(); | ||
| } | ||
| /// <summary> | ||
| /// Test that exception is raised in context manager that ignores it. | ||
| /// </summary> | ||
| [Test] | ||
| public void TestPositiveWith() | ||
| { | ||
| var locals = new PyDict(); | ||
| PythonEngine.Exec(@" | ||
| class cmTest: | ||
| ||
| def __enter__(self): | ||
| print('Enter') | ||
| return self | ||
| def __exit__(self, t, v, tb): | ||
| # Exception not handled, return will be False | ||
| print('Exit') | ||
| def fail(self): | ||
| return 5 / 0 | ||
| a = cmTest() | ||
| ", null, locals.Handle); | ||
| var a = locals.GetItem("a"); | ||
| try | ||
| { | ||
| Py.With(a, cmTest => | ||
| { | ||
| cmTest.fail(); | ||
| }); | ||
| } | ||
| catch (PythonException e) | ||
| { | ||
| Assert.IsTrue(e.Message.Contains("division by zero")); | ||
| } | ||
| } | ||
| /// <summary> | ||
| /// Test that exception is not raised in context manager that handles it | ||
| /// </summary> | ||
| [Test] | ||
| public void TestNegativeWith() | ||
| { | ||
| var locals = new PyDict(); | ||
| PythonEngine.Exec(@" | ||
| class cmTest: | ||
| def __enter__(self): | ||
| print('Enter') | ||
| return self | ||
| def __exit__(self, t, v, tb): | ||
| # Signal exception is handled by returning true | ||
| return True | ||
| def fail(self): | ||
| return 5 / 0 | ||
| a = cmTest() | ||
| ", null, locals.Handle); | ||
| var a = locals.GetItem("a"); | ||
| Py.With(a, cmTest => | ||
| { | ||
| cmTest.fail(); | ||
| }); | ||
| } | ||
| } | ||
| } | ||