Skip to content

Commit 98c866a

Browse files
committed
feat: to rst:1065
in 1019: 原文沒有不,但下面的範例沒有使用magicmock,我覺得這樣翻會比較順
1 parent f79fdb8 commit 98c866a

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

library/unittest.mock-examples.po

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgstr ""
88
"Project-Id-Version: Python 3.12\n"
99
"Report-Msgid-Bugs-To: \n"
1010
"POT-Creation-Date: 2023-09-09 00:03+0000\n"
11-
"PO-Revision-Date: 2024-03-12 21:41+0800\n"
11+
"PO-Revision-Date: 2024-03-16 15:00+0800\n"
1212
"Last-Translator: Liang-Bo Wang <[email protected]>\n"
1313
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1414
"tw)\n"
@@ -980,14 +980,16 @@ msgstr ""
980980

981981
#: ../../library/unittest.mock-examples.rst:941
982982
msgid "Nesting Patches"
983-
msgstr ""
983+
msgstr "巢狀使用 Patch"
984984

985985
#: ../../library/unittest.mock-examples.rst:943
986986
msgid ""
987987
"Using patch as a context manager is nice, but if you do multiple patches you "
988988
"can end up with nested with statements indenting further and further to the "
989989
"right::"
990990
msgstr ""
991+
"將 patch 作為情境管理器使用很好,但是如果你使用複數個 patch,你最終可能會得到"
992+
"巢狀的 with 陳述式,並且越來越向右縮排: ::"
991993

992994
#: ../../library/unittest.mock-examples.rst:961
993995
msgid ""
@@ -996,23 +998,30 @@ msgid ""
996998
"method, ``create_patch``, puts the patch in place and returns the created "
997999
"mock for us::"
9981000
msgstr ""
1001+
"我們可以使用 unittest 的 ``cleanup`` 函式以及 :ref:`start-and-stop` 來達到相"
1002+
"同的效果,而不會出現因巢狀導致的縮排。一個簡單的輔助方法 ``create_patch`` 會"
1003+
"將 patch 放置到位並為我們回傳被建立的 mock: ::"
9991004

10001005
#: ../../library/unittest.mock-examples.rst:989
10011006
msgid "Mocking a dictionary with MagicMock"
1002-
msgstr ""
1007+
msgstr "使用 MagicMock 來 mock 字典"
10031008

10041009
#: ../../library/unittest.mock-examples.rst:991
10051010
msgid ""
10061011
"You may want to mock a dictionary, or other container object, recording all "
10071012
"access to it whilst having it still behave like a dictionary."
10081013
msgstr ""
1014+
"你可能會想要 mock 字典或其他容器物件,記錄對它的所有存取,同時讓它仍然像字典"
1015+
"一樣運作。"
10091016

10101017
#: ../../library/unittest.mock-examples.rst:994
10111018
msgid ""
10121019
"We can do this with :class:`MagicMock`, which will behave like a dictionary, "
10131020
"and using :data:`~Mock.side_effect` to delegate dictionary access to a real "
10141021
"underlying dictionary that is under our control."
10151022
msgstr ""
1023+
"我們可以使用 :class:`MagicMock` 來做到這一點,它的行為會與字典一致,並使用 :"
1024+
"data:`~Mock.side_effect` 將字典存取委託給我們控制下的真實底層字典。"
10161025

10171026
#: ../../library/unittest.mock-examples.rst:998
10181027
msgid ""
@@ -1021,42 +1030,54 @@ msgid ""
10211030
"``side_effect`` is called with the key (and in the case of ``__setitem__`` "
10221031
"the value too). We can also control what is returned."
10231032
msgstr ""
1033+
"當 ``MagicMock`` 的 :meth:`~object.__getitem__` 和 :meth:`~object."
1034+
"__setitem__` 方法被呼叫時(一般的字典存取), ``side_effect`` 會被使用鍵 "
1035+
"(key) 來呼叫 (在 ``__setitem__`` 的情況也會使用值 (value))。我們也可以控制"
1036+
"回傳的內容。"
10241037

10251038
#: ../../library/unittest.mock-examples.rst:1003
10261039
msgid ""
10271040
"After the ``MagicMock`` has been used we can use attributes like :data:"
10281041
"`~Mock.call_args_list` to assert about how the dictionary was used:"
10291042
msgstr ""
1043+
"使用 ``MagicMock`` 後,我們可以使用諸如 :data:`~Mock.call_args_list` 之類的屬"
1044+
"性來斷言字典被使用的方式:"
10301045

10311046
#: ../../library/unittest.mock-examples.rst:1019
10321047
msgid ""
10331048
"An alternative to using ``MagicMock`` is to use ``Mock`` and *only* provide "
10341049
"the magic methods you specifically want:"
10351050
msgstr ""
1051+
"不使用 ``MagicMock`` 的替代方案是使用 ``Mock`` 並且\\ *只*\\ 提供你特別想要的"
1052+
"魔術方法:"
10361053

10371054
#: ../../library/unittest.mock-examples.rst:1026
10381055
msgid ""
10391056
"A *third* option is to use ``MagicMock`` but passing in ``dict`` as the "
10401057
"*spec* (or *spec_set*) argument so that the ``MagicMock`` created only has "
10411058
"dictionary magic methods available:"
10421059
msgstr ""
1060+
"第三個選擇是使用 ``MagicMock``,但傳入 ``dict`` 作為 *spec*(或*spec_set*)引"
1061+
"數,以使被建立的 ``MagicMock`` 僅具有字典可用的魔術方法:"
10431062

10441063
#: ../../library/unittest.mock-examples.rst:1034
10451064
msgid ""
10461065
"With these side effect functions in place, the ``mock`` will behave like a "
10471066
"normal dictionary but recording the access. It even raises a :exc:`KeyError` "
10481067
"if you try to access a key that doesn't exist."
10491068
msgstr ""
1069+
"有了這些 side effect 函式,``mock`` 會像一般的字典一樣運作,但會記錄存取。如"
1070+
"果你嘗試存取不存在的鍵,它甚至會引發一個 :exc:`KeyError`。"
10501071

10511072
#: ../../library/unittest.mock-examples.rst:1053
10521073
msgid ""
10531074
"After it has been used you can make assertions about the access using the "
10541075
"normal mock methods and attributes:"
1055-
msgstr ""
1076+
msgstr "在上述方式被使用後,你就可以使用普通的 mock 方法和屬性對存取進行斷言:"
10561077

10571078
#: ../../library/unittest.mock-examples.rst:1065
10581079
msgid "Mock subclasses and their attributes"
1059-
msgstr ""
1080+
msgstr "Mock 子類別及其屬性"
10601081

10611082
#: ../../library/unittest.mock-examples.rst:1067
10621083
msgid ""

0 commit comments

Comments
 (0)