Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-python-testing-cabal-mock
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-python-testing-cabal-mock
Commits
dbd92b90
Commit
dbd92b90
authored
14 years ago
by
Michael Foord
Browse files
Options
Downloads
Patches
Plain Diff
Blank line additions
parent
8b3e9b7c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mock.py
+10
-0
10 additions, 0 deletions
mock.py
with
10 additions
and
0 deletions
mock.py
+
10
−
0
View file @
dbd92b90
...
...
@@ -181,10 +181,12 @@ sentinel = Sentinel()
DEFAULT
=
sentinel
.
DEFAULT
class
OldStyleClass
:
pass
ClassType
=
type
(
OldStyleClass
)
def
_copy
(
value
):
if
type
(
value
)
in
(
dict
,
list
,
tuple
,
set
):
return
type
(
value
)(
value
)
...
...
@@ -251,6 +253,7 @@ class Mock(object):
new
=
type
(
cls
.
__name__
,
(
cls
,),
{
'
__doc__
'
:
cls
.
__doc__
})
return
object
.
__new__
(
new
)
def
__init__
(
self
,
spec
=
None
,
side_effect
=
None
,
return_value
=
DEFAULT
,
wraps
=
None
,
name
=
None
,
spec_set
=
False
,
parent
=
None
):
self
.
_parent
=
parent
...
...
@@ -277,12 +280,14 @@ class Mock(object):
self
.
reset_mock
()
@property
def
__class__
(
self
):
if
self
.
_spec_class
is
None
:
return
type
(
self
)
return
self
.
_spec_class
def
reset_mock
(
self
):
"
Restore the mock object to its initial state.
"
self
.
called
=
False
...
...
@@ -359,6 +364,7 @@ class Mock(object):
return
self
.
_children
[
name
]
def
__repr__
(
self
):
if
self
.
_name
is
None
and
self
.
_spec_class
is
None
:
return
object
.
__repr__
(
self
)
...
...
@@ -386,6 +392,7 @@ class Mock(object):
spec_string
,
id
(
self
))
def
__setattr__
(
self
,
name
,
value
):
if
not
'
method_calls
'
in
self
.
__dict__
:
# allow all attribute setting until initialisation is complete
...
...
@@ -482,6 +489,7 @@ class callargs(tuple):
return
tuple
(
args_kwargs
)
==
(
other_args
,
other_kwargs
)
def
_dot_lookup
(
thing
,
comp
,
import_path
):
try
:
return
getattr
(
thing
,
comp
)
...
...
@@ -525,6 +533,7 @@ class _patch(object):
else
:
return
self
.
decorate_callable
(
func
)
def
decorate_class
(
self
,
klass
):
for
attr
in
dir
(
klass
):
attr_value
=
getattr
(
klass
,
attr
)
...
...
@@ -532,6 +541,7 @@ class _patch(object):
setattr
(
klass
,
attr
,
self
.
copy
()(
attr_value
))
return
klass
def
decorate_callable
(
self
,
func
):
if
hasattr
(
func
,
'
patchings
'
):
func
.
patchings
.
append
(
self
)
...
...
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