-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the doctest module in get_example_data (#308)
Fixes #282 Still several todos here: - [x] Clean up code (probably don't need to define the class inside of the function) - [ ] Add tests - [ ] Check that the generated JSON is as desired (the execution status is not actually included. I'm not clear why) - [ ] Make it so that any doctest anywhere is run, not just ones in "Examples" (this doesn't necessarily need to be done in this PR) - [ ] Allow libraries to configure doctest options (like ELLIPSIS) Here's an example: ```py def docstring(x): """ Examples ======== >>> from test_mod import docstring >>> a = docstring(1) >>> a 2 >>> 1 + a 3 >>> import matplotlib.pyplot as plt >>> plt.plot([0, 1], [0, 1]) >>> plt.show() >>> 1 + 1 2 >>> syntax error >>> 1/0 # exception Traceback (most recent call last): File "<stdin>", line 1, in <module> ZeroDivisionError: division by zero >>> 1/0 # unexpected exception """ return x + 1 __version__ = '0' ``` ```toml [global] module = 'test_mod' ``` Generates ```json "example_section_data": { "children": [ { "type": "code", "value": "from test_mod import docstring\n" }, { "type": "code", "value": "a = docstring(1)\n" }, { "type": "code", "value": "a\n" }, { "type": "code", "value": "1 + a\n" }, { "type": "code", "value": "import matplotlib.pyplot as plt\n" }, { "type": "code", "value": "plt.plot([0, 1], [0, 1])\n" }, { "type": "code", "value": "plt.show()\n" }, { "type": "Fig", "value": { "kind": "assets", "module": "test_mod", "path": "fig-test_mod:docstring-0-c8430bd5.png", "type": "RefInfo", "version": "0" } }, { "type": "code", "value": "1 + 1\n" }, { "type": "code", "value": "syntax error\n" }, { "type": "code", "value": "1/0 # exception\n" }, { "type": "code", "value": "1/0 # unexpected exception\n" } ], ```
- Loading branch information
Showing
16 changed files
with
194 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.