Skip to content

Commit c8c8d8c

Browse files
committed
merged extra tests
2 parents 2a2c9c7 + bde4258 commit c8c8d8c

File tree

7 files changed

+132
-13
lines changed

7 files changed

+132
-13
lines changed

pythonnet.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25123.0
4+
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Runtime", "src\runtime\Python.Runtime.csproj", "{097B4AC0-74E9-4C58-BCF8-C69746EC8271}"
77
EndProject

src/clrmodule/clrmodule.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
108108
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
109109
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
110-
<DefineConstants>PYTHON34;UCS2</DefineConstants>
110+
<DefineConstants>PYTHON35,UCS2</DefineConstants>
111111
</PropertyGroup>
112112
<ItemGroup>
113113
<Reference Include="RGiesecke.DllExport.Metadata">

src/runtime/Python.Runtime.csproj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
</PropertyGroup>
1414
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|x86'">
1515
<OutputPath>bin\x86\ReleaseMono\</OutputPath>
16-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS4</DefineConstants>
16+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON35, UCS4</DefineConstants>
1717
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1818
<Optimize>true</Optimize>
1919
<DebugType>pdbonly</DebugType>
2020
<PlatformTarget>x86</PlatformTarget>
2121
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
2222
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
23-
<DefineConstants>PYTHON27,UCS2</DefineConstants>
23+
<DefineConstants>PYTHON35,UCS2</DefineConstants>
2424
</PropertyGroup>
2525
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|x64'">
2626
<OutputPath>bin\x64\ReleaseMono\</OutputPath>
27-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS4</DefineConstants>
27+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON35, UCS4</DefineConstants>
2828
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2929
<Optimize>true</Optimize>
3030
<DebugType>pdbonly</DebugType>
@@ -34,7 +34,7 @@
3434
</PropertyGroup>
3535
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseWin|x86'">
3636
<OutputPath>bin\x86\ReleaseWin\</OutputPath>
37-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS2</DefineConstants>
37+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON35, UCS2</DefineConstants>
3838
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3939
<Optimize>true</Optimize>
4040
<DebugType>pdbonly</DebugType>
@@ -44,19 +44,19 @@
4444
</PropertyGroup>
4545
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseWin|x64'">
4646
<OutputPath>bin\x64\ReleaseWin\</OutputPath>
47-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS2</DefineConstants>
47+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON35, UCS2</DefineConstants>
4848
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4949
<Optimize>true</Optimize>
5050
<DebugType>pdbonly</DebugType>
5151
<PlatformTarget>x64</PlatformTarget>
5252
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
5353
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
54-
<DefineConstants>PYTHON34, UCS2</DefineConstants>
54+
<DefineConstants>PYTHON35,UCS2</DefineConstants>
5555
</PropertyGroup>
5656
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x86'">
5757
<DebugSymbols>true</DebugSymbols>
5858
<OutputPath>bin\x86\DebugMono\</OutputPath>
59-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS4</DefineConstants>
59+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON35,UCS4</DefineConstants>
6060
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6161
<Optimize>false</Optimize>
6262
<DebugType>full</DebugType>
@@ -68,7 +68,7 @@
6868
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x64'">
6969
<DebugSymbols>true</DebugSymbols>
7070
<OutputPath>bin\x64\DebugMono\</OutputPath>
71-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS4</DefineConstants>
71+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON35,UCS4</DefineConstants>
7272
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7373
<Optimize>false</Optimize>
7474
<DebugType>full</DebugType>
@@ -77,7 +77,7 @@
7777
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x86'">
7878
<DebugSymbols>true</DebugSymbols>
7979
<OutputPath>bin\x86\DebugWin\</OutputPath>
80-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
80+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON35,UCS2</DefineConstants>
8181
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8282
<Optimize>false</Optimize>
8383
<DebugType>full</DebugType>
@@ -89,11 +89,12 @@
8989
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x64'">
9090
<DebugSymbols>true</DebugSymbols>
9191
<OutputPath>bin\x64\DebugWin\</OutputPath>
92-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
92+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON35,UCS2</DefineConstants>
9393
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9494
<Optimize>false</Optimize>
9595
<DebugType>full</DebugType>
9696
<PlatformTarget>x64</PlatformTarget>
97+
<DefineConstants>TRACE;DEBUG;PYTHON35,UCS2</DefineConstants>
9798
</PropertyGroup>
9899
<Choose>
99100
<When Condition=" '$(Configuration)'=='DebugMono' ">

src/testing/constructortests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,36 @@ public SubclassConstructorTest(Exception v)
7171
this.value = v;
7272
}
7373
}
74+
public class ToDoubleConstructorTest
75+
{
76+
public ToDoubleConstructorTest()
77+
{
78+
//Just default values
79+
}
80+
public ToDoubleConstructorTest(string a, double b,string c)
81+
{
82+
this.a = a;
83+
this.b = b;
84+
this.c = c;
85+
}
86+
public string a;
87+
public double b;
88+
public string c;
89+
}
90+
public class ToFloatConstructorTest
91+
{
92+
public ToFloatConstructorTest()
93+
{
94+
// just default values.
95+
}
96+
public ToFloatConstructorTest(string a, float b, string c)
97+
{
98+
this.a = a;
99+
this.b = b;
100+
this.c = c;
101+
}
102+
public string a;
103+
public float b;
104+
public string c;
105+
}
74106
}

