Skip to content

Some fixes. #219

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 6 commits into from
Jul 28, 2016
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
add test for using null like 'None' for default arguments. See 35cd5fa
  • Loading branch information
matthid committed Jun 23, 2016
commit 65626c3c5f8e82e7b51cccf92a86d51eb0dab444
2 changes: 2 additions & 0 deletions src/testing/Python.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="arraytest.cs" />
<Compile Include="callbacktest.cs" />
<Compile Include="classtest.cs" />
<Compile Include="constructortests.cs" />
<Compile Include="conversiontest.cs" />
Expand All @@ -127,6 +128,7 @@
<Compile Include="subclasstest.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
Expand Down
31 changes: 31 additions & 0 deletions src/testing/callbacktest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Python.Test
{
//========================================================================
// Tests callbacks into python code.
//========================================================================

public class CallbackTest
{
public string Call_simpleDefaultArg_WithNull(string moduleName)
{
using (Runtime.Py.GIL())
{
dynamic module = Runtime.Py.Import(moduleName);
return module.simpleDefaultArg(null);
}
}
public string Call_simpleDefaultArg_WithEmptyArgs(string moduleName)
{
using (Runtime.Py.GIL())
{
dynamic module = Runtime.Py.Import(moduleName);
return module.simpleDefaultArg();
}
}
}
}
2 changes: 2 additions & 0 deletions src/tests/test_suite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
__all__ = ['test_suite']

from .test_import import test_suite as import_tests
from .test_callback import test_suite as callback_tests

def test_suite():
suite = unittest.TestSuite()
suite.addTests((import_tests(),))
suite.addTests((callback_tests(),))
return suite
30 changes: 30 additions & 0 deletions src/tests/test_suite/test_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import unittest, sys
import clr

this_module = sys.modules[__name__]
clr.AddReference("Python.Test")
import Python.Test as Test
from Python.Test import CallbackTest
test_instance = CallbackTest()

def simpleDefaultArg(arg = 'test'):
return arg

class CallbackTests(unittest.TestCase):
"""Test that callbacks from C# into python work."""

def testDefaultForNull(self):
"""Test that C# can use null for an optional python argument"""
retVal = test_instance.Call_simpleDefaultArg_WithNull(__name__)
pythonRetVal = simpleDefaultArg(None)
self.assertEquals(retVal, pythonRetVal)

def testDefaultForNone(self):
"""Test that C# can use no argument for an optional python argument"""
retVal = test_instance.Call_simpleDefaultArg_WithEmptyArgs(__name__)
pythonRetVal = simpleDefaultArg()
self.assertEquals(retVal, pythonRetVal)

def test_suite():
return unittest.makeSuite(CallbackTests)