Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test code examples in docs using doctest #339

Open
andyk opened this issue Mar 24, 2022 · 0 comments
Open

Test code examples in docs using doctest #339

andyk opened this issue Mar 24, 2022 · 0 comments

Comments

@andyk
Copy link
Contributor

andyk commented Mar 24, 2022

It should be pretty easy to automatically include test example code in our docs via doctest using doctest.testfile on core ReStructuredText files in our docs.

We can also test our demo scripts wherever we end up adding them to the source per #323.

To see how easy it is to us doctest, try out:

# from inside an agentos dev virtualenv
cd agentos
python
>>> import doctest
>>> doctest.testfile("documentation/overview.rst")

**********************************************************************
File "./documentation/repl_quickstart.rst", line 31, in repl_quickstart.rst
Failed example:
    from agentos import Component
Exception raised:
    Traceback (most recent call last):
      File "/opt/homebrew/Caskroom/miniforge/base/envs/tmp_agentos/lib/python3.8/doctest.py", line 1336, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest repl_quickstart.rst[1]>", line 1, in <module>
        from agentos import Component
    ImportError: cannot import name 'Component' from 'agentos' (/Users/andyk/Development/agentos/agentos/__init__.py)
**********************************************************************
File "./documentation/repl_quickstart.rst", line 32, in repl_quickstart.rst
Failed example:
    adder_component = Component.from_class(Adder)
Exception raised:
    Traceback (most recent call last):
      File "/opt/homebrew/Caskroom/miniforge/base/envs/tmp_agentos/lib/python3.8/doctest.py", line 1336, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest repl_quickstart.rst[2]>", line 1, in <module>
        adder_component = Component.from_class(Adder)
    NameError: name 'Component' is not defined
**********************************************************************
File "./documentation/repl_quickstart.rst", line 38, in repl_quickstart.rst
Failed example:
    adder_component.run('add_one', {'Adder':{'add_one':{'x':1}}})
Exception raised:
    Traceback (most recent call last):
      File "/opt/homebrew/Caskroom/miniforge/base/envs/tmp_agentos/lib/python3.8/doctest.py", line 1336, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest repl_quickstart.rst[3]>", line 1, in <module>
        adder_component.run('add_one', {'Adder':{'add_one':{'x':1}}})
    NameError: name 'adder_component' is not defined
**********************************************************************
1 items had failures:
   3 of   4 in repl_quickstart.rst
***Test Failed*** 3 failures.
TestResults(failed=3, attempted=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant