Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
cc52bac9
Commit
cc52bac9
authored
Jul 22, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up and extend test to assert call dependencies between __getattr__() and __getattribute__()
parent
df19f619
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
289 additions
and
74 deletions
+289
-74
tests/run/__getattribute__.pyx
tests/run/__getattribute__.pyx
+48
-3
tests/run/__getattribute_subclasses__.pyx
tests/run/__getattribute_subclasses__.pyx
+241
-71
No files found.
tests/run/__getattribute__.pyx
View file @
cc52bac9
__doc__
=
u"""
# mode: run
__getattribute__ and __getattr__ special methods for a single class.
"""
# __getattribute__ and __getattr__ special methods for a single class.
cdef
class
just_getattribute
:
cdef
class
just_getattribute
:
"""
"""
>>> a = just_getattribute()
>>> a = just_getattribute()
>>> a.called
1
>>> a.called
2
>>> a.bar
>>> a.bar
'bar'
'bar'
>>> a.called
4
>>> a.invalid
>>> a.invalid
Traceback (most recent call last):
Traceback (most recent call last):
AttributeError
AttributeError
>>> a.called
6
"""
"""
cdef
readonly
int
called
def
__getattribute__
(
self
,
n
):
def
__getattribute__
(
self
,
n
):
self
.
called
+=
1
if
n
==
'bar'
:
if
n
==
'bar'
:
return
n
return
n
elif
n
==
'called'
:
return
self
.
called
else
:
else
:
raise
AttributeError
raise
AttributeError
cdef
class
just_getattr
:
cdef
class
just_getattr
:
"""
"""
>>> a = just_getattr()
>>> a = just_getattr()
>>> a.called
0
>>> a.called
0
>>> a.foo
>>> a.foo
10
10
>>> a.called
0
>>> a.bar
>>> a.bar
'bar'
'bar'
>>> a.called
1
>>> a.invalid
>>> a.invalid
Traceback (most recent call last):
Traceback (most recent call last):
AttributeError
AttributeError
>>> a.called
2
"""
"""
cdef
readonly
int
called
cdef
readonly
int
foo
cdef
readonly
int
foo
def
__init__
(
self
):
def
__init__
(
self
):
self
.
foo
=
10
self
.
foo
=
10
def
__getattr__
(
self
,
n
):
def
__getattr__
(
self
,
n
):
self
.
called
+=
1
if
n
==
'bar'
:
if
n
==
'bar'
:
return
n
return
n
else
:
else
:
raise
AttributeError
raise
AttributeError
cdef
class
both
:
cdef
class
both
:
"""
"""
>>> a = both()
>>> a = both()
>>> (a.called_getattr, a.called_getattribute)
(0, 2)
>>> a.foo
>>> a.foo
10
10
>>> (a.called_getattr, a.called_getattribute)
(0, 5)
>>> a.bar
>>> a.bar
'bar'
'bar'
>>> (a.called_getattr, a.called_getattribute)
(1, 8)
>>> a.invalid
>>> a.invalid
Traceback (most recent call last):
Traceback (most recent call last):
AttributeError
AttributeError
>>> (a.called_getattr, a.called_getattribute)
(2, 11)
"""
"""
cdef
readonly
int
called_getattribute
cdef
readonly
int
called_getattr
cdef
readonly
int
foo
cdef
readonly
int
foo
def
__init__
(
self
):
def
__init__
(
self
):
self
.
foo
=
10
self
.
foo
=
10
def
__getattribute__
(
self
,
n
):
def
__getattribute__
(
self
,
n
):
self
.
called_getattribute
+=
1
if
n
==
'foo'
:
if
n
==
'foo'
:
return
self
.
foo
return
self
.
foo
elif
n
==
'called_getattribute'
:
return
self
.
called_getattribute
elif
n
==
'called_getattr'
:
return
self
.
called_getattr
else
:
else
:
raise
AttributeError
raise
AttributeError
def
__getattr__
(
self
,
n
):
def
__getattr__
(
self
,
n
):
self
.
called_getattr
+=
1
if
n
==
'bar'
:
if
n
==
'bar'
:
return
n
return
n
else
:
else
:
...
...
tests/run/__getattribute_subclasses__.pyx
View file @
cc52bac9
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment