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

本章中描述的各模块可帮你编写 Python 程序。例如，"pydoc" 模块接受一个模
块并根据该模块的内容来生成文档。"doctest" 和 "unittest" 这两个模块包含
了用于编写单元测试的框架，并可用于自动测试所编写的代码，验证预期的输出
是否产生。**2to3** 程序能够将 Python 2.x 源代码翻译成有效的 Python 3.x
源代码。

本章中描述的模块列表是：

* "typing" --- 类型提示支持

  * Relevant PEPs

  * 类型别名

  * NewType

  * 可调对象（Callable）

  * 泛型（Generic）

  * 用户定义的泛型类型

  * "Any" 类型

  * 名义子类型 vs 结构子类型

  * 模块内容

    * 特殊类型原语

      * 特殊类型

      * 特殊形式

      * 构建泛型类型

      * 其他特殊指令

    * 泛型具象容器

      * 对应的内置类型

      * "collections" 对应类型

      * 其他具象类型

    * 抽象基类

      * "collections.abc" 对应的容器

      * "collections.abc" 对应的其他类型

      * 异步编程

      * 上下文管理器类型

    * 协议

    * 函数与装饰器

    * 内省辅助器

    * 常量

* "pydoc" --- 文档生成器和在线帮助系统

* Python 开发模式

* Python 开发模式的效果

* ResourceWarning 示例

* 文件描述符错误示例

* "doctest" --- 测试交互性的Python示例

  * 简单用法：检查Docstrings中的示例

  * 简单的用法：检查文本文件中的例子

  * 它是如何工作的

    * 哪些文件串被检查了？

    * 文档串的例子是如何被识别的？

    * 什么是执行上下文

    * 异常如何处理？

    * 选项标记

    * 指令

    * 警告

  * 基本API

  * Unittest API

  * 高级 API

    * DocTest 对象

    * Example 对象

    * DocTestFinder 对象

    * DocTestParser 对象

    * DocTestRunner 对象

    * OutputChecker 对象

  * 调试

  * 肥皂盒

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

  * 簡單範例

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

    * 命令列模式選項

  * Test Discovery（測試探索）

  * 组织你的测试代码

  * 复用已有的测试代码

  * 跳过测试与预计的失败

  * 使用子测试区分测试迭代

  * 类与函数

    * 测试用例

      * 已弃用的别名

    * 分组测试

    * 加载和运行测试

      * load_tests 协议

  * 类与模块设定

    * setUpClass 和 tearDownClass

    * setUpModule 和 tearDownModule

  * 信号处理

* "unittest.mock" --- mock对象库

  * 快速上手

  * Mock 类

    * 调用

    * 删除属性

    * Mock 的名称与 name 属性

    * 附加 Mock 作为属性

  * patch 装饰器

    * patch

    * patch.object

    * patch.dict

    * patch.multiple

    * patch methods: start and stop

    * patch builtins

    * TEST_PREFIX

    * Nesting Patch Decorators

    * Where to patch

    * Patching Descriptors and Proxy Objects

  * MagicMock and magic method support

    * Mocking Magic Methods

    * Magic Mock

  * Helpers

    * sentinel

    * DEFAULT

    * call

    * create_autospec

    * ANY

    * FILTER_DIR

    * mock_open

    * Autospeccing

    * Sealing mocks

* "unittest.mock" 上手指南

  * 使用 mock

    * 模拟方法调用

    * 对象上的方法调用的 mock

    * Mocking Classes

    * Naming your mocks

    * Tracking all Calls

    * Setting Return Values and Attributes

    * Raising exceptions with mocks

    * Side effect functions and iterables

    * Mocking asynchronous iterators

    * Mocking asynchronous context manager

    * Creating a Mock from an Existing Object

  * Patch Decorators

  * Further Examples

    * Mocking chained calls

    * Partial mocking

    * Mocking a Generator Method

    * Applying the same patch to every test method

    * Mocking Unbound Methods

    * Checking multiple calls with mock

    * Coping with mutable arguments

    * Nesting Patches

    * Mocking a dictionary with MagicMock

    * Mock subclasses and their attributes

    * Mocking imports with patch.dict

    * Tracking order of calls and less verbose call assertions

    * More complex argument matching

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

  * 使用 2to3

  * 修复器

  * "lib2to3" —— 2to3 支持库

* "test" ---  Python回归测试包

  * Writing Unit Tests for the "test" package

  * Running tests using the command-line interface

* "test.support" --- Utilities for the Python test suite

* "test.support.socket_helper" --- Utilities for socket tests

* "test.support.script_helper" --- Utilities for the Python execution
  tests

* "test.support.bytecode_helper" --- Support tools for testing correct
  bytecode generation
