@@ -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-26 20:46 +0800\n "
11
+ "PO-Revision-Date : 2024-03-28 22:08 +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 "
@@ -1084,6 +1084,8 @@ msgid ""
1084
1084
"There are various reasons why you might want to subclass :class:`Mock`. One "
1085
1085
"reason might be to add helper methods. Here's a silly example:"
1086
1086
msgstr ""
1087
+ "你會想子類別化 :class:`Mock` 的原因可能有很多種。其中之一是增加輔助方法。以下"
1088
+ "是一個有點笨的例子:"
1087
1089
1088
1090
#: ../../library/unittest.mock-examples.rst:1083
1089
1091
msgid ""
@@ -1094,6 +1096,10 @@ msgid ""
1094
1096
"methods then they'll also be available on the attributes and return value "
1095
1097
"mock of instances of your subclass."
1096
1098
msgstr ""
1099
+ "``Mock`` 實例的標準行為是屬性 mock 和回傳值 mock 會與存取它們的 mock 具有相同"
1100
+ "的型別。這確保了 ``Mock`` 屬性是 ``Mocks``,``MagicMock`` 屬性是 "
1101
+ "``MagicMocks`` [#]_。因此,如果你要子類別化以新增輔助方法,那麼它們也可用於子"
1102
+ "類別實例的屬性 mock 和回傳值 mock。"
1097
1103
1098
1104
#: ../../library/unittest.mock-examples.rst:1099
1099
1105
msgid ""
@@ -1102,6 +1108,10 @@ msgid ""
1102
1108
"adaptor <https://twisted.org/documents/11.0.0/api/twisted.python.components."
1103
1109
"html>`_. Having this applied to attributes too actually causes errors."
1104
1110
msgstr ""
1111
+ "有時候這很不方便。例如,`有一個使用者 <https://code.google.com/archive/p/"
1112
+ "mock/issues/105>`_\\ 正在子類別化 mock 以建立 `Twisted adaptor <https://"
1113
+ "twisted.org/documents/11.0.0/api/twisted.python.components.html>`_。將其應用"
1114
+ "於屬性實際上會導致錯誤。"
1105
1115
1106
1116
#: ../../library/unittest.mock-examples.rst:1105
1107
1117
msgid ""
@@ -1111,13 +1121,18 @@ msgid ""
1111
1121
"signature is that it takes arbitrary keyword arguments (``**kwargs``) which "
1112
1122
"are then passed onto the mock constructor:"
1113
1123
msgstr ""
1124
+ "``Mock`` (及其各種形式)使用名為 ``_get_child_mock`` 的方法來為屬性和回傳值"
1125
+ "建立這些 \" 子 mock\" 。你可以透過置換此方法來防止你的子類別被用為屬性。其簽名"
1126
+ "是取用任意的關鍵字引數(``**kwargs``\\ ),然後將其傳遞給 mock 建構函式:"
1114
1127
1115
1128
#: ../../library/unittest.mock-examples.rst:1122
1116
1129
msgid ""
1117
1130
"An exception to this rule are the non-callable mocks. Attributes use the "
1118
1131
"callable variant because otherwise non-callable mocks couldn't have callable "
1119
1132
"methods."
1120
1133
msgstr ""
1134
+ "此規則的例外是非可呼叫物件的 mock。屬性使用可呼叫物件的變體,否則非可呼叫物件"
1135
+ "的 mock 無法具有可呼叫物件的方法。"
1121
1136
1122
1137
#: ../../library/unittest.mock-examples.rst:1128
1123
1138
msgid "Mocking imports with patch.dict"
0 commit comments