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
9854789e
Kaydet (Commit)
9854789e
authored
Agu 07, 2016
tarafından
Gregory P. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #26750: unittest.mock.create_autospec() now works properly
for subclasses of property() and other data descriptors.
üst
abfe28b0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
22 deletions
+51
-22
mock.py
Lib/unittest/mock.py
+9
-1
testhelpers.py
Lib/unittest/test/testmock/testhelpers.py
+39
-21
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/unittest/mock.py
Dosyayı görüntüle @
9854789e
...
@@ -64,12 +64,20 @@ class _slotted(object):
...
@@ -64,12 +64,20 @@ class _slotted(object):
__slots__
=
[
'a'
]
__slots__
=
[
'a'
]
# Do not use this tuple. It was never documented as a public API.
# It will be removed. It has no obvious signs of users on github.
DescriptorTypes
=
(
DescriptorTypes
=
(
type
(
_slotted
.
a
),
type
(
_slotted
.
a
),
property
,
property
,
)
)
def
_is_data_descriptor
(
obj
):
# Data descriptors are Properties, slots, getsets and C data members.
return
((
hasattr
(
obj
,
'__set__'
)
or
hasattr
(
obj
,
'__del__'
))
and
hasattr
(
obj
,
'__get__'
))
def
_get_signature_object
(
func
,
as_instance
,
eat_self
):
def
_get_signature_object
(
func
,
as_instance
,
eat_self
):
"""
"""
Given an arbitrary, possibly callable object, try to create a suitable
Given an arbitrary, possibly callable object, try to create a suitable
...
@@ -2130,7 +2138,7 @@ def create_autospec(spec, spec_set=False, instance=False, _parent=None,
...
@@ -2130,7 +2138,7 @@ def create_autospec(spec, spec_set=False, instance=False, _parent=None,
_kwargs
.
update
(
kwargs
)
_kwargs
.
update
(
kwargs
)
Klass
=
MagicMock
Klass
=
MagicMock
if
type
(
spec
)
in
DescriptorTypes
:
if
_is_data_descriptor
(
spec
)
:
# descriptors don't have a spec
# descriptors don't have a spec
# because we don't know what type they return
# because we don't know what type they return
_kwargs
=
{}
_kwargs
=
{}
...
...
Lib/unittest/test/testmock/testhelpers.py
Dosyayı görüntüle @
9854789e
...
@@ -802,35 +802,53 @@ class SpecSignatureTest(unittest.TestCase):
...
@@ -802,35 +802,53 @@ class SpecSignatureTest(unittest.TestCase):
a
.
f
.
assert_called_with
(
self
=
10
)
a
.
f
.
assert_called_with
(
self
=
10
)
def
test_autospec_property
(
self
):
def
test_autospec_data_descriptor
(
self
):
class
Foo
(
object
):
class
Descriptor
(
object
):
@property
def
__init__
(
self
,
value
):
def
foo
(
self
):
self
.
value
=
value
return
3
foo
=
create_autospec
(
Foo
)
def
__get__
(
self
,
obj
,
cls
=
None
):
mock_property
=
foo
.
foo
if
obj
is
None
:
return
self
return
self
.
value
# no spec on properties
def
__set__
(
self
,
obj
,
value
):
self
.
assertIsInstance
(
mock_property
,
MagicMock
)
pass
mock_property
(
1
,
2
,
3
)
mock_property
.
abc
(
4
,
5
,
6
)
mock_property
.
assert_called_once_with
(
1
,
2
,
3
)
mock_property
.
abc
.
assert_called_once_with
(
4
,
5
,
6
)
class
MyProperty
(
property
):
pass
def
test_autospec_slots
(
self
):
class
Foo
(
object
):
class
Foo
(
object
):
__slots__
=
[
'a'
]
__slots__
=
[
'slot'
]
@property
def
prop
(
self
):
return
3
@MyProperty
def
subprop
(
self
):
return
4
desc
=
Descriptor
(
42
)
foo
=
create_autospec
(
Foo
)
foo
=
create_autospec
(
Foo
)
mock_slot
=
foo
.
a
# no spec on slots
def
check_data_descriptor
(
mock_attr
):
mock_slot
(
1
,
2
,
3
)
# Data descriptors don't have a spec.
mock_slot
.
abc
(
4
,
5
,
6
)
self
.
assertIsInstance
(
mock_attr
,
MagicMock
)
mock_slot
.
assert_called_once_with
(
1
,
2
,
3
)
mock_attr
(
1
,
2
,
3
)
mock_slot
.
abc
.
assert_called_once_with
(
4
,
5
,
6
)
mock_attr
.
abc
(
4
,
5
,
6
)
mock_attr
.
assert_called_once_with
(
1
,
2
,
3
)
mock_attr
.
abc
.
assert_called_once_with
(
4
,
5
,
6
)
# property
check_data_descriptor
(
foo
.
prop
)
# property subclass
check_data_descriptor
(
foo
.
subprop
)
# class __slot__
check_data_descriptor
(
foo
.
slot
)
# plain data descriptor
check_data_descriptor
(
foo
.
desc
)
class
TestCallList
(
unittest
.
TestCase
):
class
TestCallList
(
unittest
.
TestCase
):
...
...
Misc/NEWS
Dosyayı görüntüle @
9854789e
...
@@ -34,6 +34,9 @@ Core and Builtins
...
@@ -34,6 +34,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
26750
:
unittest
.
mock
.
create_autospec
()
now
works
properly
for
subclasses
of
property
()
and
other
data
descriptors
.
-
Issue
#
27568
:
Prevent
HTTPoxy
attack
(
CVE
-
2016
-
1000110
).
Ignore
the
-
Issue
#
27568
:
Prevent
HTTPoxy
attack
(
CVE
-
2016
-
1000110
).
Ignore
the
HTTP_PROXY
variable
when
REQUEST_METHOD
environment
is
set
,
which
indicates
HTTP_PROXY
variable
when
REQUEST_METHOD
environment
is
set
,
which
indicates
that
the
script
is
in
CGI
mode
.
that
the
script
is
in
CGI
mode
.
...
...
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