@@ -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 : 2023-11-21 22:16 +0800\n "
11
+ "PO-Revision-Date : 2024-01-14 01:14 +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 "
@@ -17,7 +17,7 @@ msgstr ""
17
17
"Content-Type : text/plain; charset=UTF-8\n "
18
18
"Content-Transfer-Encoding : 8bit\n "
19
19
"Plural-Forms : nplurals=1; plural=0;\n "
20
- "X-Generator : Poedit 3.4\n "
20
+ "X-Generator : Poedit 3.4.1 \n "
21
21
22
22
#: ../../library/unittest.mock-examples.rst:2
23
23
msgid ":mod:`unittest.mock` --- getting started"
@@ -131,7 +131,7 @@ msgstr ""
131
131
132
132
#: ../../library/unittest.mock-examples.rst:106
133
133
msgid "Mocking Classes"
134
- msgstr ""
134
+ msgstr "Mock 類別 "
135
135
136
136
#: ../../library/unittest.mock-examples.rst:108
137
137
msgid ""
@@ -140,6 +140,9 @@ msgid ""
140
140
"Instances are created by *calling the class*. This means you access the "
141
141
"\" mock instance\" by looking at the return value of the mocked class."
142
142
msgstr ""
143
+ "一個常見的例子是 mock 被測試的程式碼實例化的類別。 當你 patch 一個類別時,該"
144
+ "類別就會被替換為 mock。 實例是透過*呼叫類別*建立的。 這代表你可以透過查看被 "
145
+ "mock 的類別的回傳值來存取「mock 實例」。"
143
146
144
147
#: ../../library/unittest.mock-examples.rst:113
145
148
msgid ""
@@ -149,28 +152,36 @@ msgid ""
149
152
"mock, so it is configured by modifying the mock :attr:`~Mock."
150
153
"return_value`. ::"
151
154
msgstr ""
155
+ "在下面的範例中,我們有一個函式 ``some_function``,它實例化 ``Foo`` 並呼叫它的"
156
+ "方法。 對 :func:`patch` 的呼叫將類別 ``Foo`` 替換為一個 mock。``Foo`` 實例是"
157
+ "呼叫 mock 的結果,因此它是透過修改 mock :attr:`~Mock.return_value` 來配置"
158
+ "的。: ::"
152
159
153
160
#: ../../library/unittest.mock-examples.rst:130
154
161
msgid "Naming your mocks"
155
- msgstr ""
162
+ msgstr "命名你的 mock "
156
163
157
164
#: ../../library/unittest.mock-examples.rst:132
158
165
msgid ""
159
166
"It can be useful to give your mocks a name. The name is shown in the repr of "
160
167
"the mock and can be helpful when the mock appears in test failure messages. "
161
168
"The name is also propagated to attributes or methods of the mock:"
162
169
msgstr ""
170
+ "為你的 mock 命名可能會很有用。 這個名稱會顯示在 mock 的 repr 中,且當 mock 出"
171
+ "現在測試的失敗訊息中時,名稱會很有幫助。 該名稱也會傳播到 mock 的屬性或方法:"
163
172
164
173
#: ../../library/unittest.mock-examples.rst:144
165
174
msgid "Tracking all Calls"
166
- msgstr ""
175
+ msgstr "追蹤所有呼叫 "
167
176
168
177
#: ../../library/unittest.mock-examples.rst:146
169
178
msgid ""
170
179
"Often you want to track more than a single call to a method. The :attr:"
171
180
"`~Mock.mock_calls` attribute records all calls to child attributes of the "
172
181
"mock - and also to their children."
173
182
msgstr ""
183
+ "通常你會想要追蹤對一個方法的多個呼叫。:attr:`~Mock.mock_calls` 屬性記錄對 "
184
+ "mock 的子屬性以及其子屬性的所有呼叫。"
174
185
175
186
#: ../../library/unittest.mock-examples.rst:158
176
187
msgid ""
@@ -179,58 +190,69 @@ msgid ""
179
190
"well as asserting that the calls you expected have been made, you are also "
180
191
"checking that they were made in the right order and with no additional calls:"
181
192
msgstr ""
193
+ "如果你對 ``mock_calls`` 做出斷言並且有任何不預期的方法被呼叫,則斷言將失敗。 "
194
+ "這很有用,因為除了斷言你期望的呼叫已經進行之外,你還可以檢查它們是否按正確的"
195
+ "順序進行,並且沒有多餘的呼叫:"
182
196
183
197
#: ../../library/unittest.mock-examples.rst:163
184
198
msgid ""
185
199
"You use the :data:`call` object to construct lists for comparing with "
186
200
"``mock_calls``:"
187
- msgstr ""
201
+ msgstr "你可以使用 :data:`call` 物件來建構串列以與 ``mock_calls`` 進行比較: "
188
202
189
203
#: ../../library/unittest.mock-examples.rst:170
190
204
msgid ""
191
205
"However, parameters to calls that return mocks are not recorded, which means "
192
206
"it is not possible to track nested calls where the parameters used to create "
193
207
"ancestors are important:"
194
208
msgstr ""
209
+ "然而,回傳 mock 的呼叫的參數不會被記錄,這代表著無法追蹤用於建立重要的祖先的"
210
+ "參數的巢狀呼叫:"
195
211
196
212
#: ../../library/unittest.mock-examples.rst:181
197
213
msgid "Setting Return Values and Attributes"
198
- msgstr ""
214
+ msgstr "設定回傳值和屬性 "
199
215
200
216
#: ../../library/unittest.mock-examples.rst:183
201
217
msgid "Setting the return values on a mock object is trivially easy:"
202
- msgstr ""
218
+ msgstr "在 mock 物件上設定回傳值非常簡單: "
203
219
204
220
#: ../../library/unittest.mock-examples.rst:190
205
221
msgid "Of course you can do the same for methods on the mock:"
206
- msgstr ""
222
+ msgstr "當然,你可以對 mock 上的方法執行相同的操作: "
207
223
208
224
#: ../../library/unittest.mock-examples.rst:197
209
225
msgid "The return value can also be set in the constructor:"
210
- msgstr ""
226
+ msgstr "回傳值也可以在建構函式中設定: "
211
227
212
228
#: ../../library/unittest.mock-examples.rst:203
213
229
msgid "If you need an attribute setting on your mock, just do it:"
214
- msgstr ""
230
+ msgstr "如果你需要在 mock 上進行屬性設置,只需執行以下操作: "
215
231
216
232
#: ../../library/unittest.mock-examples.rst:210
217
233
msgid ""
218
234
"Sometimes you want to mock up a more complex situation, like for example "
219
235
"``mock.connection.cursor().execute(\" SELECT 1\" )``. If we wanted this call "
220
236
"to return a list, then we have to configure the result of the nested call."
221
237
msgstr ""
238
+ "有時你想要 mock 更複雜的情況,例如 ``mock.connection.cursor()."
239
+ "execute(\" SELECT 1\" )``。 如果我們希望此呼叫回傳一個串列,那麼我們就必須配置"
240
+ "巢狀呼叫的結果。"
222
241
223
242
#: ../../library/unittest.mock-examples.rst:214
224
243
msgid ""
225
244
"We can use :data:`call` to construct the set of calls in a \" chained call\" "
226
245
"like this for easy assertion afterwards:"
227
246
msgstr ""
247
+ "如下所示,我們可以使用 :data:`call` 在「鍊接呼叫 (chained call)」中建構呼叫的"
248
+ "集合,以便在之後輕鬆的進行斷言:"
228
249
229
250
#: ../../library/unittest.mock-examples.rst:228
230
251
msgid ""
231
252
"It is the call to ``.call_list()`` that turns our call object into a list of "
232
253
"calls representing the chained calls."
233
254
msgstr ""
255
+ "正是對 ``.call_list()`` 的呼叫將我們的呼叫物件轉換為代表鍊接呼叫的呼叫串列。"
234
256
235
257
#: ../../library/unittest.mock-examples.rst:233
236
258
msgid "Raising exceptions with mocks"
0 commit comments