Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: translate rst:1112 to rst:1433#793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mattwang44 merged 3 commits intopython:3.12fromken71301:translate-mock
Jan 15, 2024
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 108 additions & 11 deletionslibrary/unittest.mock.po
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: Python 3.12\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-12-16 00:03+0000\n"
"PO-Revision-Date:2023-12-04 21:31+0800\n"
"PO-Revision-Date:2024-01-12 08:51+0800\n"
"Last-Translator: Adrian Liaw <adrianliaw2000@gmail.com>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
Expand All@@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.4.1\n"
"X-Generator: Poedit 3.4.2\n"

#: ../../library/unittest.mock.rst:3
msgid ":mod:`unittest.mock` --- mock object library"
Expand DownExpand Up@@ -1015,25 +1015,34 @@ msgid ""
"explicitly or by calling the Mock) - but it is stored and the same one "
"returned each time."
msgstr ""
"Mock 物件可被呼叫。呼叫將回傳設定為 :attr:`~Mock.return_value` 屬性的值。預設"
"的回傳值是一個新的 Mock 物件;它會在第一次存取回傳值時(無論是顯式存取還是透"
"過呼叫 Mock)被建立,但是這個回傳值會被儲存,之後每次都回傳同一個值。"

#: ../../library/unittest.mock.rst:1112
msgid ""
"Calls made to the object will be recorded in the attributes like :attr:"
"`~Mock.call_args` and :attr:`~Mock.call_args_list`."
msgstr ""
"對物件的呼叫會被記錄在如 :attr:`~Mock.call_args` 和 :attr:`~Mock."
"call_args_list` 等屬性中。"

#: ../../library/unittest.mock.rst:1115
msgid ""
"If :attr:`~Mock.side_effect` is set then it will be called after the call "
"has been recorded, so if :attr:`side_effect` raises an exception the call is "
"still recorded."
msgstr ""
"如果 :attr:`~Mock.side_effect` 被設定,那麼在呼叫被記錄後它才會被呼叫,所以如"
"果 :attr:`side_effect` 引發例外,呼叫仍然會被記錄。"

#: ../../library/unittest.mock.rst:1119
msgid ""
"The simplest way to make a mock raise an exception when called is to make :"
"attr:`~Mock.side_effect` an exception class or instance:"
msgstr ""
"呼叫 mock 時引發例外的最簡單方式是將 :attr:`~Mock.side_effect` 設定為例外類別"
"或實例:"

#: ../../library/unittest.mock.rst:1137
msgid ""
Expand All@@ -1042,6 +1051,9 @@ msgid ""
"with the same arguments as the mock. This allows you to vary the return "
"value of the call dynamically, based on the input:"
msgstr ""
"如果 :attr:`side_effect` 是一個函式,則該函式回傳的東西就是對 mock 的呼叫所回"
"傳的值。:attr:`side_effect` 函式會使用與 mock 相同的引數被呼叫。這讓你可以根"
"據輸入動態地變更呼叫的回傳值:"

#: ../../library/unittest.mock.rst:1153
msgid ""
Expand All@@ -1050,35 +1062,42 @@ msgid ""
"return :attr:`mock.return_value` from inside :attr:`side_effect`, or return :"
"data:`DEFAULT`:"
msgstr ""
"如果你希望 mock 仍然回傳預設的回傳值(一個新的 mock),或者是任何已設定的回傳"
"值,有兩種方法可以實現。從 :attr:`side_effect` 內部回傳 :attr:`mock."
"return_value`,或回傳 :data:`DEFAULT`:"

#: ../../library/unittest.mock.rst:1172
msgid ""
"To remove a :attr:`side_effect`, and return to the default behaviour, set "
"the :attr:`side_effect` to ``None``:"
msgstr ""
"要刪除 :attr:`side_effect`,並恢復預設行為,將 :attr:`side_effect` 設為 "
"``None``:"

#: ../../library/unittest.mock.rst:1186
msgid ""
"The :attr:`side_effect` can also be any iterable object. Repeated calls to "
"the mock will return values from the iterable (until the iterable is "
"exhausted and a :exc:`StopIteration` is raised):"
msgstr ""
":attr:`side_effect` 也可以是任何可疊代的物件。對 mock 的重複呼叫將從可疊代物"
"件中回傳值(直到疊代物件耗盡並引發 :exc:`StopIteration` 為止):"

#: ../../library/unittest.mock.rst:1202
msgid ""
"If any members of the iterable are exceptions they will be raised instead of "
"returned::"
msgstr ""
msgstr "如果可疊代物件中的任何成員是例外,則它們將被引發而不是被回傳: ::"

#: ../../library/unittest.mock.rst:1220
msgid "Deleting Attributes"
msgstr ""
msgstr "刪除屬性"

#: ../../library/unittest.mock.rst:1222
msgid ""
"Mock objects create attributes on demand. This allows them to pretend to be "
"objects of any type."
msgstr ""
msgstr "Mock 物件會在需要時建立屬性。這使得它們可以假裝成任何種類的物件。"

#: ../../library/unittest.mock.rst:1225
msgid ""
Expand All@@ -1087,16 +1106,21 @@ msgid ""
"by providing an object as a :attr:`spec` for a mock, but that isn't always "
"convenient."
msgstr ""
"你可能希望一個 mock 物件在 :func:`hasattr` 呼叫時回傳 ``False``,或者在屬性被"
"提取時引發 :exc:`AttributeError`。你可以通過將物件提供為 mock 的 :attr:"
"`spec` 來實現這一點,但這並不總是那麼好用。"

#: ../../library/unittest.mock.rst:1229
msgid ""
"You \"block\" attributes by deleting them. Once deleted, accessing an "
"attribute will raise an :exc:`AttributeError`."
msgstr ""
"你可以通過刪除屬性來「阻擋」它們。一旦刪除,再次存取該屬性將會引發 :exc:"
"`AttributeError`。"

#: ../../library/unittest.mock.rst:1246
msgid "Mock names and the name attribute"
msgstr ""
msgstr "Mock 名稱與名稱屬性"

#: ../../library/unittest.mock.rst:1248
msgid ""
Expand All@@ -1105,16 +1129,19 @@ msgid ""
"creation time. There are two alternatives. One option is to use :meth:`~Mock."
"configure_mock`::"
msgstr ""
"由於 \"name\" 是傳遞給 :class:`Mock` 建構函式的引數,如果你想讓你的 mock 物件擁"
"有 \"name\" 屬性,你不能在建立時直接傳遞它。有兩種替代方法。其中一個選擇是使"
"用 :meth:`~Mock.configure_mock`: ::"

#: ../../library/unittest.mock.rst:1258
msgid ""
"A simpler option is to simply set the \"name\" attribute after mock "
"creation::"
msgstr ""
msgstr "更簡單的方法是在 mock 建立後直接設定 \"name\" 屬性: ::"

#: ../../library/unittest.mock.rst:1265
msgid "Attaching Mocks as Attributes"
msgstr ""
msgstr "如同屬性一般附加 mock"

#: ../../library/unittest.mock.rst:1267
msgid ""
Expand All@@ -1126,19 +1153,28 @@ msgid ""
"calls to the children and allows you to make assertions about the order of "
"calls between mocks:"
msgstr ""
"當你將一個 mock 附加為另一個 mock 的屬性(或作為回傳值),它將成為該 mock 的"
"「子代 (child)」。對子代的呼叫將被記錄在上代的 :attr:`~Mock.method_calls` "
"和 :attr:`~Mock.mock_calls` 屬性中。這對於配置子代並將它們附加到上代,或將 "
"mock 附加到記錄所有對子代的呼叫的上代並允許你對 mock 間的呼叫順序進行斷言非常"
"有用:"

#: ../../library/unittest.mock.rst:1285
msgid ""
"The exception to this is if the mock has a name. This allows you to prevent "
"the \"parenting\" if for some reason you don't want it to happen."
msgstr ""
"如果 mock 有 name 引數,則上述規則會有例外。這使你可以防止「親屬關係 "
"(parenting)」的建立,假設因為某些原因你不希望這種狀況發生。"

#: ../../library/unittest.mock.rst:1296
msgid ""
"Mocks created for you by :func:`patch` are automatically given names. To "
"attach mocks that have names to a parent you use the :meth:`~Mock."
"attach_mock` method::"
msgstr ""
"由 :func:`patch` 為你建立的 mock 會自動被賦予名稱。若要將具有名稱的 mock 附加"
"到上代,你可以使用 :meth:`~Mock.attach_mock` 方法: ::"

#: ../../library/unittest.mock.rst:1314
msgid ""
Expand All@@ -1149,10 +1185,14 @@ msgid ""
"a new Mock object when it expects a magic method. If you need magic method "
"support see :ref:`magic methods <magic-methods>`."
msgstr ""
"唯一的例外是魔術方法和屬性(具有前後雙底線)。Mock 不會建立這些,而是會引發 :"
"exc:`AttributeError`。這是因為直譯器通常會隱式地要求這些方法,在期望得到一個"
"魔術方法卻獲得一個新的 Mock 物件時,會讓直譯器*非常*困惑。如果你需要魔術方法"
"的支援,請參閱\\ :ref:`魔術方法 <magic-methods>`。"

#: ../../library/unittest.mock.rst:1323
msgid "The patchers"
msgstr ""
msgstr "Patchers"

#: ../../library/unittest.mock.rst:1325
msgid ""
Expand All@@ -1161,16 +1201,19 @@ msgid ""
"you, even if exceptions are raised. All of these functions can also be used "
"in with statements or as class decorators."
msgstr ""
"patch 裝飾器僅用於在裝飾的函式範圍內對物件進行 patch。它們會自動為你處理 "
"patch 的中止,即使有異常被引發也是如此。所有這些函式也可以在 with 陳述式中使"
"用,或者作為類別裝飾器使用。"

#: ../../library/unittest.mock.rst:1332
msgid "patch"
msgstr ""
msgstr "patch"

#: ../../library/unittest.mock.rst:1336
msgid ""
"The key is to do the patching in the right namespace. See the section `where "
"to patch`_."
msgstr ""
msgstr "關鍵是要在正確的命名空間進行 patch。請參閱 `where to patch`_ 一節。"

#: ../../library/unittest.mock.rst:1340
msgid ""
Expand All@@ -1179,6 +1222,9 @@ msgid ""
"patched with a *new* object. When the function/with statement exits the "
"patch is undone."
msgstr ""
":func:`patch` 充當函式裝飾器、類別裝飾器或情境管理器。在函式或 with 陳述式的"
"內部,*目標*\\ 會被 patch 成一個\\ *新的*\\ 物件。當函式或 with 陳述式結束"
"時,patch 就會被解除。"

#: ../../library/unittest.mock.rst:1345
msgid ""
Expand All@@ -1189,6 +1235,10 @@ msgid ""
"If :func:`patch` is used as a context manager the created mock is returned "
"by the context manager."
msgstr ""
"如果 *new* 被省略,則如果被 patch 的物件是非同步函式,目標會被替換為 :class:"
"`AsyncMock`,反之則替換為 :class:`MagicMock`。如果 :func:`patch` 做為裝飾器使"
"用且省略了 *new*,則所建立的 mock 會作為額外的引數傳遞給被裝飾的函式。如果 :"
"func:`patch` 作為情境管理器使用,則所建立的 mock 將由情境管理器回傳。"

#: ../../library/unittest.mock.rst:1353
msgid ""
Expand All@@ -1198,25 +1248,36 @@ msgid ""
"calling :func:`patch` from. The target is imported when the decorated "
"function is executed, not at decoration time."
msgstr ""
"*target* 應該是以 ``'package.module.ClassName'`` 形式出現的字串。*target* 會"
"被引入並用 *new* 物件替換指定的物件,因此 *target* 必須可從你呼叫 :func:"
"`patch` 的環境中引入。target 在執行被裝飾的函式時被引入,而不是在裝飾器作用"
"時 (decoration time)。"

#: ../../library/unittest.mock.rst:1359
msgid ""
"The *spec* and *spec_set* keyword arguments are passed to the :class:"
"`MagicMock` if patch is creating one for you."
msgstr ""
"*spec* 和 *spec_set* 關鍵字引數會傳遞給 :class:`MagicMock`,如果 patch 正在為"
"你建立一個。"

#: ../../library/unittest.mock.rst:1362
msgid ""
"In addition you can pass ``spec=True`` or ``spec_set=True``, which causes "
"patch to pass in the object being mocked as the spec/spec_set object."
msgstr ""
"此外,你還可以傳遞 ``spec=True``或 ``spec_set=True``,這將導致 patch 將被 "
"mock 的物件作為 spec/spec_set 物件傳遞。"

#: ../../library/unittest.mock.rst:1365
msgid ""
"*new_callable* allows you to specify a different class, or callable object, "
"that will be called to create the *new* object. By default :class:"
"`AsyncMock` is used for async functions and :class:`MagicMock` for the rest."
msgstr ""
"*new_callable* 允許你指定一個不同的類別或可呼叫的物件,用於被呼叫並建立 "
"*new* 物件。預設情況下,對於非同步函式使用 :class:`AsyncMock`,而對於其他情況"
"則使用 :class:`MagicMock`。"

#: ../../library/unittest.mock.rst:1369
msgid ""
Expand All@@ -1229,12 +1290,20 @@ msgid ""
"return value (the 'instance') will have the same spec as the class. See the :"
"func:`create_autospec` function and :ref:`auto-speccing`."
msgstr ""
"*spec* 的一種更強大的形式是 *autospec*。如果你設定 ``autospec=True``,則該 "
"mock 將使用被替換物件的規格來建立。該 mock 的所有屬性也將具有被替換物件的對應"
"屬性的規格。被 mock 的方法和函式將檢查其引數,如果呼叫時引數與規格不符(被使"
"用錯誤的簽名 (signature) 呼叫),將引發 :exc:`TypeError`。對於替換類別的 "
"mock,它們的回傳值(即 'instance')將具有與類別相同的規格。請參閱 :func:"
"`create_autospec` 函式和 :ref:`auto-speccing`。"

#: ../../library/unittest.mock.rst:1379
msgid ""
"Instead of ``autospec=True`` you can pass ``autospec=some_object`` to use an "
"arbitrary object as the spec instead of the one being replaced."
msgstr ""
"你可以用 ``autospec=some_object`` 替代 ``autospec=True``,以使用任意物件作為"
"規格,而不是被替換的物件。"

#: ../../library/unittest.mock.rst:1382
msgid ""
Expand All@@ -1246,12 +1315,19 @@ msgid ""
"off by default because it can be dangerous. With it switched on you can "
"write passing tests against APIs that don't actually exist!"
msgstr ""
"預設情況下,:func:`patch` 將無法取代不存在的屬性。如果你傳入 "
"``create=True``,且屬性不存在,則當被 patch 的函式被呼叫時,patch 將為你建立"
"該屬性,並在被 patch 的函式結束後再次刪除它。這對於撰寫針對你的生產程式碼在執"
"行環境建立的屬性的測試時非常有用。此功能預設為關閉,因為這可能會相當危險。開"
"啟這個功能後,你可以對於實際上不存在的 API 撰寫會通過的測試!"

#: ../../library/unittest.mock.rst:1392
msgid ""
"If you are patching builtins in a module then you don't need to pass "
"``create=True``, it will be added by default."
msgstr ""
"如果你正在 patch 模組中的內建函式,那麼你不需要傳遞 ``create=True``,它預設會"
"被加入。"

