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

Commit88f2cfa

Browse files
committed
Refactor Converter.ToPrimitive
1 parent950676f commit88f2cfa

File tree

2 files changed

+236
-219
lines changed

2 files changed

+236
-219
lines changed

‎src/embed_tests/TestConverter.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
usingSystem;
22
usingSystem.Collections.Generic;
33
usingNUnit.Framework;
4+
45
usingPython.Runtime;
56

7+
usingPyRuntime=Python.Runtime.Runtime;
8+
69
namespacePython.EmbeddingTest
710
{
811
publicclassTestConverter
912
{
13+
staticreadonlyType[]_numTypes=newType[]
14+
{
15+
typeof(short),
16+
typeof(ushort),
17+
typeof(int),
18+
typeof(uint),
19+
typeof(long),
20+
typeof(ulong)
21+
};
22+
1023
[OneTimeSetUp]
1124
publicvoidSetUp()
1225
{
@@ -47,6 +60,55 @@ public void TestConvertDoubleToManaged(
4760
Assert.IsTrue(((double)convertedValue).Equals(testValue));
4861
}
4962

63+
[Test]
64+
publicvoidCovertTypeError()
65+
{
66+
using(vars=newPyString("abc"))
67+
{
68+
foreach(vartypein_numTypes)
69+
{
70+
objectvalue;
71+
try
72+
{
73+
boolres=Converter.ToManaged(s.Handle,type,outvalue,true);
74+
Assert.IsFalse(res);
75+
varbo=Exceptions.ExceptionMatches(Exceptions.TypeError);
76+
Assert.IsTrue(Exceptions.ExceptionMatches(Exceptions.TypeError)
77+
||Exceptions.ExceptionMatches(Exceptions.ValueError));
78+
}
79+
finally
80+
{
81+
Exceptions.Clear();
82+
}
83+
}
84+
}
85+
}
86+
87+
[Test]
88+
publicvoidConvertOverflow()
89+
{
90+
using(varnum=newPyLong(ulong.MaxValue))
91+
{
92+
IntPtrlargeNum=PyRuntime.PyNumber_Add(num.Handle,num.Handle);
93+
try
94+
{
95+
objectvalue;
96+
foreach(vartypein_numTypes)
97+
{
98+
boolres=Converter.ToManaged(largeNum,type,outvalue,true);
99+
Assert.IsFalse(res);
100+
Assert.IsTrue(Exceptions.ExceptionMatches(Exceptions.OverflowError));
101+
Exceptions.Clear();
102+
}
103+
}
104+
finally
105+
{
106+
Exceptions.Clear();
107+
PyRuntime.XDecref(largeNum);
108+
}
109+
}
110+
}
111+
50112
[Test]
51113
publicvoidRawListProxy()
52114
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp