@@ -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-02-26 21:40 +0800\n "
11
+ "PO-Revision-Date : 2024-03-11 22:03 +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 "
@@ -758,7 +758,7 @@ msgstr ""
758
758
759
759
#: ../../library/unittest.mock-examples.rst:683
760
760
msgid "Applying the same patch to every test method"
761
- msgstr ""
761
+ msgstr "對每個測試方法應用相同的 patch "
762
762
763
763
#: ../../library/unittest.mock-examples.rst:685
764
764
msgid ""
@@ -769,13 +769,19 @@ msgid ""
769
769
"methods on the class. A test method is identified by methods whose names "
770
770
"start with ``test``::"
771
771
msgstr ""
772
+ "如果你希望 patch 能用在多個測試方法上,顯而易見的方式是將 patch 裝飾器應用於"
773
+ "每個方法。這感覺是不必要的重複行為,因此你可以使用 :func:`patch`\\ (及其他 "
774
+ "patch 的變體)作為類別裝飾器。這會將 patch 應用在該類別的所有測試方法上。測試"
775
+ "方法由名稱以 ``test`` 開頭來識別: ::"
772
776
773
777
#: ../../library/unittest.mock-examples.rst:709
774
778
msgid ""
775
779
"An alternative way of managing patches is to use the :ref:`start-and-stop`. "
776
780
"These allow you to move the patching into your ``setUp`` and ``tearDown`` "
777
781
"methods. ::"
778
782
msgstr ""
783
+ "管理 patch 的另一種方式是使用 :ref:`start-and-stop`。這允許你將 patch 移到你"
784
+ "的 ``setUp`` 與 ``tearDown`` 方法中。: ::"
779
785
780
786
#: ../../library/unittest.mock-examples.rst:726
781
787
msgid ""
@@ -784,10 +790,13 @@ msgid ""
784
790
"exception is raised in the setUp then tearDown is not called. :meth:"
785
791
"`unittest.TestCase.addCleanup` makes this easier::"
786
792
msgstr ""
793
+ "如果你使用這個技巧,你必須確保透過呼叫 ``stop`` 來 \" 取消\" patch。這可能會比"
794
+ "你想像的還要複雜一點,因為如果有例外在 ``setUp`` 中被引發,則 ``tearDown`` 就"
795
+ "不會被呼叫。:meth:`unittest.TestCase.addCleanup` 會讓這稍微簡單一點: ::"
787
796
788
797
#: ../../library/unittest.mock-examples.rst:744
789
798
msgid "Mocking Unbound Methods"
790
- msgstr ""
799
+ msgstr "Mock Unbound Methods (未繫結方法) "
791
800
792
801
#: ../../library/unittest.mock-examples.rst:746
793
802
msgid ""
@@ -802,6 +811,13 @@ msgid ""
802
811
"to patch out methods with a mock that having to create a real function "
803
812
"becomes a nuisance."
804
813
msgstr ""
814
+ "在撰寫測試時,當我們需要 patch 一個\\ *未繫結方法*\\ (patch 類別上的方法而不"
815
+ "是實例上的方法)。我們需要將 self 作為第一個引數傳入,因為我們想斷言哪些物件"
816
+ "正在呼叫這個特定方法。問題是你無法為此使用 mock 進行 patch,因為就算你用一個 "
817
+ "mock 替換未繫結方法,從實例取得它時它也不會成為一個繫結方法,因此 self 並不會"
818
+ "被傳遞。解決方法是使用真實的函式來 patch 未繫結方法。:func:`patch` 裝飾器使得"
819
+ "用 mock 來 patch out 方法是如此的簡單,以至於建立一個真正的函式相對變得很麻"
820
+ "煩。"
805
821
806
822
#: ../../library/unittest.mock-examples.rst:757
807
823
msgid ""
@@ -814,29 +830,38 @@ msgid ""
814
830
"instance. It will have ``self`` passed in as the first argument, which is "
815
831
"exactly what I wanted:"
816
832
msgstr ""
833
+ "如果你將 ``autospec=True`` 傳遞給 patch,那麼它會使用\\ *真的*\\ 函式物件來進"
834
+ "行 patch。此函式物件與它所替換的函式物件具有相同的簽名,但實際上委託給 mock。"
835
+ "你仍然會以與之前完全相同的方式自動建立 mock。但這意味著,如果你使用它來 "
836
+ "patch 類別上的未繫結方法,則從實例取得的 mock 函式將轉換為繫結方法。``self`` "
837
+ "會作為其第一個引數傳入,而這正是我們想要的:"
817
838
818
839
#: ../../library/unittest.mock-examples.rst:778
819
840
msgid ""
820
841
"If we don't use ``autospec=True`` then the unbound method is patched out "
821
842
"with a Mock instance instead, and isn't called with ``self``."
822
843
msgstr ""
844
+ "如果我們不使用 ``autospec=True``,那麼未繫結方法將使用一個 Mock 實例 patch "
845
+ "out,並且不被使用 ``self`` 進行呼叫。"
823
846
824
847
#: ../../library/unittest.mock-examples.rst:783
825
848
msgid "Checking multiple calls with mock"
826
- msgstr ""
849
+ msgstr "使用 mock 檢查多個呼叫 "
827
850
828
851
#: ../../library/unittest.mock-examples.rst:785
829
852
msgid ""
830
853
"mock has a nice API for making assertions about how your mock objects are "
831
854
"used."
832
- msgstr ""
855
+ msgstr "mock 有很好的 API,用於對 mock 物件的使用方式做出斷言。 "
833
856
834
857
#: ../../library/unittest.mock-examples.rst:792
835
858
msgid ""
836
859
"If your mock is only being called once you can use the :meth:`~Mock."
837
860
"assert_called_once_with` method that also asserts that the :attr:`~Mock."
838
861
"call_count` is one."
839
862
msgstr ""
863
+ "如果你的 mock 只被呼叫一次,你可以使用 :meth:`~Mock.assert_called_once_with` "
864
+ "方法,其也斷言 :attr:`~Mock.call_count` 是1。"
840
865
841
866
#: ../../library/unittest.mock-examples.rst:803
842
867
msgid ""
@@ -845,6 +870,9 @@ msgid ""
845
870
"times, and you want to make assertions about *all* those calls you can use :"
846
871
"attr:`~Mock.call_args_list`:"
847
872
msgstr ""
873
+ "``assert_called_with`` 和 ``assert_called_once_with`` 都對\\ *最近一次*\\ 的"
874
+ "呼叫做出斷言。如果你的 mock 將被多次呼叫,並且你想要對\\ *所有*\\ 這些呼叫進"
875
+ "行斷言,你可以使用 :attr:`~Mock.call_args_list`:"
848
876
849
877
#: ../../library/unittest.mock-examples.rst:815
850
878
msgid ""
@@ -853,10 +881,13 @@ msgid ""
853
881
"``call_args_list``. This looks remarkably similar to the repr of the "
854
882
"``call_args_list``:"
855
883
msgstr ""
884
+ ":data:`call` 輔助函式可以輕鬆地對這些呼叫做出斷言。你可以建立預期呼叫的清單並"
885
+ "將其與 ``call_args_list`` 進行比較。這看起來與 ``call_args_list`` 的 repr 非"
886
+ "常相似:"
856
887
857
888
#: ../../library/unittest.mock-examples.rst:825
858
889
msgid "Coping with mutable arguments"
859
- msgstr ""
890
+ msgstr "應對可變引數 "
860
891
861
892
#: ../../library/unittest.mock-examples.rst:827
862
893
msgid ""
@@ -866,6 +897,9 @@ msgid ""
866
897
"under test then you can no longer make assertions about what the values were "
867
898
"when the mock was called."
868
899
msgstr ""
900
+ "另一種情況很少見,但可能會困擾你,那就是當你的 mock 被使用可變引數呼叫。"
901
+ "``call_args`` 和 ``call_args_list`` 儲存對引數的\\ *參照*。如果引數被測試中的"
902
+ "程式碼改變,那麼你將無法再對 mock 被呼叫時的值進行斷言。"
869
903
870
904
#: ../../library/unittest.mock-examples.rst:832
871
905
msgid ""
0 commit comments