This repository was archived by the owner on Jul 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +65
-0
lines changed
Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 108108 </PropertyGroup >
109109 <ItemGroup >
110110 <Compile Include =" arraytest.cs" />
111+ <Compile Include =" callbacktest.cs" />
111112 <Compile Include =" classtest.cs" />
112113 <Compile Include =" constructortests.cs" />
113114 <Compile Include =" conversiontest.cs" />
127128 <Compile Include =" subclasstest.cs" />
128129 </ItemGroup >
129130 <ItemGroup >
131+ <Reference Include =" Microsoft.CSharp" />
130132 <Reference Include =" System" />
131133 <Reference Include =" System.Core" >
132134 <RequiredTargetFramework >3.5</RequiredTargetFramework >
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+
6+ namespace Python . Test
7+ {
8+ //========================================================================
9+ // Tests callbacks into python code.
10+ //========================================================================
11+
12+ public class CallbackTest
13+ {
14+ public string Call_simpleDefaultArg_WithNull ( string moduleName )
15+ {
16+ using ( Runtime . Py . GIL ( ) )
17+ {
18+ dynamic module = Runtime . Py . Import ( moduleName ) ;
19+ return module . simpleDefaultArg ( null ) ;
20+ }
21+ }
22+ public string Call_simpleDefaultArg_WithEmptyArgs ( string moduleName )
23+ {
24+ using ( Runtime . Py . GIL ( ) )
25+ {
26+ dynamic module = Runtime . Py . Import ( moduleName ) ;
27+ return module . simpleDefaultArg ( ) ;
28+ }
29+ }
30+ }
31+ }
Original file line number Diff line number Diff line change 33__all__ = ['test_suite' ]
44
55from .test_import import test_suite as import_tests
6+ from .test_callback import test_suite as callback_tests
67
78def test_suite ():
89 suite = unittest .TestSuite ()
910 suite .addTests ((import_tests (),))
11+ suite .addTests ((callback_tests (),))
1012 return suite
Original file line number Diff line number Diff line change 1+ import unittest , sys
2+ import clr
3+
4+ this_module = sys .modules [__name__ ]
5+ clr .AddReference ("Python.Test" )
6+ import Python .Test as Test
7+ from Python .Test import CallbackTest
8+ test_instance = CallbackTest ()
9+
10+ def simpleDefaultArg (arg = 'test' ):
11+ return arg
12+
13+ class CallbackTests (unittest .TestCase ):
14+ """Test that callbacks from C# into python work."""
15+
16+ def testDefaultForNull (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+ def testDefaultForNone (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+ def test_suite ():
29+ return unittest .makeSuite (CallbackTests )
30+
You can’t perform that action at this time.
0 commit comments