開發工具
********

The modules described in this chapter help you write software.  For
example, the "pydoc" module takes a module and generates documentation
based on the module's contents.  The "doctest" and "unittest" modules
contains frameworks for writing unit tests that automatically exercise
code and verify that the expected output is produced.  **2to3** can
translate Python 2.x source code into valid Python 3.x code.

The list of modules described in this chapter is:

* "typing" --- 支援型別提示

  * Python 型別系統的技術規範

  * 型別別名

  * NewType

  * 註釋 callable 物件

  * 泛型

  * 註釋元組 (tuple)

  * 類別物件的型別

  * Annotating generators and coroutines

  * 使用者定義泛型型別

  * "Any" 型別

  * 標稱 (nominal) 子型別 vs 結構子型別

  * 模組內容

    * 特別型別原語 (primitive)

      * 特別型別

      * 特別型式

      * Building generic types and type aliases

      * Other special directives

    * 協定

    * ABCs for working with IO

    * 函式與裝飾器

    * Introspection helpers

    * 常數

    * 棄用的別名

      * 內建型別的別名

      * "collections" 中型別的別名

      * Aliases to other concrete types

      * "collections.abc" 中容器 ABC 的別名

      * Aliases to asynchronous ABCs in "collections.abc"

      * Aliases to other ABCs in "collections.abc"

      * "contextlib" ABC 的別名

  * Deprecation Timeline of Major Features

* "pydoc" --- 文件產生器與線上幫助系統

* Python 開發模式

  * Python 開發模式的影響

  * ResourceWarning 範例

  * 檔案描述器的錯誤範例

* "doctest" --- 測試互動式 Python 範例

  * Simple Usage: Checking Examples in Docstrings

  * Simple Usage: Checking Examples in a Text File

  * Command-line Usage

  * How It Works

    * Which Docstrings Are Examined?

    * How are Docstring Examples Recognized?

    * What's the Execution Context?

    * What About Exceptions?

    * 可選旗標

    * Directives

    * 警告

  * 基礎 API

  * Unittest API

  * Advanced API

    * DocTest 物件

    * Example 物件

    * DocTestFinder 物件

    * DocTestParser 物件

    * DocTestRunner 物件

    * OutputChecker 物件

  * Debugging

  * Soapbox

* "unittest" --- 單元測試框架

  * 簡單範例

  * 命令執行列介面 (Command-Line Interface)

    * 命令列模式選項

  * Test Discovery（測試探索）

  * Organizing test code

  * Re-using old test code

  * Skipping tests and expected failures

  * Distinguishing test iterations using subtests

  * Classes and functions

    * Test cases

    * Grouping tests

    * Loading and running tests

      * load_tests Protocol

  * Class and Module Fixtures

    * setUpClass and tearDownClass

    * setUpModule and tearDownModule

  * Signal Handling

* "unittest.mock" — mock 物件函式庫

  * 快速導引

  * Mock 類別

    * 呼叫

    * 刪除屬性

    * Mock 名稱與名稱屬性

    * 如同屬性一般附加 mock

  * Patchers

    * patch

    * patch.object

    * patch.dict

    * patch.multiple

    * patch 方法：啟動與停止

    * patch 內建函式

    * TEST_PREFIX

    * 巢狀使用 Patch 裝飾器

    * 該 patch 何處

    * Patch 描述器與代理物件 (Proxy Objects)

  * MagicMock 以及魔術方法支援

    * Mock 魔術方法

    * Magic Mock

  * 輔助函式

    * sentinel（哨兵）

    * DEFAULT

    * call

    * create_autospec

    * ANY

    * FILTER_DIR

    * mock_open

    * Autospeccing（自動規格）

    * 密封 mock

  * Order of precedence of "side_effect", "return_value" and *wraps*

* "unittest.mock" --- 入門指南

  * 使用 Mock 的方式

    * 使用 Mock 來 patching 方法

    * 對物件的方法呼叫使用 mock

    * Mock 類別

    * 命名你的 mock

    * 追蹤所有呼叫

    * 設定回傳值和屬性

    * 透過 mock 引發例外

    * Side effect 函式以及可疊代物件

    * Mock 非同步可疊代物件

    * Mock 非同步情境管理器

    * 從現有物件建立 mock

    * 使用 side_effect 回傳各別檔案內容

  * Patch 裝飾器

  * 更多範例

    * Mock 鍊接呼叫

    * 部分 mocking

    * Mock 產生器方法

    * 對每個測試方法應用相同的 patch

    * Mock Unbound Methods （未繫結方法）

    * 使用 mock 檢查多個呼叫

    * 應對可變引數

    * 巢狀使用 Patch

    * 使用 MagicMock 來 mock 字典

    * Mock 子類別及其屬性

    * 使用 patch.dict 來 mock import

    * 追蹤呼叫順序與更簡潔的呼叫斷言

    * 更複雜的引數匹配

* 2to3 --- 自動將 Python 2的程式碼轉成 Python 3

  * 使用 2to3

  * Fixers

  * "lib2to3" --- 2to3's library

* "test" --- Python 的回歸測試 (regression tests) 套件

  * 撰寫 "test" 套件的單元測試

  * 使用命令列介面執行測試

* "test.support" --- Python 測試套件的工具

* "test.support.socket_helper" --- 用於 socket 測試的工具

* "test.support.script_helper" --- 用於 Python 執行測試的工具

* "test.support.bytecode_helper" --- 用於測試位元組碼能正確產生的支援
  工具

* "test.support.threading_helper" --- Utilities for threading tests

* "test.support.os_helper" --- 用於 os 測試的工具

* "test.support.import_helper" --- 用於 import 測試的工具

* "test.support.warnings_helper" --- 用於 warnings 測試的工具
