@@ -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-04-02 21:55 +0800\n "
11
+ "PO-Revision-Date : 2024-04-09 00:26 +0800\n "
12
12
"Last-Translator : Liang-Bo Wang <me@liang2.tw>\n "
13
13
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
14
14
"tw)\n "
@@ -1191,25 +1191,27 @@ msgstr ""
1191
1191
1192
1192
#: ../../library/unittest.mock-examples.rst:1154
1193
1193
msgid "Here's an example that mocks out the 'fooble' module."
1194
- msgstr ""
1194
+ msgstr "下面是一個 mock out 'fooble' 模組的例子。 "
1195
1195
1196
1196
#: ../../library/unittest.mock-examples.rst:1166
1197
1197
msgid ""
1198
1198
"As you can see the ``import fooble`` succeeds, but on exit there is no "
1199
1199
"'fooble' left in :data:`sys.modules`."
1200
1200
msgstr ""
1201
+ "如你所建,``import fooble`` 成功了,但在離開之後,:data:`sys.modules` 中就沒"
1202
+ "有 'fooble' 了。"
1201
1203
1202
1204
#: ../../library/unittest.mock-examples.rst:1169
1203
1205
msgid "This also works for the ``from module import name`` form:"
1204
- msgstr ""
1206
+ msgstr "這也適用於 ``from module import name`` 形式: "
1205
1207
1206
1208
#: ../../library/unittest.mock-examples.rst:1179
1207
1209
msgid "With slightly more work you can also mock package imports:"
1208
- msgstr ""
1210
+ msgstr "透過稍微多一點的處理,你也可以 mock 套件的引入: "
1209
1211
1210
1212
#: ../../library/unittest.mock-examples.rst:1192
1211
1213
msgid "Tracking order of calls and less verbose call assertions"
1212
- msgstr ""
1214
+ msgstr "追蹤呼叫順序與更簡潔的呼叫斷言 "
1213
1215
1214
1216
#: ../../library/unittest.mock-examples.rst:1194
1215
1217
msgid ""
@@ -1218,6 +1220,9 @@ msgid ""
1218
1220
"doesn't allow you to track the order of calls between separate mock objects, "
1219
1221
"however we can use :attr:`~Mock.mock_calls` to achieve the same effect."
1220
1222
msgstr ""
1223
+ ":class:`Mock` 類別可以讓你透過 :attr:`~Mock.method_calls` 屬性追蹤 mock 物件"
1224
+ "上方法呼叫的\\ *順序*。這不會讓你可以追蹤不同的 mock 物件之間的呼叫順序,然而"
1225
+ "我們可以使用 :attr:`~Mock.mock_calls` 來達到相同的效果。"
1221
1226
1222
1227
#: ../../library/unittest.mock-examples.rst:1199
1223
1228
msgid ""
@@ -1226,19 +1231,27 @@ msgid ""
1226
1231
"separate mocks from a parent one. Calls to those child mock will then all be "
1227
1232
"recorded, in order, in the ``mock_calls`` of the parent:"
1228
1233
msgstr ""
1234
+ "因為 mock 會在 ``mock_calls`` 中追蹤對子 mock 的呼叫,且存取 mock 的任意屬性"
1235
+ "會建立一個子 mock,所以我們可以從父 mock 建立不同的 mock。之後對這些子 mock "
1236
+ "的呼叫將依序全部記錄在父 mock 的 ``mock_calls`` 中:"
1229
1237
1230
1238
#: ../../library/unittest.mock-examples.rst:1216
1231
1239
msgid ""
1232
1240
"We can then assert about the calls, including the order, by comparing with "
1233
1241
"the ``mock_calls`` attribute on the manager mock:"
1234
1242
msgstr ""
1243
+ "之後我們可以透過與管理器 (manager) mock 上的 ``mock_calls`` 屬性進行比較來斷"
1244
+ "言呼叫的順序:"
1235
1245
1236
1246
#: ../../library/unittest.mock-examples.rst:1223
1237
1247
msgid ""
1238
1248
"If ``patch`` is creating, and putting in place, your mocks then you can "
1239
1249
"attach them to a manager mock using the :meth:`~Mock.attach_mock` method. "
1240
1250
"After attaching calls will be recorded in ``mock_calls`` of the manager. ::"
1241
1251
msgstr ""
1252
+ "如果 ``patch`` 正在被建立並放置為你的 mock,那麼你可以使用 :meth:`~Mock."
1253
+ "attach_mock` 方法將它們附加到管理器 mock。附加之後,呼叫將被記錄在管理器的 "
1254
+ "``mock_calls``中。: ::"
1242
1255
1243
1256
#: ../../library/unittest.mock-examples.rst:1242
1244
1257
msgid ""
@@ -1248,12 +1261,17 @@ msgid ""
1248
1261
"data:`call` object). If that sequence of calls are in :attr:`~Mock."
1249
1262
"mock_calls` then the assert succeeds."
1250
1263
msgstr ""
1264
+ "如果進行了多次呼叫,但你只對其中特定呼叫的序列感興趣,則可以是使用 :meth:"
1265
+ "`~Mock.assert_has_calls` 方法。這需要一個呼叫串列(使用 :data:`call` 物件建"
1266
+ "構)。如果該呼叫序列位於 :attr:`~Mock.mock_calls` 中,則斷言成功。"
1251
1267
1252
1268
#: ../../library/unittest.mock-examples.rst:1256
1253
1269
msgid ""
1254
1270
"Even though the chained call ``m.one().two().three()`` aren't the only calls "
1255
1271
"that have been made to the mock, the assert still succeeds."
1256
1272
msgstr ""
1273
+ "儘管鍊接呼叫 ``m.one().two().three()`` 並不是對 mock 進行的唯一呼叫,斷言仍會"
1274
+ "成功。"
1257
1275
1258
1276
#: ../../library/unittest.mock-examples.rst:1259
1259
1277
msgid ""
@@ -1262,16 +1280,21 @@ msgid ""
1262
1280
"about the order. In this case you can pass ``any_order=True`` to "
1263
1281
"``assert_has_calls``:"
1264
1282
msgstr ""
1283
+ "有時,可能會對一個 mock 進行多次呼叫,而你只對斷言其中\\ *某些*\\ 感興趣。你"
1284
+ "甚至可能不關心順序。在這種情況下,你可以將 ``any_order=True`` 傳遞給 "
1285
+ "``assert_has_calls``:"
1265
1286
1266
1287
#: ../../library/unittest.mock-examples.rst:1271
1267
1288
msgid "More complex argument matching"
1268
- msgstr ""
1289
+ msgstr "更複雜的引數匹配 "
1269
1290
1270
1291
#: ../../library/unittest.mock-examples.rst:1273
1271
1292
msgid ""
1272
1293
"Using the same basic concept as :data:`ANY` we can implement matchers to do "
1273
1294
"more complex assertions on objects used as arguments to mocks."
1274
1295
msgstr ""
1296
+ "使用與 :data:`ANY` 相同的基本概念,我們可以實作匹配器 (matcher),對用作對 "
1297
+ "mock 的引數的物件進行更複雜的斷言。"
1275
1298
1276
1299
#: ../../library/unittest.mock-examples.rst:1276
1277
1300
msgid ""
@@ -1282,27 +1305,32 @@ msgid ""
1282
1305
"attributes of this object then we can create a matcher that will check these "
1283
1306
"attributes for us."
1284
1307
msgstr ""
1308
+ "假設我們希望將某些物件傳遞給一個 mock,預設情況下,該 mock 會根據物件識別性"
1309
+ "(使用者定義類別的 Python 預設值)進行相等比較。要使用 :meth:`~Mock."
1310
+ "assert_called_with`,我們需要傳入完全相同的物件。如果我們只對該物件的某些屬性"
1311
+ "感興趣,那麼我們可以建立一個匹配器來為我們檢查這些屬性。"
1285
1312
1286
1313
#: ../../library/unittest.mock-examples.rst:1283
1287
1314
msgid ""
1288
1315
"You can see in this example how a 'standard' call to ``assert_called_with`` "
1289
1316
"isn't sufficient:"
1290
1317
msgstr ""
1318
+ "你可以在這個範例中看到對 ``assert_called_with`` 的一個「標準」呼叫是不夠的:"
1291
1319
1292
1320
#: ../../library/unittest.mock-examples.rst:1298
1293
1321
msgid ""
1294
1322
"A comparison function for our ``Foo`` class might look something like this:"
1295
- msgstr ""
1323
+ msgstr "對我們的 ``Foo`` 類別的比較函式看起來可能會像這樣: "
1296
1324
1297
1325
#: ../../library/unittest.mock-examples.rst:1310
1298
1326
msgid ""
1299
1327
"And a matcher object that can use comparison functions like this for its "
1300
1328
"equality operation would look something like this:"
1301
- msgstr ""
1329
+ msgstr "可以使用這樣的比較函式進行自身相等性運算的匹配器物件會長得像這樣: "
1302
1330
1303
1331
#: ../../library/unittest.mock-examples.rst:1321
1304
1332
msgid "Putting all this together:"
1305
- msgstr ""
1333
+ msgstr "把這些都放在一起: "
1306
1334
1307
1335
#: ../../library/unittest.mock-examples.rst:1326
1308
1336
msgid ""
@@ -1313,12 +1341,18 @@ msgid ""
1313
1341
"``assert_called_with`` passes, and if they don't an :exc:`AssertionError` is "
1314
1342
"raised:"
1315
1343
msgstr ""
1344
+ "``Matcher`` 是用我們想要比較的 ``Foo`` 物件和比較函式實例化的。在 "
1345
+ "``assert_called_with`` 中,``Matcher`` 相等方法將被呼叫,它將呼叫 mock 的物件"
1346
+ "與我們建立匹配器的物件進行比較。如果它們匹配,則 ``assert_called_with`` 會通"
1347
+ "過,如果它們不匹配,則會引發 :exc:`AssertionError`:"
1316
1348
1317
1349
#: ../../library/unittest.mock-examples.rst:1339
1318
1350
msgid ""
1319
1351
"With a bit of tweaking you could have the comparison function raise the :exc:"
1320
1352
"`AssertionError` directly and provide a more useful failure message."
1321
1353
msgstr ""
1354
+ "透過一些調整,你可以讓比較函式直接引發 :exc:`AssertionError` 並提供更有用的失"
1355
+ "敗訊息。"
1322
1356
1323
1357
#: ../../library/unittest.mock-examples.rst:1342
1324
1358
msgid ""
@@ -1328,3 +1362,8 @@ msgid ""
1328
1362
"integration.match_equality <https://pyhamcrest.readthedocs.io/en/release-1.8/"
1329
1363
"integration/#module-hamcrest.library.integration.match_equality>`_)."
1330
1364
msgstr ""
1365
+ "從版本 1.5 開始,Python 測試函式庫 `PyHamcrest <https://pyhamcrest."
1366
+ "readthedocs.io/>`_ 提供了類似的功能,在這裡可能有用,以其相等匹配器的形式 "
1367
+ "(\\ `hamcrest.library.integration.match_equality <https://pyhamcrest."
1368
+ "readthedocs.io/en/release-1.8/integration/#module-hamcrest.library."
1369
+ "integration.match_equality>`_\\ )。"
0 commit comments