FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/tests/test_property.py at master · attackgithub/pythonnet · GitHub
attackgithub
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
tests
/
test_property.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
148 lines (98 loc) · 3.95 KB
Breadcrumbs
pythonnet
/
src
/
tests
/
test_property.py
Copy path
File metadata and controls
148 lines (98 loc) · 3.95 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# -*- coding: utf-8 -*-
"""Test CLR property support."""
import
pytest
from
Python
.
Test
import
PropertyTest
def
test_public_instance_property
():
"""Test public instance properties."""
ob
=
PropertyTest
()
assert
ob
.
PublicProperty
==
0
ob
.
PublicProperty
=
1
assert
ob
.
PublicProperty
==
1
with
pytest
.
raises
(
TypeError
):
del
PropertyTest
().
PublicProperty
def
test_public_static_property
():
"""Test public static properties."""
ob
=
PropertyTest
()
assert
PropertyTest
.
PublicStaticProperty
==
0
PropertyTest
.
PublicStaticProperty
=
1
assert
PropertyTest
.
PublicStaticProperty
==
1
assert
ob
.
PublicStaticProperty
==
1
ob
.
PublicStaticProperty
=
0
assert
ob
.
PublicStaticProperty
==
0
with
pytest
.
raises
(
TypeError
):
del
PropertyTest
.
PublicStaticProperty
with
pytest
.
raises
(
TypeError
):
del
PropertyTest
().
PublicStaticProperty
def
test_protected_instance_property
():
"""Test protected instance properties."""
ob
=
PropertyTest
()
assert
ob
.
ProtectedProperty
==
0
ob
.
ProtectedProperty
=
1
assert
ob
.
ProtectedProperty
==
1
with
pytest
.
raises
(
TypeError
):
del
PropertyTest
().
ProtectedProperty
def
test_protected_static_property
():
"""Test protected static properties."""
ob
=
PropertyTest
()
assert
PropertyTest
.
ProtectedStaticProperty
==
0
PropertyTest
.
ProtectedStaticProperty
=
1
assert
PropertyTest
.
ProtectedStaticProperty
==
1
assert
ob
.
ProtectedStaticProperty
==
1
ob
.
ProtectedStaticProperty
=
0
assert
ob
.
ProtectedStaticProperty
==
0
with
pytest
.
raises
(
TypeError
):
del
PropertyTest
.
ProtectedStaticProperty
with
pytest
.
raises
(
TypeError
):
del
PropertyTest
().
ProtectedStaticProperty
def
test_internal_property
():
"""Test internal properties."""
with
pytest
.
raises
(
AttributeError
):
_
=
PropertyTest
().
InternalProperty
with
pytest
.
raises
(
AttributeError
):
_
=
PropertyTest
().
InternalStaticProperty
with
pytest
.
raises
(
AttributeError
):
_
=
PropertyTest
.
InternalStaticProperty
def
test_private_property
():
"""Test private properties."""
with
pytest
.
raises
(
AttributeError
):
_
=
PropertyTest
().
PrivateProperty
with
pytest
.
raises
(
AttributeError
):
_
=
PropertyTest
().
PrivateStaticProperty
with
pytest
.
raises
(
AttributeError
):
_
=
PropertyTest
.
PrivateStaticProperty
def
test_property_descriptor_get_set
():
"""Test property descriptor get / set."""
# This test ensures that setting an attribute implemented with
# a descriptor actually goes through the descriptor (rather than
# silently replacing the descriptor in the instance or type dict.
ob
=
PropertyTest
()
assert
PropertyTest
.
PublicStaticProperty
==
0
assert
ob
.
PublicStaticProperty
==
0
descriptor
=
PropertyTest
.
__dict__
[
'PublicStaticProperty'
]
assert
type
(
descriptor
)
!=
int
ob
.
PublicStaticProperty
=
0
descriptor
=
PropertyTest
.
__dict__
[
'PublicStaticProperty'
]
assert
type
(
descriptor
)
!=
int
PropertyTest
.
PublicStaticProperty
=
0
descriptor
=
PropertyTest
.
__dict__
[
'PublicStaticProperty'
]
assert
type
(
descriptor
)
!=
int
def
test_property_descriptor_wrong_type
():
"""Test setting a property using a value of the wrong type."""
with
pytest
.
raises
(
TypeError
):
ob
=
PropertyTest
()
ob
.
PublicProperty
=
"spam"
def
test_property_descriptor_abuse
():
"""Test property descriptor abuse."""
desc
=
PropertyTest
.
__dict__
[
'PublicProperty'
]
with
pytest
.
raises
(
TypeError
):
desc
.
__get__
(
0
,
0
)
with
pytest
.
raises
(
TypeError
):
desc
.
__set__
(
0
,
0
)
def
test_interface_property
():
"""Test properties of interfaces. Added after a bug report
that an IsAbstract check was inappropriate and prevented
use of properties when only the interface is known."""
from
System
.
Collections
import
Hashtable
,
ICollection
mapping
=
Hashtable
()
coll
=
ICollection
(
mapping
)
assert
coll
.
Count
==
0
Back
|
FazBrowse Home
|
New Git URL