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
3af125a4
Kaydet (Commit)
3af125a4
authored
Nis 21, 2012
tarafından
Michael Foord
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes issue 14634. unittest.mock.create_autospec now supports keyword only arguments.
üst
2cd48738
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
8 deletions
+31
-8
inspect.rst
Doc/library/inspect.rst
+9
-4
mock.py
Lib/unittest/mock.py
+8
-3
testhelpers.py
Lib/unittest/test/testmock/testhelpers.py
+14
-1
No files found.
Doc/library/inspect.rst
Dosyayı görüntüle @
3af125a4
...
...
@@ -440,11 +440,16 @@ Classes and functions
locals dictionary of the given frame.
.. function:: formatargspec(args[, varargs, varkw, defaults,
formatarg, formatvarargs, formatvarkw, formatvalue
])
.. function:: formatargspec(args[, varargs, varkw, defaults,
kwonlyargs, kwonlydefaults, annotations, formatarg, formatvarargs, formatvarkw, formatvalue, formatreturns, formatannotations
])
Format a pretty argument spec from the four values returned by
:func:`getargspec`. The format\* arguments are the corresponding optional
formatting functions that are called to turn names and values into strings.
Format a pretty argument spec from the values returned by
:func:`getargspec` or :func:`getfullargspec`.
The first seven arguments are (``args``, ``varargs``, ``varkw``,
``defaults``, ``kwonlyargs``, ``kwonlydefaults``, ``annotations``). The
other five arguments are the corresponding optional formatting functions
that are called to turn names and values into strings. The last argument
is an optional function to format the sequence of arguments.
.. function:: formatargvalues(args[, varargs, varkw, locals, formatarg, formatvarargs, formatvarkw, formatvalue])
...
...
Lib/unittest/mock.py
Dosyayı görüntüle @
3af125a4
...
...
@@ -78,11 +78,15 @@ def _getsignature(func, skipfirst, instance=False):
return
try
:
regargs
,
varargs
,
varkwargs
,
defaults
=
inspect
.
get
argspec
(
func
)
argspec
=
inspect
.
getfull
argspec
(
func
)
except
TypeError
:
# C function / method, possibly inherited object().__init__
return
# not using annotations
regargs
,
varargs
,
varkw
,
defaults
,
kwonly
,
kwonlydef
,
ann
=
argspec
# instance methods and classmethods need to lose the self argument
if
getattr
(
func
,
'__self__'
,
None
)
is
not
None
:
regargs
=
regargs
[
1
:]
...
...
@@ -90,8 +94,9 @@ def _getsignature(func, skipfirst, instance=False):
# this condition and the above one are never both True - why?
regargs
=
regargs
[
1
:]
signature
=
inspect
.
formatargspec
(
regargs
,
varargs
,
varkwargs
,
defaults
,
formatvalue
=
lambda
value
:
""
)
signature
=
inspect
.
formatargspec
(
regargs
,
varargs
,
varkw
,
defaults
,
kwonly
,
kwonlydef
,
ann
,
formatvalue
=
lambda
value
:
""
)
return
signature
[
1
:
-
1
],
func
...
...
Lib/unittest/test/testmock/testhelpers.py
Dosyayı görüntüle @
3af125a4
...
...
@@ -367,7 +367,7 @@ class SpecSignatureTest(unittest.TestCase):
def
test_create_autospec_unbound_methods
(
self
):
# see issue 128
# see
mock
issue 128
# this is expected to fail until the issue is fixed
return
class
Foo
(
object
):
...
...
@@ -391,6 +391,19 @@ class SpecSignatureTest(unittest.TestCase):
self
.
assertEqual
(
m
.
a
,
'3'
)
def
test_create_autospec_keyword_only_arguments
(
self
):
def
foo
(
a
,
*
,
b
=
None
):
pass
m
=
create_autospec
(
foo
)
m
(
1
)
m
.
assert_called_with
(
1
)
self
.
assertRaises
(
TypeError
,
m
,
1
,
2
)
m
(
2
,
b
=
3
)
m
.
assert_called_with
(
2
,
b
=
3
)
def
test_function_as_instance_attribute
(
self
):
obj
=
SomeClass
()
def
f
(
a
):
...
...
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