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
c02d188a
Kaydet (Commit)
c02d188a
authored
Ara 11, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #22823: Use set literals instead of creating a set from a list.
Fixed an output of sets in examples.
üst
afd6f637
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
28 deletions
+27
-28
unittest.mock-examples.rst
Doc/library/unittest.mock-examples.rst
+12
-12
mock.py
Lib/unittest/mock.py
+15
-16
No files found.
Doc/library/unittest.mock-examples.rst
Dosyayı görüntüle @
c02d188a
...
@@ -756,16 +756,16 @@ When we try to test that ``grob`` calls ``frob`` with the correct argument look
...
@@ -756,16 +756,16 @@ When we try to test that ``grob`` calls ``frob`` with the correct argument look
what happens:
what happens:
>>> with patch('mymodule.frob') as mock_frob:
>>> with patch('mymodule.frob') as mock_frob:
... val =
set([6])
... val =
{6}
... mymodule.grob(val)
... mymodule.grob(val)
...
...
>>> val
>>> val
set(
[]
)
set()
>>> mock_frob.assert_called_with(
set([6])
)
>>> mock_frob.assert_called_with(
{6}
)
Traceback (most recent call last):
Traceback (most recent call last):
...
...
AssertionError: Expected: ((
set([6])
,), {})
AssertionError: Expected: ((
{6}
,), {})
Called with: ((set(
[]
),), {})
Called with: ((set(),), {})
One possibility would be for mock to copy the arguments you pass in. This
One possibility would be for mock to copy the arguments you pass in. This
could then cause problems if you do assertions that rely on object identity
could then cause problems if you do assertions that rely on object identity
...
@@ -793,12 +793,12 @@ me.
...
@@ -793,12 +793,12 @@ me.
...
...
>>> with patch('mymodule.frob') as mock_frob:
>>> with patch('mymodule.frob') as mock_frob:
... new_mock = copy_call_args(mock_frob)
... new_mock = copy_call_args(mock_frob)
... val =
set([6])
... val =
{6}
... mymodule.grob(val)
... mymodule.grob(val)
...
...
>>> new_mock.assert_called_with(
set([6])
)
>>> new_mock.assert_called_with(
{6}
)
>>> new_mock.call_args
>>> new_mock.call_args
call(
set([6])
)
call(
{6}
)
``copy_call_args`` is called with the mock that will be called. It returns a new
``copy_call_args`` is called with the mock that will be called. It returns a new
mock that we do the assertion on. The ``side_effect`` function makes a copy of
mock that we do the assertion on. The ``side_effect`` function makes a copy of
...
@@ -811,10 +811,10 @@ the args and calls our ``new_mock`` with the copy.
...
@@ -811,10 +811,10 @@ the args and calls our ``new_mock`` with the copy.
checking inside a ``side_effect`` function.
checking inside a ``side_effect`` function.
>>> def side_effect(arg):
>>> def side_effect(arg):
... assert arg ==
set([6])
... assert arg ==
{6}
...
...
>>> mock = Mock(side_effect=side_effect)
>>> mock = Mock(side_effect=side_effect)
>>> mock(
set([6])
)
>>> mock(
{6}
)
>>> mock(set())
>>> mock(set())
Traceback (most recent call last):
Traceback (most recent call last):
...
...
...
@@ -839,8 +839,8 @@ Here's an example implementation:
...
@@ -839,8 +839,8 @@ Here's an example implementation:
>>> c.assert_called_with(arg)
>>> c.assert_called_with(arg)
Traceback (most recent call last):
Traceback (most recent call last):
...
...
AssertionError: Expected call: mock(
set([1])
)
AssertionError: Expected call: mock(
{1}
)
Actual call: mock(set(
[]
))
Actual call: mock(set())
>>> c.foo
>>> c.foo
<CopyingMock name='mock.foo' id='...'>
<CopyingMock name='mock.foo' id='...'>
...
...
Lib/unittest/mock.py
Dosyayı görüntüle @
c02d188a
...
@@ -275,13 +275,11 @@ def _copy(value):
...
@@ -275,13 +275,11 @@ def _copy(value):
return
value
return
value
_allowed_names
=
set
(
_allowed_names
=
{
[
'return_value'
,
'_mock_return_value'
,
'side_effect'
,
'return_value'
,
'_mock_return_value'
,
'side_effect'
,
'_mock_side_effect'
,
'_mock_parent'
,
'_mock_new_parent'
,
'_mock_side_effect'
,
'_mock_parent'
,
'_mock_new_parent'
,
'_mock_name'
,
'_mock_new_name'
'_mock_name'
,
'_mock_new_name'
}
]
)
def
_delegating_property
(
name
):
def
_delegating_property
(
name
):
...
@@ -1679,11 +1677,12 @@ right = ' '.join('r%s' % n for n in numerics.split())
...
@@ -1679,11 +1677,12 @@ right = ' '.join('r%s' % n for n in numerics.split())
# (as they are metaclass methods)
# (as they are metaclass methods)
# __del__ is not supported at all as it causes problems if it exists
# __del__ is not supported at all as it causes problems if it exists
_non_defaults
=
set
(
'__
%
s__'
%
method
for
method
in
[
_non_defaults
=
{
'get'
,
'set'
,
'delete'
,
'reversed'
,
'missing'
,
'reduce'
,
'reduce_ex'
,
'__get__'
,
'__set__'
,
'__delete__'
,
'__reversed__'
,
'__missing__'
,
'getinitargs'
,
'getnewargs'
,
'getstate'
,
'setstate'
,
'getformat'
,
'__reduce__'
,
'__reduce_ex__'
,
'__getinitargs__'
,
'__getnewargs__'
,
'setformat'
,
'repr'
,
'dir'
,
'subclasses'
,
'format'
,
'__getstate__'
,
'__setstate__'
,
'__getformat__'
,
'__setformat__'
,
])
'__repr__'
,
'__dir__'
,
'__subclasses__'
,
'__format__'
,
)
def
_get_method
(
name
,
func
):
def
_get_method
(
name
,
func
):
...
@@ -1694,19 +1693,19 @@ def _get_method(name, func):
...
@@ -1694,19 +1693,19 @@ def _get_method(name, func):
return
method
return
method
_magics
=
set
(
_magics
=
{
'__
%
s__'
%
method
for
method
in
'__
%
s__'
%
method
for
method
in
' '
.
join
([
magic_methods
,
numerics
,
inplace
,
right
])
.
split
()
' '
.
join
([
magic_methods
,
numerics
,
inplace
,
right
])
.
split
()
)
}
_all_magics
=
_magics
|
_non_defaults
_all_magics
=
_magics
|
_non_defaults
_unsupported_magics
=
set
([
_unsupported_magics
=
{
'__getattr__'
,
'__setattr__'
,
'__getattr__'
,
'__setattr__'
,
'__init__'
,
'__new__'
,
'__prepare__'
'__init__'
,
'__new__'
,
'__prepare__'
'__instancecheck__'
,
'__subclasscheck__'
,
'__instancecheck__'
,
'__subclasscheck__'
,
'__del__'
'__del__'
])
}
_calculate_return_value
=
{
_calculate_return_value
=
{
'__hash__'
:
lambda
self
:
object
.
__hash__
(
self
),
'__hash__'
:
lambda
self
:
object
.
__hash__
(
self
),
...
...
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