Coder Social home page Coder Social logo

ceddlyburge / docs-from-tests-example Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 12 KB

This is a demonstration repo, showing how to use the docs-from-tests python package.

Home Page: https://www.freecodecamp.org/news/how-to-create-documentation-from-your-python-tests/

Python 93.59% PowerShell 6.41%
diagrams-as-code mermaid python sequence-diagram documentation-as-code

docs-from-tests-example's Introduction

Example usage of "docs-from-tests" package

This is a demonstration repo, showing how to use the docs-from-tests python package. More background on why should want to do this are in the How to Create Documentation from Your Python Tests blog post.

The package contains functions to instrument your code / tests to create a sequence diagram (in markdown / mermaid) as the tests run. The sequence diagrams show the runtime call hierachy of the code, and are saved as files in the repository, which are checked in. You can choose to ignore specific functions, and private functions, to make the diagram readable in each context you are interested in.

The diagrams are useful documentation, and will stay up to date as they are automatically generated. Hopefully it will encourage us to have useful diagrams in the repo, with the appropriate levels of detail, which in turn will encourage us to structure the code well so it produces good diagrams, and to have tests at these levels of detail.

Build Status

Build status

Example Usage

You can see an example of generating documentation from tests at tests\test_hello_world.py

There is an end to end test, and a unit test, and they produce the documentation / graphs below

The graphs are reproduced here for convenience. They are mermaid diagrams, you may need to install a Browser Plugin or VsCode extension or similar to view them.

End to end

View full screen as an SVG

sequenceDiagram
  start->>HelloWorldCombiner.combine: calls x1
  HelloWorldCombiner.combine->>hello: calls x1
  hello-->>HelloWorldCombiner.combine: returns str
  HelloWorldCombiner.combine->>World.world: calls x1
  World.world-->>HelloWorldCombiner.combine: returns str
  HelloWorldCombiner.combine-->>start: returns str

Unit test

View full screen as SVG

sequenceDiagram
  start->>World.world: calls x1
  World.world->>World._w: calls x1
  World._w-->>World.world: returns str
  World.world->>World._o: calls x1
  World._o-->>World.world: returns str
  World.world->>World._r: calls x1
  World._r-->>World.world: returns str
  World.world->>World._l: calls x1
  World._l-->>World.world: returns str
  World.world->>World._d: calls x1
  World._d-->>World.world: returns str
  World.world-->>start: returns str

Running tests

  • use python>=3.7
  • pip install requirements.txt
  • set pythonpath=<path to root of this repo>
  • pytest

Contributing

  • Use PEP-0008
  • Please open up an Issue for new work, where any discussion can take place, and then submit a pull request to fix the issue.

docs-from-tests-example's People

Contributors

ceddlyburge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.