Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
f863e667
Commit
f863e667
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
weakfuncref tests
parent
79f88c45
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_weakfuncref.py
+72
-0
72 additions, 0 deletions
tests/test_weakfuncref.py
with
72 additions
and
0 deletions
tests/test_weakfuncref.py
0 → 100644
+
72
−
0
View file @
f863e667
#!/usr/bin/env python
#
# test_weakfuncref.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
fsl.utils.weakfuncref
as
weakfuncref
def
make_weakfuncref_that_will_get_gcd
():
def
thefunc
():
pass
return
weakfuncref
.
WeakFunctionRef
(
thefunc
)
def
make_weakfuncref_method_that_will_get_gcd
():
class
Thing
(
object
):
def
method
(
self
):
pass
return
weakfuncref
.
WeakFunctionRef
(
Thing
.
method
)
def
test_weakfuncref_function
():
def
func
():
pass
non_gcd_func
=
weakfuncref
.
WeakFunctionRef
(
func
)
gcd_func
=
make_weakfuncref_that_will_get_gcd
()
assert
gcd_func
.
function
()
is
None
assert
non_gcd_func
.
function
()
is
func
def
test_weakfuncref_method
():
class
Thing
(
object
):
def
method
(
self
):
return
'
existent!
'
def
__priv_method
(
self
):
return
'
existent!
'
@classmethod
def
clsmethod
(
clsself
):
return
'
existent!
'
t
=
Thing
()
gcd_methref
=
make_weakfuncref_that_will_get_gcd
()
methref
=
weakfuncref
.
WeakFunctionRef
(
t
.
method
)
privmethref
=
weakfuncref
.
WeakFunctionRef
(
t
.
_Thing__priv_method
)
clsmethref
=
weakfuncref
.
WeakFunctionRef
(
t
.
clsmethod
)
assert
gcd_methref
.
function
()
is
None
assert
privmethref
.
function
()()
==
'
existent!
'
assert
methref
.
function
()()
==
'
existent!
'
assert
clsmethref
.
function
()()
==
'
existent!
'
print
(
gcd_methref
)
print
(
methref
)
t
=
None
assert
methref
.
function
()
is
None
assert
privmethref
.
function
()
is
None
assert
clsmethref
.
function
()()
==
'
existent!
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment