8000 feat: to rst:1148 · python/python-docs-zh-tw@679d025 · GitHub
[go: up one dir, main page]

Skip to content

Commit 679d025

Browse files
committed
feat: to rst:1148
1 parent f47ed7f commit 679d025

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

library/unittest.mock-examples.po

Lines changed: 17 additions & 2 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-03-28 22:08+0800\n"
11+
"PO-Revision-Date: 2024-04-02 21:55+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"
@@ -1136,14 +1136,16 @@ msgstr ""
11361136

11371137
#: ../../library/unittest.mock-examples.rst:1128
11381138
msgid "Mocking imports with patch.dict"
1139-
msgstr ""
1139+
msgstr "使用 patch.dict 來 mock import"
11401140

11411141
#: ../../library/unittest.mock-examples.rst:1130
11421142
msgid ""
11431143
"One situation where mocking can be hard is where you have a local import "
11441144
"inside a function. These are harder to mock because they aren't using an "
11451145
"object from the module namespace that we can patch out."
11461146
msgstr ""
1147+
"可能讓 mock 會很困難的一種情況是在函式內部進行區域 import。這些狀況會更難進"
1148+
"行 mock,因為它們沒有使用我們可以 patch out 的模組命名空間中的物件。"
11471149

11481150
#: ../../library/unittest.mock-examples.rst:1134
11491151
msgid ""
@@ -1154,6 +1156,11 @@ msgid ""
11541156
"an unconditional local import (store the module as a class or module "
11551157
"attribute and only do the import on first use)."
11561158
msgstr ""
1159+
"一般來說,我們應該避免區域 import 的發生。有時這樣做是為了防止循環相依 "
1160+
"(circular dependencies),為此\\ *通常*\\ 有更好的方式來解決問題(例如重構程式"
1161+
"碼)或透過延遲 import 來防止「前期成本 (up front costs)」。這也可以透過比無條"
1162+
"件的區域 import 更好的方式來解決(例如將模組儲存為類別或模組屬性,並且僅在第"
1163+
"一次使用時進行 import)。"
11571164

11581165
#: ../../library/unittest.mock-examples.rst:1141
11591166
msgid ""
@@ -1164,6 +1171,10 @@ msgid ""
11641171
"in ``sys.modules``, so usually when you import something you get a module "
11651172
"back. This need not be the case however."
11661173
msgstr ""
1174+
"除此之外,還有一種方法可以使用 ``mock`` 來影響 import 的結果。Import 會從 :"
1175+
"data:`sys.modules` 字典中取得一個\\ *物件*。請注意,它會取得一個\\ *物件*,而"
1176+
"該物件不一定是一個模組。初次 import 模組會導致模組物件被放入 ``sys.modules`` "
1177+
"中,因此通常當你 import 某些東西時,你會得到一個模組。但情況並非總是如此。"
11671178

11681179
#: ../../library/unittest.mock-examples.rst:1148
11691180
msgid ""
@@ -1173,6 +1184,10 @@ msgid ""
11731184
"the with statement body is complete or ``patcher.stop()`` is called) then "
11741185
"whatever was there previously will be restored safely."
11751186
msgstr ""
1187+
"這代表你可以使用 :func:`patch.dict` 來\\ *暫時*\\ 在 :data:`sys.modules` 中原"
1188+
"地放置 mock。在這個 patch 存活時的任何 import 都會取得這個 mock。當 patch 完"
1189+
"成時(被裝飾的函式結束、with 陳述式主體完成或 ``patcher.stop()`` 被呼叫),那"
1190+
"麼之前在 ``sys.modules`` 中的任何內容都會被安全地復原。"
11761191

11771192
#: ../../library/unittest.mock-examples.rst:1154
11781193
msgid "Here's an example that mocks out the 'fooble' module."

0 commit comments

Comments
 (0)
0