@@ -8,7 +8,7 @@ msgstr ""
8
8
"Project-Id-Version : Python 3.12\n "
9
9
"Report-Msgid-Bugs-To : \n "
10
10
"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 "
12
12
"
Last-Translator :
Liang-Bo Wang <[email protected] >\n "
13
13
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
14
14
"tw)\n "
@@ -980,14 +980,16 @@ msgstr ""
980
980
981
981
#: ../../library/unittest.mock-examples.rst:941
982
982
msgid "Nesting Patches"
983
- msgstr ""
983
+ msgstr "巢狀使用 Patch "
984
984
985
985
#: ../../library/unittest.mock-examples.rst:943
986
986
msgid ""
987
987
"Using patch as a context manager is nice, but if you do multiple patches you "
988
988
"can end up with nested with statements indenting further and further to the "
989
989
"right::"
990
990
msgstr ""
991
+ "將 patch 作為情境管理器使用很好,但是如果你使用複數個 patch,你最終可能會得到"
992
+ "巢狀的 with 陳述式,並且越來越向右縮排: ::"
991
993
992
994
#: ../../library/unittest.mock-examples.rst:961
993
995
msgid ""
@@ -996,23 +998,30 @@ msgid ""
996
998
"method, ``create_patch``, puts the patch in place and returns the created "
997
999
"mock for us::"
998
1000
msgstr ""
1001
+ "我們可以使用 unittest 的 ``cleanup`` 函式以及 :ref:`start-and-stop` 來達到相"
1002
+ "同的效果,而不會出現因巢狀導致的縮排。一個簡單的輔助方法 ``create_patch`` 會"
1003
+ "將 patch 放置到位並為我們回傳被建立的 mock: ::"
999
1004
1000
1005
#: ../../library/unittest.mock-examples.rst:989
1001
1006
msgid "Mocking a dictionary with MagicMock"
1002
- msgstr ""
1007
+ msgstr "使用 MagicMock 來 mock 字典 "
1003
1008
1004
1009
#: ../../library/unittest.mock-examples.rst:991
1005
1010
msgid ""
1006
1011
"You may want to mock a dictionary, or other container object, recording all "
1007
1012
"access to it whilst having it still behave like a dictionary."
1008
1013
msgstr ""
1014
+ "你可能會想要 mock 字典或其他容器物件,記錄對它的所有存取,同時讓它仍然像字典"
1015
+ "一樣運作。"
1009
1016
1010
1017
#: ../../library/unittest.mock-examples.rst:994
1011
1018
msgid ""
1012
1019
"We can do this with :class:`MagicMock`, which will behave like a dictionary, "
1013
1020
"and using :data:`~Mock.side_effect` to delegate dictionary access to a real "
1014
1021
"underlying dictionary that is under our control."
1015
1022
msgstr ""
1023
+ "我們可以使用 :class:`MagicMock` 來做到這一點,它的行為會與字典一致,並使用 :"
1024
+ "data:`~Mock.side_effect` 將字典存取委託給我們控制下的真實底層字典。"
1016
1025
1017
1026
#: ../../library/unittest.mock-examples.rst:998
1018
1027
msgid ""
@@ -1021,42 +1030,54 @@ msgid ""
1021
1030
"``side_effect`` is called with the key (and in the case of ``__setitem__`` "
1022
1031
"the value too). We can also control what is returned."
1023
1032
msgstr ""
1033
+ "當 ``MagicMock`` 的 :meth:`~object.__getitem__` 和 :meth:`~object."
1034
+ "__setitem__` 方法被呼叫時(一般的字典存取), ``side_effect`` 會被使用鍵 "
1035
+ "(key) 來呼叫 (在 ``__setitem__`` 的情況也會使用值 (value))。我們也可以控制"
1036
+ "回傳的內容。"
1024
1037
1025
1038
#: ../../library/unittest.mock-examples.rst:1003
1026
1039
msgid ""
1027
1040
"After the ``MagicMock`` has been used we can use attributes like :data:"
1028
1041
"`~Mock.call_args_list` to assert about how the dictionary was used:"
1029
1042
msgstr ""
1043
+ "使用 ``MagicMock`` 後,我們可以使用諸如 :data:`~Mock.call_args_list` 之類的屬"
1044
+ "性來斷言字典被使用的方式:"
1030
1045
1031
1046
#: ../../library/unittest.mock-examples.rst:1019
1032
1047
msgid ""
1033
1048
"An alternative to using ``MagicMock`` is to use ``Mock`` and *only* provide "
1034
1049
"the magic methods you specifically want:"
1035
1050
msgstr ""
1051
+ "不使用 ``MagicMock`` 的替代方案是使用 ``Mock`` 並且\\ *只*\\ 提供你特別想要的"
1052
+ "魔術方法:"
1036
1053
1037
1054
#: ../../library/unittest.mock-examples.rst:1026
1038
1055
msgid ""
1039
1056
"A *third* option is to use ``MagicMock`` but passing in ``dict`` as the "
1040
1057
"*spec* (or *spec_set*) argument so that the ``MagicMock`` created only has "
1041
1058
"dictionary magic methods available:"
1042
1059
msgstr ""
1060
+ "第三個選擇是使用 ``MagicMock``,但傳入 ``dict`` 作為 *spec*(或*spec_set*)引"
1061
+ "數,以使被建立的 ``MagicMock`` 僅具有字典可用的魔術方法:"
1043
1062
1044
1063
#: ../../library/unittest.mock-examples.rst:1034
1045
1064
msgid ""
1046
1065
"With these side effect functions in place, the ``mock`` will behave like a "
1047
1066
"normal dictionary but recording the access. It even raises a :exc:`KeyError` "
1048
1067
"if you try to access a key that doesn't exist."
1049
1068
msgstr ""
1069
+ "有了這些 side effect 函式,``mock`` 會像一般的字典一樣運作,但會記錄存取。如"
1070
+ "果你嘗試存取不存在的鍵,它甚至會引發一個 :exc:`KeyError`。"
1050
1071
1051
1072
#: ../../library/unittest.mock-examples.rst:1053
1052
1073
msgid ""
1053
1074
"After it has been used you can make assertions about the access using the "
1054
1075
"normal mock methods and attributes:"
1055
- msgstr ""
1076
+ msgstr "在上述方式被使用後,你就可以使用普通的 mock 方法和屬性對存取進行斷言: "
1056
1077
1057
1078
#: ../../library/unittest.mock-examples.rst:1065
1058
1079
msgid "Mock subclasses and their attributes"
1059
- msgstr ""
1080
+ msgstr "Mock 子類別及其屬性 "
1060
1081
1061
1082
#: ../../library/unittest.mock-examples.rst:1067
1062
1083
msgid ""
0 commit comments