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

Appearance settings

Commit b6a472d

Browse filesBrowse files
committed
feat: to rst:1342
1 parent 679d025 commit b6a472d
Copy full SHA for b6a472d

File tree

Expand file treeCollapse file tree

1 file changed

+48
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+48
-9
lines changed

‎library/unittest.mock-examples.po

Copy file name to clipboardExpand all lines: library/unittest.mock-examples.po
+48-9Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgstr ""
88
"Project-Id-Version: Python 3.12\n"
99
"Report-Msgid-Bugs-To: \n"
1010
"POT-Creation-Date: 2023-09-09 00:03+0000\n"
11-
"PO-Revision-Date: 2024-04-02 21:55+0800\n"
11+
"PO-Revision-Date: 2024-04-09 00:26+0800\n"
1212
"Last-Translator: Liang-Bo Wang <me@liang2.tw>\n"
1313
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1414
"tw)\n"
@@ -1191,25 +1191,27 @@ msgstr ""
11911191

11921192
#: ../../library/unittest.mock-examples.rst:1154
11931193
msgid "Here's an example that mocks out the 'fooble' module."
1194-
msgstr ""
1194+
msgstr "下面是一個 mock out 'fooble' 模組的例子。"
11951195

11961196
#: ../../library/unittest.mock-examples.rst:1166
11971197
msgid ""
11981198
"As you can see the ``import fooble`` succeeds, but on exit there is no "
11991199
"'fooble' left in :data:`sys.modules`."
12001200
msgstr ""
1201+
"如你所建,``import fooble`` 成功了,但在離開之後,:data:`sys.modules` 中就沒"
1202+
"有 'fooble' 了。"
12011203

12021204
#: ../../library/unittest.mock-examples.rst:1169
12031205
msgid "This also works for the ``from module import name`` form:"
1204-
msgstr ""
1206+
msgstr "這也適用於 ``from module import name`` 形式:"
12051207

12061208
#: ../../library/unittest.mock-examples.rst:1179
12071209
msgid "With slightly more work you can also mock package imports:"
1208-
msgstr ""
1210+
msgstr "透過稍微多一點的處理,你也可以 mock 套件的引入:"
12091211

12101212
#: ../../library/unittest.mock-examples.rst:1192
12111213
msgid "Tracking order of calls and less verbose call assertions"
1212-
msgstr ""
1214+
msgstr "追蹤呼叫順序與更簡潔的呼叫斷言"
12131215

12141216
#: ../../library/unittest.mock-examples.rst:1194
12151217
msgid ""
@@ -1218,6 +1220,9 @@ msgid ""
12181220
"doesn't allow you to track the order of calls between separate mock objects, "
12191221
"however we can use :attr:`~Mock.mock_calls` to achieve the same effect."
12201222
msgstr ""
1223+
":class:`Mock` 類別可以讓你透過 :attr:`~Mock.method_calls` 屬性追蹤 mock 物件"
1224+
"上方法呼叫的\\ *順序*。這不會讓你可以追蹤不同的 mock 物件之間的呼叫順序,然而"
1225+
"我們可以使用 :attr:`~Mock.mock_calls` 來達到相同的效果。"
12211226

12221227
#: ../../library/unittest.mock-examples.rst:1199
12231228
msgid ""
@@ -1226,19 +1231,27 @@ msgid ""
12261231
"separate mocks from a parent one. Calls to those child mock will then all be "
12271232
"recorded, in order, in the ``mock_calls`` of the parent:"
12281233
msgstr ""
1234+
"因為 mock 會在 ``mock_calls`` 中追蹤對子 mock 的呼叫,且存取 mock 的任意屬性"
1235+
"會建立一個子 mock,所以我們可以從父 mock 建立不同的 mock。之後對這些子 mock "
1236+
"的呼叫將依序全部記錄在父 mock 的 ``mock_calls`` 中:"
12291237

12301238
#: ../../library/unittest.mock-examples.rst:1216
12311239
msgid ""
12321240
"We can then assert about the calls, including the order, by comparing with "
12331241
"the ``mock_calls`` attribute on the manager mock:"
12341242
msgstr ""
1243+
"之後我們可以透過與管理器 (manager) mock 上的 ``mock_calls`` 屬性進行比較來斷"
1244+
"言呼叫的順序:"
12351245

12361246
#: ../../library/unittest.mock-examples.rst:1223
12371247
msgid ""
12381248
"If ``patch`` is creating, and putting in place, your mocks then you can "
12391249
"attach them to a manager mock using the :meth:`~Mock.attach_mock` method. "
12401250
"After attaching calls will be recorded in ``mock_calls`` of the manager. ::"
12411251
msgstr ""
1252+
"如果 ``patch`` 正在被建立並放置為你的 mock,那麼你可以使用 :meth:`~Mock."
1253+
"attach_mock` 方法將它們附加到管理器 mock。附加之後,呼叫將被記錄在管理器的 "
1254+
"``mock_calls``中。: ::"
12421255

12431256
#: ../../library/unittest.mock-examples.rst:1242
12441257
msgid ""
@@ -1248,12 +1261,17 @@ msgid ""
12481261
"data:`call` object). If that sequence of calls are in :attr:`~Mock."
12491262
"mock_calls` then the assert succeeds."
12501263
msgstr ""
1264+
"如果進行了多次呼叫,但你只對其中特定呼叫的序列感興趣,則可以是使用 :meth:"
1265+
"`~Mock.assert_has_calls` 方法。這需要一個呼叫串列(使用 :data:`call` 物件建"
1266+
"構)。如果該呼叫序列位於 :attr:`~Mock.mock_calls` 中,則斷言成功。"
12511267

