FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/tests/test_constructors.py at python3.14 · guywithface/pythonnet · GitHub
guywithface
/
pythonnet
Public
forked from
pythonnet/pythonnet
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
tests
/
test_constructors.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
102 lines (66 loc) · 2.2 KB
Breadcrumbs
pythonnet
/
tests
/
test_constructors.py
Copy path
File metadata and controls
102 lines (66 loc) · 2.2 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
# -*- coding: utf-8 -*-
"""Test CLR class constructor support."""
import
pytest
import
sys
import
System
def
test_enum_constructor
():
"""Test enum constructor args"""
from
System
import
TypeCode
from
Python
.
Test
import
EnumConstructorTest
ob
=
EnumConstructorTest
(
TypeCode
.
Int32
)
assert
ob
.
value
==
TypeCode
.
Int32
def
test_flags_constructor
():
"""Test flags constructor args"""
from
Python
.
Test
import
FlagsConstructorTest
from
System
.
IO
import
FileAccess
flags
=
FileAccess
.
Read
|
FileAccess
.
Write
ob
=
FlagsConstructorTest
(
flags
)
assert
ob
.
value
==
flags
def
test_struct_constructor
():
"""Test struct constructor args"""
from
System
import
Guid
from
Python
.
Test
import
StructConstructorTest
guid
=
Guid
.
NewGuid
()
ob
=
StructConstructorTest
(
guid
)
assert
ob
.
value
==
guid
def
test_datetime
():
inst
=
System
.
DateTime
(
2021
,
12
,
29
)
assert
inst
.
Year
==
2021
def
test_subclass_constructor
():
"""Test subclass constructor args"""
from
Python
.
Test
import
SubclassConstructorTest
class
Sub
(
System
.
Exception
):
pass
instance
=
Sub
()
ob
=
SubclassConstructorTest
(
instance
)
assert
isinstance
(
ob
.
value
,
System
.
Exception
)
def
test_multiple_constructor
():
from
Python
.
Test
import
MultipleConstructorsTest
# Test parameterless
ob
=
MultipleConstructorsTest
()
assert
ob
.
value
==
""
def
test_default_constructor_fallback
():
from
Python
.
Test
import
DefaultConstructorMatching
ob
=
DefaultConstructorMatching
(
2
)
assert
ob
.
a
==
2
with
pytest
.
raises
(
TypeError
):
ob
=
DefaultConstructorMatching
(
"2"
)
def
test_constructor_leak
():
from
System
import
Uri
from
Python
.
Runtime
import
Runtime
uri
=
Uri
(
"http://www.python.org"
)
Runtime
.
TryCollectingGarbage
(
20
)
ref_count
=
sys
.
getrefcount
(
uri
)
# check disabled due to GC uncertainty
# assert ref_count == 1
def
test_string_constructor
():
from
System
import
String
,
Char
,
Array
ob
=
String
(
'A'
,
10
)
assert
ob
==
'A'
*
10
arr
=
Array
[
Char
](
10
)
for
i
in
range
(
10
):
arr
[
i
]
=
Char
(
str
(
i
))
ob
=
String
(
arr
)
assert
ob
==
"0123456789"
ob
=
String
(
arr
,
5
,
4
)
assert
ob
==
"5678"
Back
|
FazBrowse Home
|
New Git URL