@@ -8,7 +8,7 @@ msgstr ""
88"Project-Id-Version :Python 3.12\n "
99"Report-Msgid-Bugs-To :\n "
1010"POT-Creation-Date :2023-09-09 00:03+0000\n "
11- "PO-Revision-Date :2024-01-1401 :14+0800\n "
11+ "PO-Revision-Date :2024-01-1418 :14+0800\n "
1212"Last-Translator :Liang-Bo Wang <me@liang2.tw>\n "
1313"Language-Team :Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
1414"tw)\n "
@@ -256,18 +256,20 @@ msgstr ""
256256
257257#: ../../library/unittest.mock-examples.rst:233
258258msgid "Raising exceptions with mocks"
259- msgstr ""
259+ msgstr "透過 mock 引發例外 "
260260
261261#: ../../library/unittest.mock-examples.rst:235
262262msgid ""
263263"A useful attribute is :attr:`~Mock.side_effect`. If you set this to an "
264264"exception class or instance then the exception will be raised when the mock "
265265"is called."
266266msgstr ""
267+ "一個有用的屬性是 :attr:`~Mock.side_effect`。如果將其設定為例外類別或實例,則"
268+ "當 mock 被呼叫時將引發例外。"
267269
268270#: ../../library/unittest.mock-examples.rst:247
269271msgid "Side effect functions and iterables"
270- msgstr ""
272+ msgstr "Side effect 函式以及可疊代物件 "
271273
272274#: ../../library/unittest.mock-examples.rst:249
273275msgid ""
@@ -277,6 +279,10 @@ msgid ""
277279"set ``side_effect`` to an iterable every call to the mock returns the next "
278280"value from the iterable:"
279281msgstr ""
282+ "``side_effect`` 也可以設定為函式或可疊代物件。``side_effect`` 作為可疊代物件"
283+ "的使用案例是:當你的 mock 將會被多次呼叫,且你希望每次呼叫回傳不同的值。當你"
284+ "將``side_effect`` 設定為可疊代物件時,對 mock 的每次呼叫都會傳回可疊代物件中"
285+ "的下一個值:"
280286
281287#: ../../library/unittest.mock-examples.rst:264
282288msgid ""
@@ -285,10 +291,13 @@ msgid ""
285291"function. The function will be called with the same arguments as the mock. "
286292"Whatever the function returns is what the call returns:"
287293msgstr ""
294+ "對於更進階的使用案例,例如根據 mock 被呼叫的內容動態變更回傳值,"
295+ "``side_effect`` 可以是一個函式。該函式會使用與 mock 相同的引數被呼叫。函式回"
296+ "傳的內容就會是呼叫回傳的內容:"
288297
289298#: ../../library/unittest.mock-examples.rst:281
290299msgid "Mocking asynchronous iterators"
291- msgstr ""
300+ msgstr "Mock 非同步可疊代物件 "
292301
293302#: ../../library/unittest.mock-examples.rst:283
294303msgid ""
@@ -297,10 +306,13 @@ msgid ""
297306"attribute of ``__aiter__`` can be used to set the return values to be used "
298307"for iteration."
299308msgstr ""
309+ "從 Python 3.8 開始,``AsyncMock`` 和 ``MagicMock`` 支援透過 ``__aiter__`` 來 "
310+ "mock :ref:`async-iterators`。``__aiter__`` 的 :attr:`~Mock.return_value` 屬性"
311+ "可用來設定用於疊代的回傳值。"
300312
301313#: ../../library/unittest.mock-examples.rst:298
302314msgid "Mocking asynchronous context manager"
303- msgstr ""
315+ msgstr "Mock 非同步情境管理器 "
304316
305317#: ../../library/unittest.mock-examples.rst:300
306318msgid ""
@@ -309,10 +321,13 @@ msgid ""
309321"default, ``__aenter__`` and ``__aexit__`` are ``AsyncMock`` instances that "
310322"return an async function."
311323msgstr ""
324+ "從 Python 3.8 開始,``AsyncMock`` 和 ``MagicMock`` 支援透過 ``__aenter__`` "
325+ "和 ``__aexit__`` 來 mock :ref:`async-context-managers`。預設情況下,"
326+ "``__aenter__`` 和 ``__aexit__`` 是回傳非同步函式的 ``AsyncMock`` 實例。"
312327
313328#: ../../library/unittest.mock-examples.rst:322
314329msgid "Creating a Mock from an Existing Object"
315- msgstr ""
330+ msgstr "從現有物件建立 mock "
316331
317332#: ../../library/unittest.mock-examples.rst:324
318333msgid ""
@@ -323,6 +338,11 @@ msgid ""
323338"you refactor the first class, so that it no longer has ``some_method`` - "
324339"then your tests will continue to pass even though your code is now broken!"
325340msgstr ""
341+ "過度使用 mock 的一個問題是,它將你的測試與 mock 的實現結合在一起,而不是與真"
342+ "實的程式碼結合。假設你有一個實作 ``some_method`` 的類別,在另一個類別的測試"
343+ "中,你提供了一個 mock 的物件,其*也*提供了 ``some_method``。如果之後你重構第"
344+ "一個類別,使其不再具有 ``some_method`` - 那麼即使你的程式碼已經損壞,你的測試"
345+ "也將繼續通過!"
326346
327347#: ../../library/unittest.mock-examples.rst:331
328348msgid ""
@@ -333,26 +353,35 @@ msgid ""
333353"specification, then tests that use that class will start failing immediately "
334354"without you having to instantiate the class in those tests."
335355msgstr ""
356+ ":class:`Mock` 允許你使用 *spec* 關鍵字引數提供一個物件作為 mock 的規格。 對 "
357+ "mock 存取規格物件上不存在的方法或屬性將立即引發一個屬性錯誤。如果你更改規格的"
358+ "實作,那麼使用該類別的測試將立即失敗,而無需在這些測試中實例化該類別。"
336359
337360#: ../../library/unittest.mock-examples.rst:344
338361msgid ""
339362"Using a specification also enables a smarter matching of calls made to the "
340363"mock, regardless of whether some parameters were passed as positional or "
341364"named arguments::"
342365msgstr ""
366+ "使用規格還可以更聰明地匹配對 mock 的呼叫,無論引數是作為位置引數還是命名引數"
367+ "傳遞: ::"
343368
344369#: ../../library/unittest.mock-examples.rst:355
345370msgid ""
346371"If you want this smarter matching to also work with method calls on the "
347372"mock, you can use :ref:`auto-speccing <auto-speccing>`."
348373msgstr ""
374+ "如果你希望這種更聰明的匹配也可以應用於 mock 上的方法呼叫,你可以使用\\ :ref:`"
375+ "自動規格 <auto-speccing>`。"
349376
350377#: ../../library/unittest.mock-examples.rst:358
351378msgid ""
352379"If you want a stronger form of specification that prevents the setting of "
353380"arbitrary attributes as well as the getting of them then you can use "
354381"*spec_set* instead of *spec*."
355382msgstr ""
383+ "如果你想要一種更強大的規格形式來防止設定任意屬性以及取得它們,那麼你可以使用 "
384+ "*spec_set* 而不是 *spec*。"
356385
357386#: ../../library/unittest.mock-examples.rst:364
358387msgid "Using side_effect to return per file content"