12521268
#: ../../library/unittest.mock-examples.rst:1256
12531269
msgid ""
12541270
"Even though the chained call ``m.one().two().three()`` aren't the only calls "
12551271
"that have been made to the mock, the assert still succeeds."
12561272
msgstr ""
1273+
"儘管鍊接呼叫 ``m.one().two().three()`` 並不是對 mock 進行的唯一呼叫,斷言仍會"
1274+
"成功。"
12571275

12581276
#: ../../library/unittest.mock-examples.rst:1259
12591277
msgid ""
@@ -1262,16 +1280,21 @@ msgid ""
12621280
"about the order. In this case you can pass ``any_order=True`` to "
12631281
"``assert_has_calls``:"
12641282
msgstr ""
1283+
"有時,可能會對一個 mock 進行多次呼叫,而你只對斷言其中\\ *某些*\\ 感興趣。你"
1284+
"甚至可能不關心順序。在這種情況下,你可以將 ``any_order=True`` 傳遞給 "
1285+
"``assert_has_calls``:"
12651286

12661287
#: ../../library/unittest.mock-examples.rst:1271
12671288
msgid "More complex argument matching"
1268-
msgstr ""
1289+
msgstr "更複雜的引數匹配"
12691290

12701291
#: ../../library/unittest.mock-examples.rst:1273
12711292
msgid ""
12721293
"Using the same basic concept as :data:`ANY` we can implement matchers to do "
12731294
"more complex assertions on objects used as arguments to mocks."
12741295
msgstr ""
1296+
"使用與 :data:`ANY` 相同的基本概念,我們可以實作匹配器 (matcher),對用作對 "
1297+
"mock 的引數的物件進行更複雜的斷言。"
12751298

12761299
#: ../../library/unittest.mock-examples.rst:1276
12771300
msgid ""
@@ -1282,27 +1305,32 @@ msgid ""
12821305
"attributes of this object then we can create a matcher that will check these "
12831306
"attributes for us."
12841307
msgstr ""
1308+
"假設我們希望將某些物件傳遞給一個 mock,預設情況下,該 mock 會根據物件識別性"
1309+
"(使用者定義類別的 Python 預設值)進行相等比較。要使用 :meth:`~Mock."
1310+
"assert_called_with`,我們需要傳入完全相同的物件。如果我們只對該物件的某些屬性"
1311+
"感興趣,那麼我們可以建立一個匹配器來為我們檢查這些屬性。"
12851312

12861313
#: ../../library/unittest.mock-examples.rst:1283
12871314
msgid ""
12881315
"You can see in this example how a 'standard' call to ``assert_called_with`` "
12891316
"isn't sufficient:"
12901317
msgstr ""
1318+
"你可以在這個範例中看到對 ``assert_called_with`` 的一個「標準」呼叫是不夠的:"
12911319

12921320
#: ../../library/unittest.mock-examples.rst:1298
12931321
msgid ""
12941322
"A comparison function for our ``Foo`` class might look something like this:"
1295-
msgstr ""
1323+
msgstr "對我們的 ``Foo`` 類別的比較函式看起來可能會像這樣:"
12961324

12971325
#: ../../library/unittest.mock-examples.rst:1310
12981326
msgid ""
12991327
"And a matcher object that can use comparison functions like this for its "
13001328
"equality operation would look something like this:"
1301-
msgstr ""
1329+
msgstr "可以使用這樣的比較函式進行自身相等性運算的匹配器物件會長得像這樣:"
13021330

13031331
#: ../../library/unittest.mock-examples.rst:1321
13041332
msgid "Putting all this together:"
1305-
msgstr ""
1333+
msgstr "把這些都放在一起:"
13061334

13071335
#: ../../library/unittest.mock-examples.rst:1326
13081336
msgid ""
@@ -1313,12 +1341,18 @@ msgid ""
13131341
"``assert_called_with`` passes, and if they don't an :exc:`AssertionError` is "
13141342
"raised:"
13151343
msgstr ""
1344+
"``Matcher`` 是用我們想要比較的 ``Foo`` 物件和比較函式實例化的。在 "
1345+
"``assert_called_with`` 中,``Matcher`` 相等方法將被呼叫,它將呼叫 mock 的物件"
1346+
"與我們建立匹配器的物件進行比較。如果它們匹配,則 ``assert_called_with`` 會通"
1347+
"過,如果它們不匹配,則會引發 :exc:`AssertionError`:"
13161348

13171349
#: ../../library/unittest.mock-examples.rst:1339
13181350
msgid ""
13191351
"With a bit of tweaking you could have the comparison function raise the :exc:"
13201352
"`AssertionError` directly and provide a more useful failure message."
13211353
msgstr ""
1354+
"透過一些調整,你可以讓比較函式直接引發 :exc:`AssertionError` 並提供更有用的失"
1355+
"敗訊息。"
13221356

13231357
#: ../../library/unittest.mock-examples.rst:1342
13241358
msgid ""
@@ -1328,3 +1362,8 @@ msgid ""
13281362
"integration.match_equality <https://pyhamcrest.readthedocs.io/en/release-1.8/"
13291363
"integration/#module-hamcrest.library.integration.match_equality>`_)."
13301364
msgstr ""
1365+
"從版本 1.5 開始,Python 測試函式庫 `PyHamcrest <https://pyhamcrest."
1366+
"readthedocs.io/>`_ 提供了類似的功能,在這裡可能有用,以其相等匹配器的形式 "
1367+
"(\\ `hamcrest.library.integration.match_equality <https://pyhamcrest."
1368+
"readthedocs.io/en/release-1.8/integration/#module-hamcrest.library."
1369+
"integration.match_equality>`_\\ )。"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.