@@ -7,7 +7,7 @@ msgstr ""
7
7
"Project-Id-Version : Python 3.12\n "
8
8
"Report-Msgid-Bugs-To : \n "
9
9
"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 "
11
11
"
Last-Translator :
Adrian Liaw <[email protected] >\n "
12
12
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
13
13
"tw)\n "
@@ -16,7 +16,7 @@ msgstr ""
16
16
"Content-Type : text/plain; charset=UTF-8\n "
17
17
"Content-Transfer-Encoding : 8bit\n "
18
18
"Plural-Forms : nplurals=1; plural=0;\n "
19
- "X-Generator : Poedit 3.4.1 \n "
19
+ "X-Generator : Poedit 3.4.2 \n "
20
20
21
21
#: ../../library/unittest.mock.rst:3
22
22
msgid ":mod:`unittest.mock` --- mock object library"
@@ -1015,25 +1015,34 @@ msgid ""
1015
1015
"explicitly or by calling the Mock) - but it is stored and the same one "
1016
1016
"returned each time."
1017
1017
msgstr ""
1018
+ "Mock 物件可被呼叫。呼叫將回傳設定為 :attr:`~Mock.return_value` 屬性的值。預設"
1019
+ "的回傳值是一個新的 Mock 物件;它會在第一次存取回傳值時(無論是顯式存取還是透"
1020
+ "過呼叫 Mock)被建立,但是這個回傳值會被儲存,之後每次都回傳同一個值。"
1018
1021
1019
1022
#: ../../library/unittest.mock.rst:1112
1020
1023
msgid ""
1021
1024
"Calls made to the object will be recorded in the attributes like :attr:"
1022
1025
"`~Mock.call_args` and :attr:`~Mock.call_args_list`."
1023
1026
msgstr ""
1027
+ "對物件的呼叫會被記錄在如 :attr:`~Mock.call_args` 和 :attr:`~Mock."
1028
+ "call_args_list` 等屬性中。"
1024
1029
1025
1030
#: ../../library/unittest.mock.rst:1115
1026
1031
msgid ""
1027
1032
"If :attr:`~Mock.side_effect` is set then it will be called after the call "
1028
1033
"has been recorded, so if :attr:`side_effect` raises an exception the call is "
1029
1034
"still recorded."
1030
1035
msgstr ""
1036
+ "如果 :attr:`~Mock.side_effect` 被設定,那麼在呼叫被記錄後它才會被呼叫,所以如"
1037
+ "果 :attr:`side_effect` 引發例外,呼叫仍然會被記錄。"
1031
1038
1032
1039
#: ../../library/unittest.mock.rst:1119
1033
1040
msgid ""
1034
1041
"The simplest way to make a mock raise an exception when called is to make :"
1035
1042
"attr:`~Mock.side_effect` an exception class or instance:"
1036
1043
msgstr ""
1044
+ "呼叫 mock 時引發例外的最簡單方式是將 :attr:`~Mock.side_effect` 設定為例外類別"
1045
+ "或實例:"
1037
1046
1038
1047
#: ../../library/unittest.mock.rst:1137
1039
1048
msgid ""
@@ -1042,6 +1051,9 @@ msgid ""
1042
1051
"with the same arguments as the mock. This allows you to vary the return "
1043
1052
"value of the call dynamically, based on the input:"
1044
1053
msgstr ""
1054
+ "如果 :attr:`side_effect` 是一個函式,則該函式回傳的東西就是對 mock 的呼叫所回"
1055
+ "傳的值。:attr:`side_effect` 函式會使用與 mock 相同的引數被呼叫。這讓你可以根"
1056
+ "據輸入動態地變更呼叫的回傳值:"
1045
1057
1046
1058
#: ../../library/unittest.mock.rst:1153
1047
1059
msgid ""
@@ -1050,35 +1062,42 @@ msgid ""
1050
1062
"return :attr:`mock.return_value` from inside :attr:`side_effect`, or return :"
1051
1063
"data:`DEFAULT`:"
1052
1064
msgstr ""
1065
+ "如果你希望 mock 仍然回傳預設的回傳值(一個新的 mock),或者是任何已設定的回傳"
1066
+ "值,有兩種方法可以實現。從 :attr:`side_effect` 內部回傳 :attr:`mock."
1067
+ "return_value`,或回傳 :data:`DEFAULT`:"
1053
1068
1054
1069
#: ../../library/unittest.mock.rst:1172
1055
1070
msgid ""
1056
1071
"To remove a :attr:`side_effect`, and return to the default behaviour, set "
1057
1072
"the :attr:`side_effect` to ``None``:"
1058
1073
msgstr ""
1074
+ "要刪除 :attr:`side_effect`,並恢復預設行為,將 :attr:`side_effect` 設為 "
1075
+ "``None``:"
1059
1076
1060
1077
#: ../../library/unittest.mock.rst:1186
1061
1078
msgid ""
1062
1079
"The :attr:`side_effect` can also be any iterable object. Repeated calls to "
1063
1080
"the mock will return values from the iterable (until the iterable is "
1064
1081
"exhausted and a :exc:`StopIteration` is raised):"
1065
1082
msgstr ""
1083
+ ":attr:`side_effect` 也可以是任何可疊代的物件。對 mock 的重複呼叫將從可疊代物"
1084
+ "件中回傳值(直到疊代物件耗盡並引發 :exc:`StopIteration` 為止):"
1066
1085
1067
1086
#: ../../library/unittest.mock.rst:1202
1068
1087
msgid ""
1069
1088
"If any members of the iterable are exceptions they will be raised instead of "
1070
1089
"returned::"
1071
- msgstr ""
1090
+ msgstr "如果可疊代物件中的任何成員是例外,則它們將被引發而不是被回傳: :: "
1072
1091
1073
1092
#: ../../library/unittest.mock.rst:1220
1074
1093
msgid "Deleting Attributes"
1075
- msgstr ""
1094
+ msgstr "刪除屬性 "
1076
1095
1077
1096
#: ../../library/unittest.mock.rst:1222
1078
1097
msgid ""
1079
1098
"Mock objects create attributes on demand. This allows them to pretend to be "
1080
1099
"objects of any type."
1081
- msgstr ""
1100
+ msgstr "Mock 物件會在需要時建立屬性。這使得它們可以假裝成任何種類的物件。 "
1082
1101
1083
1102
#: ../../library/unittest.mock.rst:1225
1084
1103
msgid ""
@@ -1087,16 +1106,21 @@ msgid ""
1087
1106
"by providing an object as a :attr:`spec` for a mock, but that isn't always "
1088
1107
"convenient."
1089
1108
msgstr ""
1109
+ "你可能希望一個 mock 物件在 :func:`hasattr` 呼叫時回傳 ``False``,或者在屬性被"
1110
+ "提取時引發 :exc:`AttributeError`。你可以通過將物件提供為 mock 的 :attr:"
1111
+ "`spec` 來實現這一點,但這並不總是那麼好用。"
1090
1112
1091
1113
#: ../../library/unittest.mock.rst:1229
1092
1114
msgid ""
1093
1115
"You \" block\" attributes by deleting them. Once deleted, accessing an "
1094
1116
"attribute will raise an :exc:`AttributeError`."
1095
1117
msgstr ""
1118
+ "你可以通過刪除屬性來「阻擋」它們。一旦刪除,再次存取該屬性將會引發 :exc:"
1119
+ "`AttributeError`。"
1096
1120
1097
1121
#: ../../library/unittest.mock.rst:1246
1098
1122
msgid "Mock names and the name attribute"
1099
- msgstr ""
1123
+ msgstr "Mock 名稱與名稱屬性 "
1100
1124
1101
1125
#: ../../library/unittest.mock.rst:1248
1102
1126
msgid ""
@@ -1105,16 +1129,19 @@ msgid ""
1105
1129
"creation time. There are two alternatives. One option is to use :meth:`~Mock."
1106
1130
"configure_mock`::"
1107
1131
msgstr ""
1132
+ "由於 \" name\" 是傳遞給 :class:`Mock` 建構函式的引數,如果你想讓你的 mock 物件擁"
1133
+ "有 \" name\" 屬性,你不能在建立時直接傳遞它。有兩種替代方法。其中一個選擇是使"
1134
+ "用 :meth:`~Mock.configure_mock`: ::"
1108
1135
1109
1136
#: ../../library/unittest.mock.rst:1258
1110
1137
msgid ""
1111
1138
"A simpler option is to simply set the \" name\" attribute after mock "
1112
1139
"creation::"
1113
- msgstr ""
1140
+ msgstr "更簡單的方法是在 mock 建立後直接設定 \" name \" 屬性: :: "
1114
1141
1115
1142
#: ../../library/unittest.mock.rst:1265
1116
1143
msgid "Attaching Mocks as Attributes"
1117
- msgstr ""
1144
+ msgstr "如同屬性一般附加 mock "
1118
1145
1119
1146
#: ../../library/unittest.mock.rst:1267
1120
1147
msgid ""
@@ -1126,19 +1153,28 @@ msgid ""
1126
1153
"calls to the children and allows you to make assertions about the order of "
1127
1154
"calls between mocks:"
1128
1155
msgstr ""
1156
+ "當你將一個 mock 附加為另一個 mock 的屬性(或作為回傳值),它將成為該 mock 的"
1157
+ "「子代 (child)」。對子代的呼叫將被記錄在上代的 :attr:`~Mock.method_calls` "
1158
+ "和 :attr:`~Mock.mock_calls` 屬性中。這對於配置子代並將它們附加到上代,或將 "
1159
+ "mock 附加到記錄所有對子代的呼叫的上代並允許你對 mock 間的呼叫順序進行斷言非常"
1160
+ "有用:"
1129
1161
1130
1162
#: ../../library/unittest.mock.rst:1285
1131
1163
msgid ""
1132
1164
"The exception to this is if the mock has a name. This allows you to prevent "
1133
1165
"the \" parenting\" if for some reason you don't want it to happen."
1134
1166
msgstr ""
1167
+ "如果 mock 有 name 引數,則上述規則會有例外。這使你可以防止「親屬關係 "
1168
+ "(parenting)」的建立,假設因為某些原因你不希望這種狀況發生。"
1135
1169
1136
1170
#: ../../library/unittest.mock.rst:1296
1137
1171
msgid ""
1138
1172
"Mocks created for you by :func:`patch` are automatically given names. To "
1139
1173
"attach mocks that have names to a parent you use the :meth:`~Mock."
1140
1174
"attach_mock` method::"
1141
1175
msgstr ""
1176
+ "由 :func:`patch` 為你建立的 mock 會自動被賦予名稱。若要將具有名稱的 mock 附加"
1177
+ "到上代,你可以使用 :meth:`~Mock.attach_mock` 方法: ::"
1142
1178
1143
1179
#: ../../library/unittest.mock.rst:1314
1144
1180
msgid ""
@@ -1149,10 +1185,14 @@ msgid ""
1149
1185
"a new Mock object when it expects a magic method. If you need magic method "
1150
1186
"support see :ref:`magic methods <magic-methods>`."
1151
1187
msgstr ""
1188
+ "唯一的例外是魔術方法和屬性(具有前後雙底線)。Mock 不會建立這些,而是會引發 :"
1189
+ "exc:`AttributeError`。這是因為直譯器通常會隱式地要求這些方法,在期望得到一個"
1190
+ "魔術方法卻獲得一個新的 Mock 物件時,會讓直譯器*非常*困惑。如果你需要魔術方法"
1191
+ "的支援,請參閱\\ :ref:`魔術方法 <magic-methods>`。"
1152
1192
1153
1193
#: ../../library/unittest.mock.rst:1323
1154
1194
msgid "The patchers"
1155
- msgstr ""
1195
+ msgstr "Patchers "
1156
1196
1157
1197
#: ../../library/unittest.mock.rst:1325
1158
1198
msgid ""
@@ -1161,16 +1201,19 @@ msgid ""
1161
1201
"you, even if exceptions are raised. All of these functions can also be used "
1162
1202
"in with statements or as class decorators."
1163
1203
msgstr ""
1204
+ "patch 裝飾器僅用於在裝飾的函式範圍內對物件進行 patch。它們會自動為你處理 "
1205
+ "patch 的中止,即使有異常被引發也是如此。所有這些函式也可以在 with 陳述式中使"
1206
+ "用,或者作為類別裝飾器使用。"
1164
1207
1165
1208
#: ../../library/unittest.mock.rst:1332
1166
1209
msgid "patch"
1167
- msgstr ""
1210
+ msgstr "patch "
1168
1211
1169
1212
#: ../../library/unittest.mock.rst:1336
1170
1213
msgid ""
1171
1214
"The key is to do the patching in the right namespace. See the section `where "
1172
1215
"to patch`_."
1173
- msgstr ""
1216
+ msgstr "關鍵是要在正確的命名空間進行 patch。請參閱 `where to patch`_ 一節。 "
1174
1217
1175
1218
#: ../../library/unittest.mock.rst:1340
1176
1219
msgid ""
@@ -1179,6 +1222,9 @@ msgid ""
1179
1222
"patched with a *new* object. When the function/with statement exits the "
1180
1223
"patch is undone."
1181
1224
msgstr ""
1225
+ ":func:`patch` 充當函式裝飾器、類別裝飾器或情境管理器。在函式或 with 陳述式的"
1226
+ "內部,*目標*\\ 會被 patch 成一個\\ *新的*\\ 物件。當函式或 with 陳述式結束"
1227
+ "時,patch 就會被解除。"
1182
1228
1183
1229
#: ../../library/unittest.mock.rst:1345
1184
1230
msgid ""
@@ -1189,6 +1235,10 @@ msgid ""
1189
1235
"If :func:`patch` is used as a context manager the created mock is returned "
1190
1236
"by the context manager."
1191
1237
msgstr ""
1238
+ "如果 *new* 被省略,則如果被 patch 的物件是非同步函式,目標會被替換為 :class:"
1239
+ "`AsyncMock`,反之則替換為 :class:`MagicMock`。如果 :func:`patch` 做為裝飾器使"
1240
+ "用且省略了 *new*,則所建立的 mock 會作為額外的引數傳遞給被裝飾的函式。如果 :"
1241
+ "func:`patch` 作為情境管理器使用,則所建立的 mock 將由情境管理器回傳。"
1192
1242
1193
1243
#: ../../library/unittest.mock.rst:1353
1194
1244
msgid ""
@@ -1198,25 +1248,36 @@ msgid ""
1198
1248
"calling :func:`patch` from. The target is imported when the decorated "
1199
1249
"function is executed, not at decoration time."
1200
1250
msgstr ""
1251
+ "*target* 應該是以 ``'package.module.ClassName'`` 形式出現的字串。*target* 會"
1252
+ "被引入並用 *new* 物件替換指定的物件,因此 *target* 必須可從你呼叫 :func:"
1253
+ "`patch` 的環境中引入。target 在執行被裝飾的函式時被引入,而不是在裝飾器作用"
1254
+ "時 (decoration time)。"
1201
1255
1202
1256
#: ../../library/unittest.mock.rst:1359
1203
1257
msgid ""
1204
1258
"The *spec* and *spec_set* keyword arguments are passed to the :class:"
1205
1259
"`MagicMock` if patch is creating one for you."
1206
1260
msgstr ""
1261
+ "*spec* 和 *spec_set* 關鍵字引數會傳遞給 :class:`MagicMock`,如果 patch 正在為"
1262
+ "你建立一個。"
1207
1263
1208
1264
#: ../../library/unittest.mock.rst:1362
1209
1265
msgid ""
1210
1266
"In addition you can pass ``spec=True`` or ``spec_set=True``, which causes "
1211
1267
"patch to pass in the object being mocked as the spec/spec_set object."
1212
1268
msgstr ""
1269
+ "此外,你還可以傳遞 ``spec=True``或 ``spec_set=True``,這將導致 patch 將被 "
1270
+ "mock 的物件作為 spec/spec_set 物件傳遞。"
1213
1271
1214
1272
#: ../../library/unittest.mock.rst:1365
1215
1273
msgid ""
1216
1274
"*new_callable* allows you to specify a different class, or callable object, "
1217
1275
"that will be called to create the *new* object. By default :class:"
1218
1276
"`AsyncMock` is used for async functions and :class:`MagicMock` for the rest."
1219
1277
msgstr ""
1278
+ "*new_callable* 允許你指定一個不同的類別或可呼叫的物件,用於被呼叫並建立 "
1279
+ "*new* 物件。預設情況下,對於非同步函式使用 :class:`AsyncMock`,而對於其他情況"
1280
+ "則使用 :class:`MagicMock`。"
1220
1281
1221
1282
#: ../../library/unittest.mock.rst:1369
1222
1283
msgid ""
@@ -1229,12 +1290,20 @@ msgid ""
1229
1290
"return value (the 'instance') will have the same spec as the class. See the :"
1230
1291
"func:`create_autospec` function and :ref:`auto-speccing`."
1231
1292
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`。"
1232
1299
1233
1300
#: ../../library/unittest.mock.rst:1379
1234
1301
msgid ""
1235
1302
"Instead of ``autospec=True`` you can pass ``autospec=some_object`` to use an "
1236
1303
"arbitrary object as the spec instead of the one being replaced."
1237
1304
msgstr ""
1305
+ "你可以用 ``autospec=some_object`` 替代 ``autospec=True``,以使用任意物件作為"
1306
+ "規格,而不是被替換的物件。"
1238
1307
1239
1308
#: ../../library/unittest.mock.rst:1382
1240
1309
msgid ""
@@ -1246,12 +1315,19 @@ msgid ""
1246
1315
"off by default because it can be dangerous. With it switched on you can "
1247
1316
"write passing tests against APIs that don't actually exist!"
1248
1317
msgstr ""
1318
+ "預設情況下,:func:`patch` 將無法取代不存在的屬性。如果你傳入 "
1319
+ "``create=True``,且屬性不存在,則當被 patch 的函式被呼叫時,patch 將為你建立"
1320
+ "該屬性,並在被 patch 的函式結束後再次刪除它。這對於撰寫針對你的生產程式碼在執"
1321
+ "行環境建立的屬性的測試時非常有用。此功能預設為關閉,因為這可能會相當危險。開"
1322
+ "啟這個功能後,你可以對於實際上不存在的 API 撰寫會通過的測試!"
1249
1323
1250
1324
#: ../../library/unittest.mock.rst:1392
1251
1325
msgid ""
1252
1326
"If you are patching builtins in a module then you don't need to pass "
1253
1327
"``create=True``, it will be added by default."
1254
1328
msgstr ""
1329
+ "如果你正在 patch 模組中的內建函式,那麼你不需要傳遞 ``create=True``,它預設會"
1330
+ "被加入。"
1255
1331
1256
1332
#: ../../library/unittest.mock.rst:1396
1257
1333
msgid ""
@@ -1263,6 +1339,11 @@ msgid ""
1263
1339
"tests. You can specify an alternative prefix by setting ``patch."
1264
1340
"TEST_PREFIX``."
1265
1341
msgstr ""
1342
+ "patch 可以做為 :class:`TestCase` 類別的裝飾器使用。它透過裝飾類別中的每個測試"
1343
+ "方法來運作。當你的測試方法共享一組常見的 patch 時,這會減少繁冗的代碼。:func:"
1344
+ "`patch` 通過搜尋以 ``patch.TEST_PREFIX`` 開頭的方法名來尋找測試。預設情況下會"
1345
+ "是 ``'test'``,這與 :mod:`unittest` 尋找測試的方式相匹配。你可以通過設定 "
1346
+ "``patch.TEST_PREFIX`` 來指定別的前綴。"
1266
1347
1267
1348
#: ../../library/unittest.mock.rst:1403
1268
1349
msgid ""
@@ -1271,45 +1352,61 @@ msgid ""
1271
1352
"\" as\" then the patched object will be bound to the name after the \" as\" ; "
1272
1353
"very useful if :func:`patch` is creating a mock object for you."
1273
1354
msgstr ""
1355
+ "透過 with 陳述式,Patch 可以做為情境管理器使用。 patch 適用於 with 陳述式之後"
1356
+ "的縮排區塊。 如果你使用 \" as\" ,則被 patch 的物件將被綁定到 \" as\" 後面的名"
1357
+ "稱; 如果 :func:`patch` 正在為你建立一個 mock 物件,這會非常有用。"
1274
1358
1275
1359
#: ../../library/unittest.mock.rst:1408
1276
1360
msgid ""
1277
1361
":func:`patch` takes arbitrary keyword arguments. These will be passed to :"
1278
1362
"class:`AsyncMock` if the patched object is asynchronous, to :class:"
1279
1363
"`MagicMock` otherwise or to *new_callable* if specified."
1280
1364
msgstr ""
1365
+ ":func:`patch` 接受任意的關鍵字引數。 如果被 patch 的物件是非同步的,這些將會"
1366
+ "被傳遞給 :class:`AsyncMock`,如果是同步的則會傳遞給 :class:`MagicMock`,或如"
1367
+ "果指定了 *new_callable*,則傳遞給它。"
1281
1368
1282
1369
#: ../../library/unittest.mock.rst:1412
1283
1370
msgid ""
1284
1371
"``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are "
1285
1372
"available for alternate use-cases."
1286
1373
msgstr ""
1374
+ "``patch.dict(...)``、``patch.multiple(...)`` 和 ``patch.object(...)`` 可用於"
1375
+ "其餘的使用情境。"
1287
1376
1288
1377
#: ../../library/unittest.mock.rst:1415
1289
1378
msgid ""
1290
1379
":func:`patch` as function decorator, creating the mock for you and passing "
1291
1380
"it into the decorated function::"
1292
1381
msgstr ""
1382
+ ":func:`patch` 作為函式裝飾器,為你建立 mock 並將其傳遞給被裝飾的函式: ::"
1293
1383
1294
1384
#: ../../library/unittest.mock.rst:1425
1295
1385
msgid ""
1296
1386
"Patching a class replaces the class with a :class:`MagicMock` *instance*. If "
1297
1387
"the class is instantiated in the code under test then it will be the :attr:"
1298
1388
"`~Mock.return_value` of the mock that will be used."
1299
1389
msgstr ""
1390
+ "Patch 一個類別會以 :class:`MagicMock`\\ *實例*\\ 取代該類別。如果該類別在被"
1391
+ "測試的程式碼中實例化,那麼它將是會被使用的 mock 的 :attr:`~Mock."
1392
+ "return_value`。"
1300
1393
1301
1394
#: ../../library/unittest.mock.rst:1429
1302
1395
msgid ""
1303
1396
"If the class is instantiated multiple times you could use :attr:`~Mock."
1304
1397
"side_effect` to return a new mock each time. Alternatively you can set the "
1305
1398
"*return_value* to be anything you want."
1306
1399
msgstr ""
1400
+ "如果該類別被實例化多次,你可以使用 :attr:`~Mock.side_effect` 來每次回傳一個新"
1401
+ "的 mock。 或者你可以將 *return_value* 設定成你想要的任何值。"
1307
1402
1308
1403
#: ../../library/unittest.mock.rst:1433
1309
1404
msgid ""
1310
1405
"To configure return values on methods of *instances* on the patched class "
1311
1406
"you must do this on the :attr:`return_value`. For example::"
1312
1407
msgstr ""
1408
+ "若要配置被 patch 的類別的\\ *實例*\\ 方法的回傳值,你必須在 :attr:`return_value` 上"
1409
+ "進行配置。 例如: ::"
1313
1410
1314
1411
#: ../../library/unittest.mock.rst:1447
1315
1412
msgid ""
0 commit comments