Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c287062f
Kaydet (Commit)
c287062f
authored
Nis 13, 2012
tarafından
Michael Foord
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
unittest.mock.PropertyMock return value and attributes are now standard MagicMocks
üst
633b32a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
0 deletions
+25
-0
unittest.mock.rst
Doc/library/unittest.mock.rst
+11
-0
mock.py
Lib/unittest/mock.py
+3
-0
testhelpers.py
Lib/unittest/test/testmock/testhelpers.py
+11
-0
No files found.
Doc/library/unittest.mock.rst
Dosyayı görüntüle @
c287062f
...
...
@@ -712,6 +712,17 @@ have to create a dictionary and unpack it using `**`:
>>> mock_foo.mock_calls
[call(), call(6)]
Because of the way mock attributes are stored you can't directly attach a
`PropertyMock` to a mock object. Instead you can attach it to the mock type
object::
>>> m = MagicMock()
>>> p = PropertyMock(return_value=3)
>>> type(m).foo = p
>>> m.foo
3
>>> p.assert_called_once_with()
Calling
~~~~~~~
...
...
Lib/unittest/mock.py
Dosyayı görüntüle @
c287062f
...
...
@@ -2166,6 +2166,9 @@ class PropertyMock(Mock):
Fetching a `PropertyMock` instance from an object calls the mock, with
no args. Setting it calls the mock with the value being set.
"""
def
_get_child_mock
(
self
,
**
kwargs
):
return
MagicMock
(
**
kwargs
)
def
__get__
(
self
,
obj
,
obj_type
):
return
self
()
def
__set__
(
self
,
obj
,
val
):
...
...
Lib/unittest/test/testmock/testhelpers.py
Dosyayı görüntüle @
c287062f
...
...
@@ -831,5 +831,16 @@ class TestCallList(unittest.TestCase):
p
.
stop
()
def
test_propertymock_returnvalue
(
self
):
m
=
MagicMock
()
p
=
PropertyMock
()
type
(
m
)
.
foo
=
p
returned
=
m
.
foo
p
.
assert_called_once_with
()
self
.
assertIsInstance
(
returned
,
MagicMock
)
self
.
assertNotIsInstance
(
returned
,
PropertyMock
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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