Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commit65626c3

Browse files
committed
add test for using null like 'None' for default arguments. See35cd5fa
1 parent8effe30 commit65626c3

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

‎src/testing/Python.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
</PropertyGroup>
109109
<ItemGroup>
110110
<CompileInclude="arraytest.cs" />
111+
<CompileInclude="callbacktest.cs" />
111112
<CompileInclude="classtest.cs" />
112113
<CompileInclude="constructortests.cs" />
113114
<CompileInclude="conversiontest.cs" />
@@ -127,6 +128,7 @@
127128
<CompileInclude="subclasstest.cs" />
128129
</ItemGroup>
129130
<ItemGroup>
131+
<ReferenceInclude="Microsoft.CSharp" />
130132
<ReferenceInclude="System" />
131133
<ReferenceInclude="System.Core">
132134
<RequiredTargetFramework>3.5</RequiredTargetFramework>

‎src/testing/callbacktest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
usingSystem;
2+
usingSystem.Collections.Generic;
3+
usingSystem.Linq;
4+
usingSystem.Text;
5+
6+
namespacePython.Test
7+
{
8+
//========================================================================
9+
// Tests callbacks into python code.
10+
//========================================================================
11+
12+
publicclassCallbackTest
13+
{
14+
publicstringCall_simpleDefaultArg_WithNull(stringmoduleName)
15+
{
16+
using(Runtime.Py.GIL())
17+
{
18+
dynamicmodule=Runtime.Py.Import(moduleName);
19+
returnmodule.simpleDefaultArg(null);
20+
}
21+
}
22+
publicstringCall_simpleDefaultArg_WithEmptyArgs(stringmoduleName)
23+
{
24+
using(Runtime.Py.GIL())
25+
{
26+
dynamicmodule=Runtime.Py.Import(moduleName);
27+
returnmodule.simpleDefaultArg();
28+
}
29+
}
30+
}
31+
}

‎src/tests/test_suite/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
__all__= ['test_suite']
44

55
from .test_importimporttest_suiteasimport_tests
6+
from .test_callbackimporttest_suiteascallback_tests
67

78
deftest_suite():
89
suite=unittest.TestSuite()
910
suite.addTests((import_tests(),))
11+
suite.addTests((callback_tests(),))
1012
returnsuite

‎src/tests/test_suite/test_callback.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
importunittest,sys
2+
importclr
3+
4+
this_module=sys.modules[__name__]
5+
clr.AddReference("Python.Test")
6+
importPython.TestasTest
7+
fromPython.TestimportCallbackTest
8+
test_instance=CallbackTest()
9+
10+
defsimpleDefaultArg(arg='test'):
11+
returnarg
12+
13+
classCallbackTests(unittest.TestCase):
14+
"""Test that callbacks from C# into python work."""
15+
16+
deftestDefaultForNull(self):
17+
"""Test that C# can use null for an optional python argument"""
18+
retVal=test_instance.Call_simpleDefaultArg_WithNull(__name__)
19+
pythonRetVal=simpleDefaultArg(None)
20+
self.assertEquals(retVal,pythonRetVal)
21+
22+
deftestDefaultForNone(self):
23+
"""Test that C# can use no argument for an optional python argument"""
24+
retVal=test_instance.Call_simpleDefaultArg_WithEmptyArgs(__name__)
25+
pythonRetVal=simpleDefaultArg()
26+
self.assertEquals(retVal,pythonRetVal)
27+
28+
deftest_suite():
29+
returnunittest.makeSuite(CallbackTests)
30+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp