Development Tools开发工具¶
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. pydoc
模块接受一个模块并基于该模块的内容生成文档。The doctest
and unittest
modules contains frameworks for writing unit tests that automatically exercise code and verify that the expected output is produced. doctest
和unittest
模块包含用于编写单元测试的框架,单元测试可以自动执行代码并验证是否生成了预期的输出。2to3 can translate Python 2.x source code into valid Python 3.x code.它可以将Python 2x源代码转换为有效的Python 3x代码。
The list of modules described in this chapter is:本章描述的模块列表如下:
typing
—Support for type hints支持类型提示Relevant PEPs相关政治公众人物Type aliases输入别名- NewType
- Callable
Generics泛型User-defined generic types用户定义的泛型类型- The
Any
type Nominal vs structural subtyping标称与结构子类型Module contents模块内容
pydoc
—Documentation generator and online help system文档生成器和在线帮助系统Python Development ModePython开发模式Effects of the Python Development ModePython开发模式的影响- ResourceWarning Example
Bad file descriptor error example错误的文件描述符错误示例doctest
—Test interactive Python examples测试交互式Python示例unittest
—Unit testing framework单元测试框架unittest.mock
— mock object libraryunittest.mock
—getting started开始Using Mock使用模拟Mock Patching Methods模拟修补方法Mock for Method Calls on an Object模拟对象上的方法调用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使用mock检查多个调用Coping with mutable arguments应对多变的争论Nesting Patches嵌套补丁Mocking a dictionary with MagicMock用MagicMock模拟字典Mock subclasses and their attributes模拟子类及其属性Mocking imports with patch.dict用patch.dict模拟导入Tracking order of calls and less verbose call assertions跟踪调用顺序和更少冗长的调用断言More complex argument matching更复杂的参数匹配
- 2to3 -
Automated Python 2 to 3 code translation自动Python 2到3代码翻译 test
—Regression tests package for PythonPython回归测试包test.support
—Utilities for the Python test suitePython测试套件的实用程序test.support.socket_helper
—Utilities for socket tests套接字测试的实用程序test.support.script_helper
—Utilities for the Python execution testsPython执行测试的实用程序test.support.bytecode_helper
—Support tools for testing correct bytecode generation支持测试正确字节码生成的工具test.support.threading_helper
—Utilities for threading tests线程测试实用程序test.support.os_helper
—Utilities for os tests操作系统测试实用程序test.support.import_helper
—Utilities for import tests导入测试的实用程序test.support.warnings_helper
—Utilities for warnings tests警告测试实用程序