FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learning-python/test_reflection.py at master · rrees/learning-python · GitHub
rrees
/
learning-python
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
9
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
learning-python
/
test_reflection.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (27 loc) · 870 Bytes
Breadcrumbs
learning-python
/
test_reflection.py
Copy path
File metadata and controls
37 lines (27 loc) · 870 Bytes
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
import
unittest
from
collections
import
namedtuple
Point
=
namedtuple
(
'Point'
, [
'x'
,
'y'
])
class
PointClass
:
def
__init__
(
self
,
x
,
y
):
self
.
x
=
x
self
.
y
=
y
class
TestReflection
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
p
=
Point
(
9
,
15
)
self
.
pc
=
PointClass
(
23
,
4
)
self
.
all
=
[
self
.
p
,
self
.
pc
]
def
test_attribute_checking
(
self
):
for
item
in
self
.
all
:
self
.
assertTrue
(
hasattr
(
item
,
'x'
))
self
.
assertTrue
(
hasattr
(
item
,
'y'
))
self
.
assertFalse
(
hasattr
(
item
,
'b'
))
def
test_attribute_reading
(
self
):
for
item
in
self
.
all
:
self
.
assertEqual
(
getattr
(
item
,
'x'
),
item
.
x
)
self
.
assertEqual
(
getattr
(
item
,
'y'
),
item
.
y
)
def
test_attribute_setting
(
self
):
setattr
(
self
.
pc
,
'b'
,
3
)
self
.
assertTrue
(
hasattr
(
self
.
pc
,
'b'
))
self
.
assertEqual
(
getattr
(
self
.
pc
,
'b'
),
3
)
setattr
(
self
.
pc
,
'y'
,
14
)
self
.
assertEqual
(
getattr
(
self
.
pc
,
'y'
),
14
)
Back
|
FazBrowse Home
|
New Git URL