src/testing/methodtest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ public Guid TestStructConversion(Guid v)
7373
{
7474
return v;
7575
}
76+
/// <summary>
77+
/// Method to support testing
78+
/// simple promotion of numeric types:
79+
///
80+
/// integer types -> double
81+
///
82+
/// </summary>
83+
/// <param name="a"></param>
84+
/// <param name="b"></param>
85+
/// <returns></returns>
86+
public double TestSimpleIntToDoubleTypePromotion(double a, double b)
87+
{
88+
return a + b;
89+
}
90+
public float TestSimpleIntToFloatTypePromotion(float a, float b)
91+
{
92+
return a + b;
93+
}
7694

7795
public Exception TestSubclassConversion(Exception v)
7896
{

src/tests/test_constructors.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class sub(System.Exception):
4444

4545
instance = sub()
4646
ob = SubclassConstructorTest(instance)
47-
print(ob)
4847
self.assertTrue(isinstance(ob.value, System.Exception))
4948

49+
5050
def testConstructorArgumentMatching(self):
5151
""" Test that simple type promitions works for int->double """
5252
from Python.Test import AConstrucorTest, LinkConstructorTest
@@ -60,6 +60,25 @@ def testConstructorArgumentMatching(self):
6060
self.assertEqual(l1.a2.name, a2.name)
6161
self.assertAlmostEqual(3000.0,l1.MatchMe)
6262

63+
def testIntToDoubleConstructorArguments(self):
64+
from Python.Test import ToDoubleConstructorTest
65+
66+
o = ToDoubleConstructorTest('a',2,'c')
67+
self.assertEqual(o.a,'a')
68+
self.assertAlmostEqual(o.b,2)
69+
self.assertEqual(o.c,'c')
70+
71+
o = ToDoubleConstructorTest()
72+
73+
def testIntToFloatConstructorArguments(self):
74+
from Python.Test import ToFloatConstructorTest
75+
76+
o = ToFloatConstructorTest('a',2,'c')
77+
self.assertEqual(o.a,'a')
78+
self.assertAlmostEqual(o.b,2)
79+
self.assertEqual(o.c,'c')
80+
81+
o = ToFloatConstructorTest()
6382

6483
def test_suite():
6584
return unittest.makeSuite(ConstructorTests)

src/tests/test_method.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,55 @@ def testMethodCallFlagsConversion(self):
208208
r = object.TestFlagsConversion(flags)
209209
self.assertTrue(r == flags)
210210

211+
def testSimpleTypePromotionIntToDouble(self):
212+
object = MethodTest()
213+
try:
214+
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2,2)
215+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
216+
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2.0,2)
217+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
218+
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2,2.0)
219+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
220+
sum_of_a_plus_b = object.TestSimpleIntToDoubleTypePromotion(2.0,2.0)
221+
self.assertAlmostEqual(sum_of_a_plus_b,2.0+2.0)
222+
except:
223+
self.assertTrue(False,"Type promotion from int to double failed")
224+
225+
try:
226+
should_fail = object.TestSimpleIntToDoubleTypePromotion(2,'2.0')
227+
self.assertTrue(False,"the promotion of string to double should fail")
228+
except:
229+
pass
230+
try:
231+
should_fail = object.TestSimpleIntToDoubleTypePromotion(2,True)
232+
self.assertTrue(False,"the promotion of boolean to double should fail")
233+
except:
234+
pass
235+
236+
def testSimpleTypePromotionIntToFloat(self):
237+
object = MethodTest()
238+
try:
239+
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2,2)
240+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
241+
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2.0,2)
242+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
243+
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2,2.0)
244+
self.assertAlmostEqual(sum_of_a_plus_b,2+2)
245+
sum_of_a_plus_b = object.TestSimpleIntToFloatTypePromotion(2.0,2.0)
246+
self.assertAlmostEqual(sum_of_a_plus_b,2.0+2.0)
247+
except:
248+
self.assertTrue(False,"Type promotion from int to float failed")
249+
try:
250+
should_fail = object.TestSimpleIntToFloatTypePromotion(2,'2.0')
251+
self.assertTrue(False,"the promotion of string to float should fail")
252+
except:
253+
pass
254+
try:
255+
should_fail = object.TestSimpleIntToFloatTypePromotion(2,True)
256+
self.assertTrue(False,"the promotion of boolean to float should fail")
257+
except:
258+
pass
259+
211260
def testMethodCallStructConversion(self):
212261
"""Test struct conversion in method call."""
213262
from System import Guid

0 commit comments

Comments
 (0)