@@ -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-02-26 21:40 +0800\n "
11+ "PO-Revision-Date :2024-03-11 22:03 +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 "
@@ -758,7 +758,7 @@ msgstr ""
758758
759759#: ../../library/unittest.mock-examples.rst:683
760760msgid "Applying the same patch to every test method"
761- msgstr ""
761+ msgstr "對每個測試方法應用相同的 patch "
762762
763763#: ../../library/unittest.mock-examples.rst:685
764764msgid ""
@@ -769,13 +769,19 @@ msgid ""
769769"methods on the class. A test method is identified by methods whose names "
770770"start with ``test``::"
771771msgstr ""
772+ "如果你希望 patch 能用在多個測試方法上,顯而易見的方式是將 patch 裝飾器應用於"
773+ "每個方法。這感覺是不必要的重複行為,因此你可以使用 :func:`patch`\\ (及其他 "
774+ "patch 的變體)作為類別裝飾器。這會將 patch 應用在該類別的所有測試方法上。測試"
775+ "方法由名稱以 ``test`` 開頭來識別: ::"
772776
773777#: ../../library/unittest.mock-examples.rst:709
774778msgid ""
775779"An alternative way of managing patches is to use the :ref:`start-and-stop`. "
776780"These allow you to move the patching into your ``setUp`` and ``tearDown`` "
777781"methods. ::"
778782msgstr ""
783+ "管理 patch 的另一種方式是使用 :ref:`start-and-stop`。這允許你將 patch 移到你"
784+ "的 ``setUp`` 與 ``tearDown`` 方法中。: ::"
779785
780786#: ../../library/unittest.mock-examples.rst:726
781787msgid ""
@@ -784,10 +790,13 @@ msgid ""
784790"exception is raised in the setUp then tearDown is not called. :meth:"
785791"`unittest.TestCase.addCleanup` makes this easier::"
786792msgstr ""
793+ "如果你使用這個技巧,你必須確保透過呼叫 ``stop`` 來\" 取消\" patch。這可能會比"
794+ "你想像的還要複雜一點,因為如果有例外在 ``setUp`` 中被引發,則 ``tearDown`` 就"
795+ "不會被呼叫。:meth:`unittest.TestCase.addCleanup` 會讓這稍微簡單一點: ::"
787796
788797#: ../../library/unittest.mock-examples.rst:744
789798msgid "Mocking Unbound Methods"
790- msgstr ""
799+ msgstr "Mock Unbound Methods (未繫結方法) "
791800
792801#: ../../library/unittest.mock-examples.rst:746
793802msgid ""
@@ -802,6 +811,13 @@ msgid ""
802811"to patch out methods with a mock that having to create a real function "
803812"becomes a nuisance."
804813msgstr ""
814+ "在撰寫測試時,當我們需要 patch 一個\\ *未繫結方法*\\ (patch 類別上的方法而不"
815+ "是實例上的方法)。我們需要將 self 作為第一個引數傳入,因為我們想斷言哪些物件"
816+ "正在呼叫這個特定方法。問題是你無法為此使用 mock 進行 patch,因為就算你用一個 "
817+ "mock 替換未繫結方法,從實例取得它時它也不會成為一個繫結方法,因此 self 並不會"
818+ "被傳遞。解決方法是使用真實的函式來 patch 未繫結方法。:func:`patch` 裝飾器使得"
819+ "用 mock 來 patch out 方法是如此的簡單,以至於建立一個真正的函式相對變得很麻"
820+ "煩。"
805821
806822#: ../../library/unittest.mock-examples.rst:757
807823msgid ""
@@ -814,29 +830,38 @@ msgid ""
814830"instance. It will have ``self`` passed in as the first argument, which is "
815831"exactly what I wanted:"
816832msgstr ""
833+ "如果你將 ``autospec=True`` 傳遞給 patch,那麼它會使用\\ *真的*\\ 函式物件來進"
834+ "行 patch。此函式物件與它所替換的函式物件具有相同的簽名,但實際上委託給 mock。"
835+ "你仍然會以與之前完全相同的方式自動建立 mock。但這意味著,如果你使用它來 "
836+ "patch 類別上的未繫結方法,則從實例取得的 mock 函式將轉換為繫結方法。``self`` "
837+ "會作為其第一個引數傳入,而這正是我們想要的:"
817838
818839#: ../../library/unittest.mock-examples.rst:778
819840msgid ""
820841"If we don't use ``autospec=True`` then the unbound method is patched out "
821842"with a Mock instance instead, and isn't called with ``self``."
822843msgstr ""
844+ "如果我們不使用 ``autospec=True``,那麼未繫結方法將使用一個 Mock 實例 patch "
845+ "out,並且不被使用 ``self`` 進行呼叫。"
823846
824847#: ../../library/unittest.mock-examples.rst:783
825848msgid "Checking multiple calls with mock"
826- msgstr ""
849+ msgstr "使用 mock 檢查多個呼叫 "
827850
828851#: ../../library/unittest.mock-examples.rst:785
829852msgid ""
830853"mock has a nice API for making assertions about how your mock objects are "
831854"used."
832- msgstr ""
855+ msgstr "mock 有很好的 API,用於對 mock 物件的使用方式做出斷言。 "
833856
834857#: ../../library/unittest.mock-examples.rst:792
835858msgid ""
836859"If your mock is only being called once you can use the :meth:`~Mock."
837860"assert_called_once_with` method that also asserts that the :attr:`~Mock."
838861"call_count` is one."
839862msgstr ""
863+ "如果你的 mock 只被呼叫一次,你可以使用 :meth:`~Mock.assert_called_once_with` "
864+ "方法,其也斷言 :attr:`~Mock.call_count` 是1。"
840865
841866#: ../../library/unittest.mock-examples.rst:803
842867msgid ""
@@ -845,6 +870,9 @@ msgid ""
845870"times, and you want to make assertions about *all* those calls you can use :"
846871"attr:`~Mock.call_args_list`:"
847872msgstr ""
873+ "``assert_called_with`` 和 ``assert_called_once_with`` 都對\\ *最近一次*\\ 的"
874+ "呼叫做出斷言。如果你的 mock 將被多次呼叫,並且你想要對\\ *所有*\\ 這些呼叫進"
875+ "行斷言,你可以使用 :attr:`~Mock.call_args_list`:"
848876
849877#: ../../library/unittest.mock-examples.rst:815
850878msgid ""
@@ -853,10 +881,13 @@ msgid ""
853881"``call_args_list``. This looks remarkably similar to the repr of the "
854882"``call_args_list``:"
855883msgstr ""
884+ ":data:`call` 輔助函式可以輕鬆地對這些呼叫做出斷言。你可以建立預期呼叫的清單並"
885+ "將其與 ``call_args_list`` 進行比較。這看起來與 ``call_args_list`` 的 repr 非"
886+ "常相似:"
856887
857888#: ../../library/unittest.mock-examples.rst:825
858889msgid "Coping with mutable arguments"
859- msgstr ""
890+ msgstr "應對可變引數 "
860891
861892#: ../../library/unittest.mock-examples.rst:827
862893msgid ""
@@ -866,6 +897,9 @@ msgid ""
866897"under test then you can no longer make assertions about what the values were "
867898"when the mock was called."
868899msgstr ""
900+ "另一種情況很少見,但可能會困擾你,那就是當你的 mock 被使用可變引數呼叫。"
901+ "``call_args`` 和 ``call_args_list`` 儲存對引數的\\ *參照*。如果引數被測試中的"
902+ "程式碼改變,那麼你將無法再對 mock 被呼叫時的值進行斷言。"
869903
870904#: ../../library/unittest.mock-examples.rst:832
871905msgid ""