开发工具
********

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

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

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

  * 类型别名

  * NewType

  * 可调对象（Callable）

  * 泛型（Generic）

  * 用户定义的泛型类型

  * "Any" 类型

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

  * 模块内容

    * 特殊类型原语

      * 特殊类型

      * 特殊形式

      * 构建泛型类型

      * 其他特殊指令

    * 泛型具象容器

      * 对应的内置类型

      * "collections" 对应类型

      * 其他具象类型

    * 抽象基类

      * "collections.abc" 对应的容器

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

      * 异步编程

      * 上下文管理器类型

    * 协议

    * 函数与装饰器

    * 内省辅助器

    * 常量

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

* Python Development Mode

* Effects of the Python Development Mode

* ResourceWarning Example

* Bad file descriptor error example

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

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

  * Simple Usage: Checking Examples in a Text File

  * How It Works

    * Which Docstrings Are Examined?

    * How are Docstring Examples Recognized?

    * What's the Execution Context?

    * What About Exceptions?

    * Option Flags

    * Directives

    * 警告

  * Basic API

  * Unittest API

  * Advanced API

    * DocTest 对象

    * Example Objects

    * DocTestFinder 对象

    * DocTestParser 对象

    * DocTestRunner 对象

    * OutputChecker 对象

  * 调试

  * Soapbox

* "unittest" --- 单元测试框架

  * 基本实例

  * 命令行界面

    * 命令行选项

  * 探索性测试

  * 组织你的测试代码

  * 复用已有的测试代码

  * 跳过测试与预计的失败

  * Distinguishing test iterations using subtests

  * 类与函数

    * 测试用例

      * Deprecated aliases

    * Grouping tests

    * Loading and running tests

      * load_tests Protocol

  * Class and Module Fixtures

    * setUpClass and tearDownClass

    * setUpModule and tearDownModule

  * 信号处理

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

  * 快速上手

  * Mock 类

    * Calling

    * Deleting Attributes

    * Mock names and the name attribute

    * Attaching Mocks as Attributes

  * The patchers

    * 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
