The syntax of doctests

Doctest語法
        
You might have guessed from looking at the previous example: doctest recognizes tests by looking for sections of text that look like they've been copied and pasted from a Python interactive session. Anything that can be expressed in Python is valid within a doctest.        
通過查看之前的例子您可能已經猜到: doctest通過搜尋文本塊來識別測試,這些文本看起來像是拷貝粘貼自Python交互會話。  任何能在python中表達的在doctest內都是有效的。

                                                   
Lines that start with a >>> prompt are sent to a Python interpreter. Lines that start with a ... prompt are sent as continuations of the code from the previous line, allowing you to embed complex block statements into your doctests. Finally, any lines that don't start with >>> or ..., up to the next blank line or >>> prompt, represent the output expected from the statement. The output appears as it would in an interactive Python session, including both the return value and the one printed to the console. If you don't have any output lines, doctest assumes it to mean that the statement is expected to have no visible result on the console.
以>>> 提示符開始的行被髮送給Python解釋器。以...開始的行延續前一行代碼發送,允許你將複雜的塊語句嵌入到你的doctest。最後,凡是到下一個空 行或者>>>提示符前不以>>>或...開頭的行都代表描述語句預期的輸出。這個輸出就好像是在一個交互的 python會話中產生的,其中包括返回值以及打印到控制檯上的輸出。如果您沒有任何輸出行,那麼doctest理解的含義是該語句將不會在控制檯上有可 見的結果輸出。
**assume, suggest 等詞通常翻譯成認爲或理解。**
                                                   
Doctest ignores anything in the file that isn't part of a test, which means that you can place explanatory text, HTML, line-art diagrams, or whatever else strikes your fancy in between your tests. We took advantage of that in the previous doctest, to add an explanatory sentence before the test itself.
Doctest忽略任何文件中與測試無關的部分,也就是說你能放置說明性的文本,HTML, 線條圖表,    或任何其它測視裏你喜歡添加的內容。 在之前的doctest裏我們可利用這一特點在測試前添加一個說明性文字。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章