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
15f2d177
Kaydet (Commit)
15f2d177
authored
Nis 15, 2014
tarafından
Michael Foord
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge
üst
27adf446
ebc1a30d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
7 deletions
+32
-7
mock.py
Lib/unittest/mock.py
+10
-5
testpatch.py
Lib/unittest/test/testmock/testpatch.py
+18
-1
NEWS
Misc/NEWS
+4
-1
No files found.
Lib/unittest/mock.py
Dosyayı görüntüle @
15f2d177
...
...
@@ -1054,7 +1054,7 @@ def _is_started(patcher):
class
_patch
(
object
):
attribute_name
=
None
_active_patches
=
set
()
_active_patches
=
[]
def
__init__
(
self
,
getter
,
attribute
,
new
,
spec
,
create
,
...
...
@@ -1330,13 +1330,18 @@ class _patch(object):
def
start
(
self
):
"""Activate a patch, returning any created mock."""
result
=
self
.
__enter__
()
self
.
_active_patches
.
a
d
d
(
self
)
self
.
_active_patches
.
a
ppen
d
(
self
)
return
result
def
stop
(
self
):
"""Stop an active patch."""
self
.
_active_patches
.
discard
(
self
)
try
:
self
.
_active_patches
.
remove
(
self
)
except
ValueError
:
# If the patch hasn't been started this will fail
pass
return
self
.
__exit__
()
...
...
@@ -1629,8 +1634,8 @@ def _clear_dict(in_dict):
def
_patch_stopall
():
"""Stop all active patches."""
for
patch
in
list
(
_patch
.
_active_patches
):
"""Stop all active patches.
LIFO to unroll nested patches.
"""
for
patch
in
reversed
(
_patch
.
_active_patches
):
patch
.
stop
()
...
...
Lib/unittest/test/testmock/testpatch.py
Dosyayı görüntüle @
15f2d177
...
...
@@ -12,7 +12,7 @@ from unittest.test.testmock.support import SomeClass, is_instance
from
unittest.mock
import
(
NonCallableMock
,
CallableMixin
,
patch
,
sentinel
,
MagicMock
,
Mock
,
NonCallableMagicMock
,
patch
,
_patch
,
DEFAULT
,
call
,
_get_target
DEFAULT
,
call
,
_get_target
,
_patch
)
...
...
@@ -1799,6 +1799,23 @@ class PatchTest(unittest.TestCase):
patched
()
self
.
assertIs
(
os
.
path
,
path
)
def
test_stopall_lifo
(
self
):
stopped
=
[]
class
thing
(
object
):
one
=
two
=
three
=
None
def
get_patch
(
attribute
):
class
mypatch
(
_patch
):
def
stop
(
self
):
stopped
.
append
(
attribute
)
return
super
(
mypatch
,
self
)
.
stop
()
return
mypatch
(
lambda
:
thing
,
attribute
,
None
,
None
,
False
,
None
,
None
,
None
,
{})
[
get_patch
(
val
)
.
start
()
for
val
in
(
"one"
,
"two"
,
"three"
)]
patch
.
stopall
()
self
.
assertEqual
(
stopped
,
[
"three"
,
"two"
,
"one"
])
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
Dosyayı görüntüle @
15f2d177
...
...
@@ -46,9 +46,12 @@ Core and Builtins
Library
-------
- Issue #21239: patch.stopall() didn'
t
work
deterministically
when
the
same
name
was
patched
more
than
once
.
-
Issue
#
21203
:
Updated
fileConfig
and
dictConfig
to
remove
inconsistencies
.
Thanks
to
Jure
Koren
for
the
patch
.
-
Issue
#
21222
:
Passing
name
keyword
argument
to
mock
.
create_autospec
now
works
.
...
...
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