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
4b4c915a
Commit
4b4c915a
authored
13 years ago
by
Michael Foord
Browse files
Options
Downloads
Patches
Plain Diff
Adding PropertyMock
parent
8f1cda09
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/changelog.txt
+1
-0
1 addition, 0 deletions
docs/changelog.txt
mock.py
+8
-0
8 additions, 0 deletions
mock.py
tests/testhelpers.py
+18
-1
18 additions, 1 deletion
tests/testhelpers.py
with
27 additions
and
1 deletion
docs/changelog.txt
+
1
−
0
View file @
4b4c915a
...
@@ -15,6 +15,7 @@ The standard library version!
...
@@ -15,6 +15,7 @@ The standard library version!
* Added the `mock_open` helper function for mocking open as a context manager
* Added the `mock_open` helper function for mocking open as a context manager
* `__class__` is assignable, so a mock can pass an `isinstance` check without
* `__class__` is assignable, so a mock can pass an `isinstance` check without
requiring a spec
requiring a spec
* Addition of `PropertyMock`
2012/02/13 Version 0.8.0
2012/02/13 Version 0.8.0
...
...
This diff is collapsed.
Click to expand it.
mock.py
+
8
−
0
View file @
4b4c915a
...
@@ -26,6 +26,7 @@ __all__ = (
...
@@ -26,6 +26,7 @@ __all__ = (
'
NonCallableMock
'
,
'
NonCallableMock
'
,
'
NonCallableMagicMock
'
,
'
NonCallableMagicMock
'
,
'
mock_open
'
,
'
mock_open
'
,
'
PropertyMock
'
,
)
)
...
@@ -2239,3 +2240,10 @@ def mock_open(mock=None, read_data=None):
...
@@ -2239,3 +2240,10 @@ def mock_open(mock=None, read_data=None):
mock
.
return_value
=
handle
mock
.
return_value
=
handle
return
mock
return
mock
class
PropertyMock
(
Mock
):
"""
A Mock variant with __get__ and __set__ methods to act as a property
"""
def
__get__
(
self
,
obj
,
obj_type
):
return
self
()
def
__set__
(
self
,
obj
,
val
):
self
(
val
)
This diff is collapsed.
Click to expand it.
tests/testhelpers.py
+
18
−
1
View file @
4b4c915a
...
@@ -6,7 +6,7 @@ from tests.support import unittest2, inPy3k
...
@@ -6,7 +6,7 @@ from tests.support import unittest2, inPy3k
from
mock
import
(
from
mock
import
(
call
,
_Call
,
create_autospec
,
MagicMock
,
call
,
_Call
,
create_autospec
,
MagicMock
,
Mock
,
ANY
,
_CallList
,
patch
Mock
,
ANY
,
_CallList
,
patch
,
PropertyMock
)
)
from
datetime
import
datetime
from
datetime
import
datetime
...
@@ -863,6 +863,23 @@ class TestCallList(unittest2.TestCase):
...
@@ -863,6 +863,23 @@ class TestCallList(unittest2.TestCase):
self
.
assertEqual
(
str
(
mock
.
mock_calls
),
expected
)
self
.
assertEqual
(
str
(
mock
.
mock_calls
),
expected
)
def
test_propertymock
(
self
):
p
=
patch
(
'
%s.SomeClass.one
'
%
__name__
,
new_callable
=
PropertyMock
)
mock
=
p
.
start
()
try
:
SomeClass
.
one
mock
.
assert_called_once_with
()
s
=
SomeClass
()
s
.
one
mock
.
assert_called_with
()
self
.
assertEqual
(
mock
.
mock_calls
,
[
call
(),
call
()])
s
.
one
=
3
self
.
assertEqual
(
mock
.
mock_calls
,
[
call
(),
call
(),
call
(
3
)])
finally
:
p
.
stop
()
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
unittest2
.
main
()
unittest2
.
main
()
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