FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/embed_tests/CodecGroups.cs at master · sdpython/pythonnet · GitHub
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
sdpython
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
CodecGroups.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
132 lines (117 loc) · 4.65 KB
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
CodecGroups.cs
Copy path
File metadata and controls
132 lines (117 loc) · 4.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
namespace
Python
.
EmbeddingTest
{
using
System
;
using
System
.
Linq
;
using
NUnit
.
Framework
;
using
Python
.
Runtime
;
using
Python
.
Runtime
.
Codecs
;
public
class
CodecGroups
{
[
Test
]
public
void
GetEncodersByType
(
)
{
var
encoder1
=
new
ObjectToEncoderInstanceEncoder
<
Uri
>
(
)
;
var
encoder2
=
new
ObjectToEncoderInstanceEncoder
<
Uri
>
(
)
;
var
group
=
new
EncoderGroup
{
new
ObjectToEncoderInstanceEncoder
<
Tuple
<
int
>
>
(
)
,
encoder1
,
encoder2
,
}
;
var
got
=
group
.
GetEncoders
(
typeof
(
Uri
)
)
.
ToArray
(
)
;
CollectionAssert
.
AreEqual
(
new
[
]
{
encoder1
,
encoder2
}
,
got
)
;
}
[
Test
]
public
void
CanEncode
(
)
{
var
group
=
new
EncoderGroup
{
new
ObjectToEncoderInstanceEncoder
<
Tuple
<
int
>
>
(
)
,
new
ObjectToEncoderInstanceEncoder
<
Uri
>
(
)
,
}
;
Assert
.
IsTrue
(
group
.
CanEncode
(
typeof
(
Tuple
<
int
>
)
)
)
;
Assert
.
IsTrue
(
group
.
CanEncode
(
typeof
(
Uri
)
)
)
;
Assert
.
IsFalse
(
group
.
CanEncode
(
typeof
(
string
)
)
)
;
}
[
Test
]
public
void
Encodes
(
)
{
var
encoder0
=
new
ObjectToEncoderInstanceEncoder
<
Tuple
<
int
>
>
(
)
;
var
encoder1
=
new
ObjectToEncoderInstanceEncoder
<
Uri
>
(
)
;
var
encoder2
=
new
ObjectToEncoderInstanceEncoder
<
Uri
>
(
)
;
var
group
=
new
EncoderGroup
{
encoder0
,
encoder1
,
encoder2
,
}
;
var
uri
=
group
.
TryEncode
(
new
Uri
(
"data:"
)
)
;
var
clrObject
=
(
CLRObject
)
ManagedType
.
GetManagedObject
(
uri
.
Handle
)
;
Assert
.
AreSame
(
encoder1
,
clrObject
.
inst
)
;
Assert
.
AreNotSame
(
encoder2
,
clrObject
.
inst
)
;
var
tuple
=
group
.
TryEncode
(
Tuple
.
Create
(
1
)
)
;
clrObject
=
(
CLRObject
)
ManagedType
.
GetManagedObject
(
tuple
.
Handle
)
;
Assert
.
AreSame
(
encoder0
,
clrObject
.
inst
)
;
}
[
Test
]
public
void
GetDecodersByTypes
(
)
{
var
pyint
=
new
PyInt
(
10
)
.
GetPythonType
(
)
;
var
pyfloat
=
new
PyFloat
(
10
)
.
GetPythonType
(
)
;
var
pystr
=
new
PyString
(
"world"
)
.
GetPythonType
(
)
;
var
decoder1
=
new
DecoderReturningPredefinedValue
<
long
>
(
pyint
,
decodeResult
:
42
)
;
var
decoder2
=
new
DecoderReturningPredefinedValue
<
string
>
(
pyfloat
,
decodeResult
:
"atad:"
)
;
var
group
=
new
DecoderGroup
{
decoder1
,
decoder2
,
}
;
var
decoder
=
group
.
GetDecoder
(
pyfloat
,
typeof
(
string
)
)
;
Assert
.
AreSame
(
decoder2
,
decoder
)
;
decoder
=
group
.
GetDecoder
(
pystr
,
typeof
(
string
)
)
;
Assert
.
IsNull
(
decoder
)
;
decoder
=
group
.
GetDecoder
(
pyint
,
typeof
(
long
)
)
;
Assert
.
AreSame
(
decoder1
,
decoder
)
;
}
[
Test
]
public
void
CanDecode
(
)
{
var
pyint
=
new
PyInt
(
10
)
.
GetPythonType
(
)
;
var
pyfloat
=
new
PyFloat
(
10
)
.
GetPythonType
(
)
;
var
pystr
=
new
PyString
(
"world"
)
.
GetPythonType
(
)
;
var
decoder1
=
new
DecoderReturningPredefinedValue
<
long
>
(
pyint
,
decodeResult
:
42
)
;
var
decoder2
=
new
DecoderReturningPredefinedValue
<
string
>
(
pyfloat
,
decodeResult
:
"atad:"
)
;
var
group
=
new
DecoderGroup
{
decoder1
,
decoder2
,
}
;
Assert
.
IsTrue
(
group
.
CanDecode
(
pyint
,
typeof
(
long
)
)
)
;
Assert
.
IsFalse
(
group
.
CanDecode
(
pyint
,
typeof
(
int
)
)
)
;
Assert
.
IsTrue
(
group
.
CanDecode
(
pyfloat
,
typeof
(
string
)
)
)
;
Assert
.
IsFalse
(
group
.
CanDecode
(
pystr
,
typeof
(
string
)
)
)
;
}
[
Test
]
public
void
Decodes
(
)
{
var
pyint
=
new
PyInt
(
10
)
.
GetPythonType
(
)
;
var
pyfloat
=
new
PyFloat
(
10
)
.
GetPythonType
(
)
;
var
decoder1
=
new
DecoderReturningPredefinedValue
<
long
>
(
pyint
,
decodeResult
:
42
)
;
var
decoder2
=
new
DecoderReturningPredefinedValue
<
string
>
(
pyfloat
,
decodeResult
:
"atad:"
)
;
var
group
=
new
DecoderGroup
{
decoder1
,
decoder2
,
}
;
Assert
.
IsTrue
(
group
.
TryDecode
(
new
PyInt
(
10
)
,
out
long
longResult
)
)
;
Assert
.
AreEqual
(
42
,
longResult
)
;
Assert
.
IsTrue
(
group
.
TryDecode
(
new
PyFloat
(
10
)
,
out
string
strResult
)
)
;
Assert
.
AreSame
(
"atad:"
,
strResult
)
;
Assert
.
IsFalse
(
group
.
TryDecode
(
new
PyInt
(
10
)
,
out
int
_
)
)
;
}
[
SetUp
]
public
void
SetUp
(
)
{
PythonEngine
.
Initialize
(
)
;
}
[
TearDown
]
public
void
Dispose
(
)
{
PythonEngine
.
Shutdown
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL