Skip to content

Commit da79861

Browse files
ken71301PayonAbyss
andauthored
feat: translate rst:1112 to rst:1433 (#793)
* feat: rst:1112 to rst:1433 * fix: fix some words * fix: as comment --------- Co-authored-by: 鄭宇辰 <[email protected]>
1 parent cbb7556 commit da79861

File tree

1 file changed

+108
-11
lines changed

1 file changed

+108
-11
lines changed

library/unittest.mock.po

Lines changed: 108 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgstr ""
77
"Project-Id-Version: Python 3.12\n"
88
"Report-Msgid-Bugs-To: \n"
99
"POT-Creation-Date: 2023-12-16 00:03+0000\n"
10-
"PO-Revision-Date: 2023-12-04 21:31+0800\n"
10+
"PO-Revision-Date: 2024-01-12 08:51+0800\n"
1111
"Last-Translator: Adrian Liaw <[email protected]>\n"
1212
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1313
"tw)\n"
@@ -16,7 +16,7 @@ msgstr ""
1616
"Content-Type: text/plain; charset=UTF-8\n"
1717
"Content-Transfer-Encoding: 8bit\n"
1818
"Plural-Forms: nplurals=1; plural=0;\n"
19-
"X-Generator: Poedit 3.4.1\n"
19+
"X-Generator: Poedit 3.4.2\n"
2020

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

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

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

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

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

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

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

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

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

10731092
#: ../../library/unittest.mock.rst:1220
10741093
msgid "Deleting Attributes"
1075-
msgstr ""
1094+
msgstr "刪除屬性"
10761095

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

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

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

10971121
#: ../../library/unittest.mock.rst:1246
10981122
msgid "Mock names and the name attribute"
1099-
msgstr ""
1123+
msgstr "Mock 名稱與名稱屬性"
11001124

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

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

11151142
#: ../../library/unittest.mock.rst:1265
11161143
msgid "Attaching Mocks as Attributes"
1117-
msgstr ""
1144+
msgstr "如同屬性一般附加 mock"
11181145

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

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

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

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

11531193
#: ../../library/unittest.mock.rst:1323
11541194
msgid "The patchers"
1155-
msgstr ""
1195+
msgstr "Patchers"
11561196

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

11651208
#: ../../library/unittest.mock.rst:1332
11661209
msgid "patch"
1167-
msgstr ""
1210+
msgstr "patch"
11681211

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

13141411
#: ../../library/unittest.mock.rst:1447
13151412
msgid ""

0 commit comments

Comments
 (0)