@@ -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-07-22 00:04+0000\n "
11
- "PO-Revision-Date : 2023-08-29 15:33 +0800\n "
11
+ "PO-Revision-Date : 2023-09-05 00:58 +0800\n "
12
12
"
Last-Translator :
Adrian Liaw <[email protected] >\n "
13
13
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
14
14
"tw)\n "
@@ -198,9 +198,9 @@ msgid ""
198
198
msgstr ""
199
199
"為了確保測試中的 mock 物件與它們要替換的物件具有相同的 api,你可以使用\\ :"
200
200
"ref:`自動規格 <auto-speccing>`\\ 。自動規格(auto-speccing)可以通過 patch "
201
- "的 *autospec* 引數或 :func:`create_autospec` 函式來完成。自動規格建立的 "
202
- "mock 物件與它們要替換的物件具有相同的屬性和方法,並且任何函式和方法(包括建構 "
203
- "函式 )都具有與真實物件相同的呼叫簽名(call signature)。"
201
+ "的 *autospec* 引數或 :func:`create_autospec` 函式來完成。自動規格建立的 mock "
202
+ "物件與它們要替換的物件具有相同的屬性和方法,並且任何函式和方法(包括建構函 "
203
+ "式 )都具有與真實物件相同的呼叫簽名(call signature)。"
204
204
205
205
#: ../../library/unittest.mock.rst:178
206
206
msgid ""
@@ -229,6 +229,10 @@ msgid ""
229
229
"attribute will always return the same mock. Mocks record how you use them, "
230
230
"allowing you to make assertions about what your code has done to them."
231
231
msgstr ""
232
+ ":class:`Mock` 是一個彈性的的 mock 物件,旨在代替程式碼中 stubs 和 test "
233
+ "doubles (測試替身)的使用。Mock 是可呼叫的,並在你存取它們時將屬性創建為新"
234
+ "的 mock [#]_。存取相同的屬性將永遠返回相同的 mock。Mock 記錄了你如何使用它"
235
+ "們,允許你判定你的程式碼對 mock 的行為。"
232
236
233
237
#: ../../library/unittest.mock.rst:218
234
238
msgid ""
@@ -237,6 +241,9 @@ msgid ""
237
241
"when you are mocking out objects that aren't callable: :class:"
238
242
"`NonCallableMock` and :class:`NonCallableMagicMock`"
239
243
msgstr ""
244
+ ":class:`MagicMock` 是 :class:`Mock` 的子類別,其中所有魔術方法均已預先建立並"
245
+ "可供使用。也有不可呼叫的變體,在你 mock 無法呼叫的物件時很有用:\\ :class:"
246
+ "`NonCallableMock` 和 :class:`NonCallableMagicMock`"
240
247
241
248
#: ../../library/unittest.mock.rst:223
242
249
msgid ""
@@ -245,12 +252,17 @@ msgid ""
245
252
"will create a :class:`MagicMock` for you. You can specify an alternative "
246
253
"class of :class:`Mock` using the *new_callable* argument to :func:`patch`."
247
254
msgstr ""
255
+ ":func:`patch` 裝飾器可以輕鬆地用 :class:`Mock` 物件臨時替換特定模組中的類別。"
256
+ "默認情況下,\\ :func:`patch` 會為你建立一個 :class:`MagicMock`\\ 。你可以使"
257
+ "用 :func:`patch` 的 *new_callable* 引數指定 :class:`Mock` 的替代類別。"
248
258
249
259
#: ../../library/unittest.mock.rst:231
250
260
msgid ""
251
261
"Create a new :class:`Mock` object. :class:`Mock` takes several optional "
252
262
"arguments that specify the behaviour of the Mock object:"
253
263
msgstr ""
264
+ "建立一個新的 :class:`Mock` 對象。\\ :class:`Mock` 接受數個可選的引數來指定 "
265
+ "Mock 物件的行為:"
254
266
255
267
#: ../../library/unittest.mock.rst:234
256
268
msgid ""
@@ -260,21 +272,32 @@ msgid ""
260
272
"(excluding unsupported magic attributes and methods). Accessing any "
261
273
"attribute not in this list will raise an :exc:`AttributeError`."
262
274
msgstr ""
275
+ "*spec*:這可以是字串的 list(串列),也可以是充當 mock 物件規格的現有物件(類"
276
+ "別或實例)。如果傳入一個物件,則通過對該物件呼叫 dir 來形成字串的串列(不包括"
277
+ "不支援的魔術屬性和方法)。存取不在此串列中的任何屬性都會引發 :exc:"
278
+ "`AttributeError`\\ 。"
263
279
264
280
#: ../../library/unittest.mock.rst:240
265
281
msgid ""
266
282
"If *spec* is an object (rather than a list of strings) then :attr:`~instance."
267
283
"__class__` returns the class of the spec object. This allows mocks to pass :"
268
284
"func:`isinstance` tests."
269
285
msgstr ""
286
+ "如果 *spec* 是一個物件(而不是一個字串的串列),那麼 :attr:`~instance."
287
+ "__class__` 會回傳 spec 物件的類別。這允許 mocks 通過 :func:`isinstance` 測"
288
+ "試。"
270
289
271
290
#: ../../library/unittest.mock.rst:244
272
291
msgid ""
273
292
"*spec_set*: A stricter variant of *spec*. If used, attempting to *set* or "
274
293
"get an attribute on the mock that isn't on the object passed as *spec_set* "
275
294
"will raise an :exc:`AttributeError`."
276
295
msgstr ""
296
+ "*spec_set*:*spec* 的一個更嚴格的變體。如果使用 *spec_set*,在 mock 上嘗試 "
297
+ "*set* 或取得不在傳遞給 *spec_set* 的物件上的屬性將會引發 :exc:"
298
+ "`AttributeError`。"
277
299
300
+ # 待討論
278
301
#: ../../library/unittest.mock.rst:248
279
302
msgid ""
280
303
"*side_effect*: A function to be called whenever the Mock is called. See the :"
@@ -283,6 +306,9 @@ msgid ""
283
306
"arguments as the mock, and unless it returns :data:`DEFAULT`, the return "
284
307
"value of this function is used as the return value."
285
308
msgstr ""
309
+ "*side_effect*:每當呼叫 Mock 時要呼叫的函式。參見 :attr:`~Mock.side_effect` "
310
+ "屬性。用於引發例外或動態變更回傳值。該函式使用與 mock 相同的引數呼叫,且除非"
311
+ "它回傳 :data:`DEFAULT`,否則此函式的返回值將用作返回值。"
286
312
287
313
#: ../../library/unittest.mock.rst:254
288
314
msgid ""
0 commit comments