@@ -7,7 +7,7 @@ msgstr ""
7
7
"Project-Id-Version :Python 3.12\n "
8
8
"Report-Msgid-Bugs-To :\n "
9
9
"POT-Creation-Date :2023-12-16 00:03+0000\n "
10
- "PO-Revision-Date :2024-01-0901 :08+0800\n "
10
+ "PO-Revision-Date :2024-01-0923 :08+0800\n "
11
11
"Last-Translator :Adrian Liaw <adrianliaw2000@gmail.com>\n "
12
12
"Language-Team :Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
13
13
"tw)\n "
@@ -1235,6 +1235,10 @@ msgid ""
1235
1235
"If :func:`patch` is used as a context manager the created mock is returned "
1236
1236
"by the context manager."
1237
1237
msgstr ""
1238
+ "如果 *new* 被省略,則如果被 patch 的物件是非同步函式,目標會被替換為 :class:"
1239
+ "`AsyncMock`,反之則替換為 :class:`MagicMock`。如果 :func:`patch` 做為裝飾器使"
1240
+ "用且省略了 *new*,則所建立的 mock 會作為額外的引數傳遞給被裝飾的函式。如果 :"
1241
+ "func:`patch` 作為情境管理器使用,則所建立的 mock 將由情境管理器回傳。"
1238
1242
1239
1243
#: ../../library/unittest.mock.rst:1353
1240
1244
msgid ""
@@ -1244,25 +1248,36 @@ msgid ""
1244
1248
"calling :func:`patch` from. The target is imported when the decorated "
1245
1249
"function is executed, not at decoration time."
1246
1250
msgstr ""
1251
+ "*target* 應該是以 ``'package.module.ClassName'`` 形式出現的字串。*target* 會"
1252
+ "被引入並用 *new* 物件替換指定的物件,因此 *target* 必須可從你呼叫 :func:"
1253
+ "`patch` 的環境中引入。target 在執行被裝飾的函式時被引入,而不是在裝飾器作用"
1254
+ "時 (decoration time)。"
1247
1255
1248
1256
#: ../../library/unittest.mock.rst:1359
1249
1257
msgid ""
1250
1258
"The *spec* and *spec_set* keyword arguments are passed to the :class:"
1251
1259
"`MagicMock` if patch is creating one for you."
1252
1260
msgstr ""
1261
+ "*spec* 和 *spec_set* 關鍵字引數會傳遞給 :class:`MagicMock`,如果 patch 正在為"
1262
+ "你建立一個。"
1253
1263
1254
1264
#: ../../library/unittest.mock.rst:1362
1255
1265
msgid ""
1256
1266
"In addition you can pass ``spec=True`` or ``spec_set=True``, which causes "
1257
1267
"patch to pass in the object being mocked as the spec/spec_set object."
1258
1268
msgstr ""
1269
+ "此外,你還可以傳遞 ``spec=True``或 ``spec_set=True``,這將導致 patch 將被 "
1270
+ "mock 的物件作為 spec/spec_set 物件傳遞。"
1259
1271
1260
1272
#: ../../library/unittest.mock.rst:1365
1261
1273
msgid ""
1262
1274
"*new_callable* allows you to specify a different class, or callable object, "
1263
1275
"that will be called to create the *new* object. By default :class:"
1264
1276
"`AsyncMock` is used for async functions and :class:`MagicMock` for the rest."
1265
1277
msgstr ""
1278
+ "*new_callable* 允許你指定一個不同的類別或可呼叫的物件,用於被呼叫並建立 "
1279
+ "*new* 物件。預設情況下,對於非同步函式使用 :class:`AsyncMock`,而對於其他情況"
1280
+ "則使用 :class:`MagicMock`。"
1266
1281
1267
1282
#: ../../library/unittest.mock.rst:1369
1268
1283
msgid ""
@@ -1275,12 +1290,20 @@ msgid ""
1275
1290
"return value (the 'instance') will have the same spec as the class. See the :"
1276
1291
"func:`create_autospec` function and :ref:`auto-speccing`."
1277
1292
msgstr ""
1293
+ "*spec* 的一種更強大的形式是 *autospec*。如果你設定 ``autospec=True``,則該 "
1294
+ "mock 將使用被替換物件的規格來建立。該 mock 的所有屬性也將具有被替換物件的對應"
1295
+ "屬性的規格。被 mock 的方法和函式將檢查其引數,如果呼叫時引數與規格不符(被使"
1296
+ "用錯誤的簽名 (signature) 呼叫),將引發 :exc:`TypeError`。對於替換類別的 "
1297
+ "mock,它們的回傳值(即 'instance')將具有與類別相同的規格。請參閱 :func:"
1298
+ "`create_autospec` 函式和 :ref:`auto-speccing`。"
1278
1299
1279
1300
#: ../../library/unittest.mock.rst:1379
1280
1301
msgid ""
1281
1302
"Instead of ``autospec=True`` you can pass ``autospec=some_object`` to use an "
1282
1303
"arbitrary object as the spec instead of the one being replaced."
1283
1304
msgstr ""
1305
+ "你可以用 ``autospec=some_object`` 替代 ``autospec=True``,以使用任意物件作為"
1306
+ "規格,而不是被替換的物件。"
1284
1307
1285
1308
#: ../../library/unittest.mock.rst:1382
1286
1309
msgid ""
@@ -1292,6 +1315,11 @@ msgid ""
1292
1315
"off by default because it can be dangerous. With it switched on you can "
1293
1316
"write passing tests against APIs that don't actually exist!"
1294
1317
msgstr ""
1318
+ "預設情況下,:func:`patch` 將無法取代不存在的屬性。如果你傳入 "
1319
+ "``create=True``,且屬性不存在,則當被 patch 的函式被呼叫時,patch 將為你建立"
1320
+ "該屬性,並在被 patch 的函式結束後再次刪除它。這對於撰寫針對你的生產程式碼在執"
1321
+ "行環境建立的屬性的測試時非常有用。此功能預設為關閉,因為這可能會相當危險。開"
1322
+ "啟這個功能後,你可以對於實際上不存在的 API 撰寫會通過的測試!"
1295
1323
1296
1324
#: ../../library/unittest.mock.rst:1392
1297
1325
msgid ""