@@ -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-01-14 01 :14+0800\n "
11
+ "PO-Revision-Date : 2024-01-14 18 :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 "
@@ -256,18 +256,20 @@ msgstr ""
256
256
257
257
#: ../../library/unittest.mock-examples.rst:233
258
258
msgid "Raising exceptions with mocks"
259
- msgstr ""
259
+ msgstr "透過 mock 引發例外 "
260
260
261
261
#: ../../library/unittest.mock-examples.rst:235
262
262
msgid ""
263
263
"A useful attribute is :attr:`~Mock.side_effect`. If you set this to an "
264
264
"exception class or instance then the exception will be raised when the mock "
265
265
"is called."
266
266
msgstr ""
267
+ "一個有用的屬性是 :attr:`~Mock.side_effect`。如果將其設定為例外類別或實例,則"
268
+ "當 mock 被呼叫時將引發例外。"
267
269
268
270
#: ../../library/unittest.mock-examples.rst:247
269
271
msgid "Side effect functions and iterables"
270
- msgstr ""
272
+ msgstr "Side effect 函式以及可疊代物件 "
271
273
272
274
#: ../../library/unittest.mock-examples.rst:249
273
275
msgid ""
@@ -277,6 +279,10 @@ msgid ""
277
279
"set ``side_effect`` to an iterable every call to the mock returns the next "
278
280
"value from the iterable:"
279
281
msgstr ""
282
+ "``side_effect`` 也可以設定為函式或可疊代物件。``side_effect`` 作為可疊代物件"
283
+ "的使用案例是:當你的 mock 將會被多次呼叫,且你希望每次呼叫回傳不同的值。當你"
284
+ "將``side_effect`` 設定為可疊代物件時,對 mock 的每次呼叫都會傳回可疊代物件中"
285
+ "的下一個值:"
280
286
281
287
#: ../../library/unittest.mock-examples.rst:264
282
288
msgid ""
@@ -285,10 +291,13 @@ msgid ""
285
291
"function. The function will be called with the same arguments as the mock. "
286
292
"Whatever the function returns is what the call returns:"
287
293
msgstr ""
294
+ "對於更進階的使用案例,例如根據 mock 被呼叫的內容動態變更回傳值,"
295
+ "``side_effect`` 可以是一個函式。該函式會使用與 mock 相同的引數被呼叫。函式回"
296
+ "傳的內容就會是呼叫回傳的內容:"
288
297
289
298
#: ../../library/unittest.mock-examples.rst:281
290
299
msgid "Mocking asynchronous iterators"
291
- msgstr ""
300
+ msgstr "Mock 非同步可疊代物件 "
292
301
293
302
#: ../../library/unittest.mock-examples.rst:283
294
303
msgid ""
@@ -297,10 +306,13 @@ msgid ""
297
306
"attribute of ``__aiter__`` can be used to set the return values to be used "
298
307
"for iteration."
299
308
msgstr ""
309
+ "從 Python 3.8 開始,``AsyncMock`` 和 ``MagicMock`` 支援透過 ``__aiter__`` 來 "
310
+ "mock :ref:`async-iterators`。``__aiter__`` 的 :attr:`~Mock.return_value` 屬性"
311
+ "可用來設定用於疊代的回傳值。"
300
312
301
313
#: ../../library/unittest.mock-examples.rst:298
302
314
msgid "Mocking asynchronous context manager"
303
- msgstr ""
315
+ msgstr "Mock 非同步情境管理器 "
304
316
305
317
#: ../../library/unittest.mock-examples.rst:300
306
318
msgid ""
@@ -309,10 +321,13 @@ msgid ""
309
321
"default, ``__aenter__`` and ``__aexit__`` are ``AsyncMock`` instances that "
310
322
"return an async function."
311
323
msgstr ""
324
+ "從 Python 3.8 開始,``AsyncMock`` 和 ``MagicMock`` 支援透過 ``__aenter__`` "
325
+ "和 ``__aexit__`` 來 mock :ref:`async-context-managers`。預設情況下,"
326
+ "``__aenter__`` 和 ``__aexit__`` 是回傳非同步函式的 ``AsyncMock`` 實例。"
312
327
313
328
#: ../../library/unittest.mock-examples.rst:322
314
329
msgid "Creating a Mock from an Existing Object"
315
- msgstr ""
330
+ msgstr "從現有物件建立 mock "
316
331
317
332
#: ../../library/unittest.mock-examples.rst:324
318
333
msgid ""
@@ -323,6 +338,11 @@ msgid ""
323
338
"you refactor the first class, so that it no longer has ``some_method`` - "
324
339
"then your tests will continue to pass even though your code is now broken!"
325
340
msgstr ""
341
+ "過度使用 mock 的一個問題是,它將你的測試與 mock 的實現結合在一起,而不是與真"
342
+ "實的程式碼結合。假設你有一個實作 ``some_method`` 的類別,在另一個類別的測試"
343
+ "中,你提供了一個 mock 的物件,其*也*提供了 ``some_method``。如果之後你重構第"
344
+ "一個類別,使其不再具有 ``some_method`` - 那麼即使你的程式碼已經損壞,你的測試"
345
+ "也將繼續通過!"
326
346
327
347
#: ../../library/unittest.mock-examples.rst:331
328
348
msgid ""
@@ -333,26 +353,35 @@ msgid ""
333
353
"specification, then tests that use that class will start failing immediately "
334
354
"without you having to instantiate the class in those tests."
335
355
msgstr ""
356
+ ":class:`Mock` 允許你使用 *spec* 關鍵字引數提供一個物件作為 mock 的規格。 對 "
357
+ "mock 存取規格物件上不存在的方法或屬性將立即引發一個屬性錯誤。如果你更改規格的"
358
+ "實作,那麼使用該類別的測試將立即失敗,而無需在這些測試中實例化該類別。"
336
359
337
360
#: ../../library/unittest.mock-examples.rst:344
338
361
msgid ""
339
362
"Using a specification also enables a smarter matching of calls made to the "
340
363
"mock, regardless of whether some parameters were passed as positional or "
341
364
"named arguments::"
342
365
msgstr ""
366
+ "使用規格還可以更聰明地匹配對 mock 的呼叫,無論引數是作為位置引數還是命名引數"
367
+ "傳遞: ::"
343
368
344
369
#: ../../library/unittest.mock-examples.rst:355
345
370
msgid ""
346
371
"If you want this smarter matching to also work with method calls on the "
347
372
"mock, you can use :ref:`auto-speccing <auto-speccing>`."
348
373
msgstr ""
374
+ "如果你希望這種更聰明的匹配也可以應用於 mock 上的方法呼叫,你可以使用\\ :ref:`"
375
+ "自動規格 <auto-speccing>`。"
349
376
350
377
#: ../../library/unittest.mock-examples.rst:358
351
378
msgid ""
352
379
"If you want a stronger form of specification that prevents the setting of "
353
380
"arbitrary attributes as well as the getting of them then you can use "
354
381
"*spec_set* instead of *spec*."
355
382
msgstr ""
383
+ "如果你想要一種更強大的規格形式來防止設定任意屬性以及取得它們,那麼你可以使用 "
384
+ "*spec_set* 而不是 *spec*。"
356
385
357
386
#: ../../library/unittest.mock-examples.rst:364
358
387
msgid "Using side_effect to return per file content"
0 commit comments