@@ -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 -26 19:03 +0800\n "
11
+ "PO-Revision-Date : 2024-02 -26 21:40 +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 "
@@ -627,7 +627,7 @@ msgstr ""
627
627
628
628
#: ../../library/unittest.mock-examples.rst:601
629
629
msgid "Partial mocking"
630
- msgstr ""
630
+ msgstr "部分 mocking "
631
631
632
632
#: ../../library/unittest.mock-examples.rst:603
633
633
msgid ""
@@ -637,13 +637,19 @@ msgid ""
637
637
"in C, and so I couldn't just monkey-patch out the static :meth:`datetime."
638
638
"date.today` method."
639
639
msgstr ""
640
+ "在某些測試中,我們會想 mock 對 :meth:`datetime.date.today` 的呼叫以回傳一個已"
641
+ "知日期,但我不想阻止測試中的程式碼建立新的日期物件。不幸的是 :class:"
642
+ "`datetime.date` 是用 C 語言寫的,所以們我不能 monkey patch 靜態的 :meth:"
643
+ "`datetime.date.today` 方法。"
640
644
641
645
#: ../../library/unittest.mock-examples.rst:608
642
646
msgid ""
643
647
"I found a simple way of doing this that involved effectively wrapping the "
644
648
"date class with a mock, but passing through calls to the constructor to the "
645
649
"real class (and returning real instances)."
646
650
msgstr ""
651
+ "我們找到了一種簡單的方法來做到這一點,其用 mock 有效地包裝日期類別,但將對建"
652
+ "構函式的呼叫傳遞給真實的類別(並返回真實的實例)。"
647
653
648
654
#: ../../library/unittest.mock-examples.rst:612
649
655
msgid ""
@@ -653,12 +659,18 @@ msgid ""
653
659
"date. When the mock date class is called a real date will be constructed and "
654
660
"returned by ``side_effect``. ::"
655
661
msgstr ""
662
+ "這裡使用 :func:`patch 裝飾器 <patch>` 來 mock 被測模組中的 ``date`` 類別。然"
663
+ "後,mock 日期類別上的 :attr:`~Mock.side_effect` 屬性會被設定為回傳真實日期的 "
664
+ "lambda 函式。當 mock 日期類別被呼叫時,將透過 ``side_effect`` 建構並回傳真實"
665
+ "日期。: ::"
656
666
657
667
#: ../../library/unittest.mock-examples.rst:626
658
668
msgid ""
659
669
"Note that we don't patch :class:`datetime.date` globally, we patch ``date`` "
660
670
"in the module that *uses* it. See :ref:`where to patch <where-to-patch>`."
661
671
msgstr ""
672
+ "注意,我們沒有全域 patch :class:`datetime.date`,而是在\\ *使用*\\ 它的模組"
673
+ "中 patch ``date``。請參閱 :ref:`該 patch 何處 <where-to-patch>`。"
662
674
663
675
#: ../../library/unittest.mock-examples.rst:629
664
676
msgid ""
@@ -667,29 +679,40 @@ msgid ""
667
679
"find yourself having to calculate an expected result using exactly the same "
668
680
"algorithm as the code under test, which is a classic testing anti-pattern."
669
681
msgstr ""
682
+ "當 ``date.today()`` 被呼叫時,一個已知日期會被回傳,但對 ``date(...)`` 建構函"
683
+ "式的呼叫仍然會回傳正常日期。如果不這樣使用,你可能會發現自己必須使用與被測程"
684
+ "式碼完全相同的演算法來計算預期結果,這是一個典型的測試的反面模式 (anti-"
685
+ "pattern)。"
670
686
671
687
#: ../../library/unittest.mock-examples.rst:634
672
688
msgid ""
673
689
"Calls to the date constructor are recorded in the ``mock_date`` attributes "
674
690
"(``call_count`` and friends) which may also be useful for your tests."
675
691
msgstr ""
692
+ "對日期建構函式的呼叫被記錄在 ``mock_date`` 屬性(\\ ``call_count`` 和它的朋友"
693
+ "們)中,這對你的測試也可能有用處。"
676
694
677
695
#: ../../library/unittest.mock-examples.rst:637
678
696
msgid ""
679
697
"An alternative way of dealing with mocking dates, or other builtin classes, "
680
698
"is discussed in `this blog entry <https://williambert.online/2011/07/how-to-"
681
699
"unit-testing-in-django-with-mocking-and-patching/>`_."
682
700
msgstr ""
701
+ "處理 mock 日期或其他內建類別的另一種方法在 `這個 blog <https://williambert."
702
+ "online/2011/07/how-to-unit-testing-in-django-with-mocking-and-patching/>`_ 中"
703
+ "討論。"
683
704
684
705
#: ../../library/unittest.mock-examples.rst:643
685
706
msgid "Mocking a Generator Method"
686
- msgstr ""
707
+ msgstr "Mock 產生器方法 "
687
708
688
709
#: ../../library/unittest.mock-examples.rst:645
689
710
msgid ""
690
711
"A Python generator is a function or method that uses the :keyword:`yield` "
691
712
"statement to return a series of values when iterated over [#]_."
692
713
msgstr ""
714
+ "Python 產生器是一個函式或方法,它使用 :keyword:`yield` 陳述式在疊代 [#]_ 時回"
715
+ "傳一系列的值。"
693
716
694
717
#: ../../library/unittest.mock-examples.rst:648
695
718
msgid ""
@@ -698,22 +721,27 @@ msgid ""
698
721
"iteration is :meth:`~container.__iter__`, so we can mock this using a :class:"
699
722
"`MagicMock`."
700
723
msgstr ""
724
+ "產生器方法 / 函式會被呼叫以回傳產生器物件。之後此產生器會進行疊代。疊代的協定"
725
+ "方法是 :meth:`~container.__iter__`,所以我們可以使用 :class:`MagicMock` 來 "
726
+ "mock 它。"
701
727
702
728
#: ../../library/unittest.mock-examples.rst:653
703
729
msgid ""
704
730
"Here's an example class with an \" iter\" method implemented as a generator:"
705
- msgstr ""
731
+ msgstr "下面是一個範例類別,其包含實作產生器的一個 \" iter \" 方法: "
706
732
707
733
#: ../../library/unittest.mock-examples.rst:665
708
734
msgid "How would we mock this class, and in particular its \" iter\" method?"
709
- msgstr ""
735
+ msgstr "我們該如何 mock 這個類別,特別是它的 \" iter \" 方法呢? "
710
736
711
737
#: ../../library/unittest.mock-examples.rst:667
712
738
msgid ""
713
739
"To configure the values returned from the iteration (implicit in the call "
714
740
"to :class:`list`), we need to configure the object returned by the call to "
715
741
"``foo.iter()``."
716
742
msgstr ""
743
+ "要配置從疊代回傳的值(隱含在對 :class:`list` 的呼叫中),我們需要配置呼叫 "
744
+ "``foo.iter()`` 所回傳的物件。"
717
745
718
746
#: ../../library/unittest.mock-examples.rst:675
719
747
msgid ""
@@ -723,6 +751,10 @@ msgid ""
723
751
"they are is: `Generator Tricks for Systems Programmers <http://www.dabeaz."
724
752
"com/generators/>`_."
725
753
msgstr ""
754
+ "還有關於產生器運算式及產生器的更多 `進階用法 <http://www.dabeaz.com/"
755
+ "coroutines/index.html>`_ ,但我們在這裡不考慮它們。一個關於產生器及其強大功能"
756
+ "的優良說明是:`Generator Tricks for Systems Programmers <http://www.dabeaz."
757
+ "com/generators/>`_。"
726
758
727
759
#: ../../library/unittest.mock-examples.rst:683
728
760
msgid "Applying the same patch to every test method"
0 commit comments