question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[doctest] Provide definition of `default_evaluator` and other default objects

See original GitHub issue

📚 Documentation

It was already discussed and also pointed out in the forum that it is unclear how default objects are defined inside doctest examples. For example: https://pytorch.org/ignite/generated/ignite.metrics.Accuracy.html#ignite.metrics.Accuracy

metric = Accuracy()
metric.attach(default_evaluator, "accuracy")
y_true = torch.Tensor([1, 0, 1, 1, 0, 1])
y_pred = torch.Tensor([1, 0, 1, 0, 1, 1])
state = default_evaluator.run([[y_pred, y_true]])
print(state.metrics["accuracy"])

We can think of different solutions:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
DevPranjalcommented, Feb 9, 2022

Hi @vfdev-5 @sdesrozis, I was trying a few options to resolve this problem

Ideal solution would be to find how to make this code foldable (IMO, it shouldn’t be easy). So that once rendered we could have something like

I ended up with this using the sphinx_togglebutton extension

https://user-images.githubusercontent.com/72960463/153129453-84a1aeba-f0b8-4396-8059-e809cf9c181f.mp4

Currently, I am using code docstring below:

.. toggle::
   .. testcode::
        <defaults>
...

But as mentioned,

Ideally, we do not want to have all declarations to be present at each docstring, it would be better to predefine them somehow and while rendering the docs, add to the place where they should be

I tried the below, but was not able to get it to work:

.. toggle::        
     .. include:: defaults.rst
...
1reaction
vfdev-5commented, Feb 9, 2022

@DevPranjal I just tried to use .. include:: directive here and looks like it works:

image

Can you try this in your fork to see if everything could work with toggle ?

Docs for include directive: https://docutils.sourceforge.io/docs/ref/rst/directives.html#include

EDIT: I think we have to manually copy defaults.rst to source/generated in order to be discovered from the docstring. I updated my fork. You can borrow the code from it and send a PR.

image
Read more comments on GitHub >

github_iconTop Results From Across the Web

doctest — Test interactive Python examples — Python 3.11.1 ...
Test examples associated with object f; for example, f may be a string, a module, a function, or a class object. A shallow...
Read more >
Python's doctest: Document and Test Your Code at Once
In this tutorial, you'll learn how to add usage examples to your code's documentation and docstrings and how to use these examples to...
Read more >
How To Write Doctests in Python - DigitalOcean
Python's standard library comes equipped with a test framework module called doctest. The doctest module programmatically searches Python ...
Read more >
doctest — Testing Through Documentation — PyMOTW 3
It works by parsing the help text to find examples, running them, then comparing the output text against the expected value.
Read more >
doctest/assertions.md at master - GitHub
doctest is different (but it's like Catch in this regard). ... A doctest::Context object still has to be created somewhere and set as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found