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

本章所描述的模組可以幫助你編寫軟體。例如 "pydoc" 模組可以根據模組的內
容生成文件；"doctest" 和 "unittest" 模組則包含編寫單元測試的框架，這些
測試程式碼會自動執行並驗證輸出結果是否正確。

本章節所描述的模組列表為：

* "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 的別名

      * "collections.abc" 中非同步 ABC 的別名

      * Aliases to other ABCs in "collections.abc"

      * "contextlib" ABC 的別名

  * 主要功能的棄用時程表

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

* Python 開發模式

  * Python 開發模式的影響

  * ResourceWarning 範例

  * 檔案描述器的錯誤範例

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

  * Simple Usage: Checking Examples in Docstrings

  * Simple Usage: Checking Examples in a Text File

  * 命令列用法

  * 運作方式

    * 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 物件

    * TestResults 物件

    * DocTestRunner 物件

    * OutputChecker 物件

  * 偵錯

  * Soapbox

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

  * 簡單範例

  * 命令列介面

    * 命令列模式選項

  * Test Discovery（測試探索）

  * Organizing test code

  * Re-using old test code

  * Skipping tests and expected failures

  * Distinguishing test iterations using subtests

  * 類別與函式

    * Test cases

    * Grouping tests

    * Loading and running tests

      * load_tests 協定

  * Class and Module Fixtures

    * setUpClass 和 tearDownClass

    * setUpModule 和 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

  * "side_effect"、"return_value" 和 *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

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

    * 更複雜的引數匹配

* "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 測試的工具
