自动测试文档中的示例

Automatic testing of examples in documentation

SageMath manual 的结尾,他们解释了为什么选择在 Python 中实施 SageMath。其中一项说:"Excellent support for documentation of functions and packages in the source code, including automatic extraction of documentation and automatic testing of all examples. The examples are automatically tested regularly and guaranteed to work as indicated."

这听起来不错,但我还没有找到实现它的方法。如何自动测试文档中出现的所有示例到我的功能?

原则上,您可以使用this syntax编写示例。然后,你应该可以做到

sage -t path/to/myfile.sage

鉴于评论线程,显然可行!