#: ../../library/unittest.mock.rst:1396
msgid ""
Expand All@@ -1263,6 +1339,11 @@ msgid ""
"tests. You can specify an alternative prefix by setting ``patch."
"TEST_PREFIX``."
msgstr ""
"patch 可以做為 :class:`TestCase` 類別的裝飾器使用。它透過裝飾類別中的每個測試"
"方法來運作。當你的測試方法共享一組常見的 patch 時,這會減少繁冗的代碼。:func:"
"`patch` 通過搜尋以 ``patch.TEST_PREFIX`` 開頭的方法名來尋找測試。預設情況下會"
"是 ``'test'``,這與 :mod:`unittest` 尋找測試的方式相匹配。你可以通過設定 "
"``patch.TEST_PREFIX`` 來指定別的前綴。"

#: ../../library/unittest.mock.rst:1403
msgid ""
Expand All@@ -1271,45 +1352,61 @@ msgid ""
"\"as\" then the patched object will be bound to the name after the \"as\"; "
"very useful if :func:`patch` is creating a mock object for you."
msgstr ""
"透過 with 陳述式,Patch 可以做為情境管理器使用。 patch 適用於 with 陳述式之後"
"的縮排區塊。 如果你使用 \"as\",則被 patch 的物件將被綁定到 \"as\" 後面的名"
"稱; 如果 :func:`patch` 正在為你建立一個 mock 物件,這會非常有用。"

#: ../../library/unittest.mock.rst:1408
msgid ""
":func:`patch` takes arbitrary keyword arguments. These will be passed to :"
"class:`AsyncMock` if the patched object is asynchronous, to :class:"
"`MagicMock` otherwise or to *new_callable* if specified."
msgstr ""
":func:`patch` 接受任意的關鍵字引數。 如果被 patch 的物件是非同步的,這些將會"
"被傳遞給 :class:`AsyncMock`,如果是同步的則會傳遞給 :class:`MagicMock`,或如"
"果指定了 *new_callable*,則傳遞給它。"

#: ../../library/unittest.mock.rst:1412
msgid ""
"``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are "
"available for alternate use-cases."
msgstr ""
"``patch.dict(...)``、``patch.multiple(...)`` 和 ``patch.object(...)`` 可用於"
"其餘的使用情境。"

#: ../../library/unittest.mock.rst:1415
msgid ""
":func:`patch` as function decorator, creating the mock for you and passing "
"it into the decorated function::"
msgstr ""
":func:`patch` 作為函式裝飾器,為你建立 mock 並將其傳遞給被裝飾的函式: ::"

#: ../../library/unittest.mock.rst:1425
msgid ""
"Patching a class replaces the class with a :class:`MagicMock` *instance*. If "
"the class is instantiated in the code under test then it will be the :attr:"
"`~Mock.return_value` of the mock that will be used."
msgstr ""
"Patch 一個類別會以 :class:`MagicMock`\\ *實例*\\ 取代該類別。如果該類別在被"
"測試的程式碼中實例化,那麼它將是會被使用的 mock 的 :attr:`~Mock."
"return_value`。"

#: ../../library/unittest.mock.rst:1429
msgid ""
"If the class is instantiated multiple times you could use :attr:`~Mock."
"side_effect` to return a new mock each time. Alternatively you can set the "
"*return_value* to be anything you want."
msgstr ""
"如果該類別被實例化多次,你可以使用 :attr:`~Mock.side_effect` 來每次回傳一個新"
"的 mock。 或者你可以將 *return_value* 設定成你想要的任何值。"

#: ../../library/unittest.mock.rst:1433
msgid ""
"To configure return values on methods of *instances* on the patched class "
"you must do this on the :attr:`return_value`. For example::"
msgstr ""
"若要配置被 patch 的類別的\\ *實例*\\ 方法的回傳值,你必須在 :attr:`return_value` 上"
"進行配置。 例如: ::"

#: ../../library/unittest.mock.rst:1447
msgid ""
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp