PyLuaTeX
PyLuaTeX copied to clipboard
Issue with doctest
Hi,
the following code as an issue together with the function testmod of doctest module (a space is missing in (2,5)). I get the issue with a classical IDE, but not with latex/pyluatex.
Thanks, and merry Christmas !
\documentclass[11pt]{article}
\usepackage{xcolor}
\usepackage{piton}
\usepackage{pyluatex}
\NewDocumentEnvironment { PitonREPL } { !O{ } } % le ! est obligatoire
{
\PyLTVerbatimEnv
\begin{pythonrepl}
}
{
\directlua
{
tex.print("\\begin{Piton}")
tex.print(pyluatex.get_last_output())
tex.print("\\end{Piton}")
tex.print("")
}
\end{pythonrepl}
}
\begin{document}
\begin{python}
import doctest
def division(a: int, b: int) -> (int, int):
"""
>>> division(19, 7)
(2,5)
"""
if (a<0) or (b<=0):
return None
q, r = 0, a
while r >= b:
q += 1
r -= b # bq+r = b(q+1) + (r-b)
return (q, r)
\end{python}
\begin{PitonREPL}
doctest.testmod()
\end{PitonREPL}
\end{document}
Hi,
unfortunately, testmod() does not find your function. If you run testmod(verbose=True), you get the following output:
>>> doctest.testmod(verbose=True)
12 items had no tests:
__main__
__main__.Handler
__main__.Handler.handle
__main__.Interpreter
__main__.Interpreter.__init__
__main__.Interpreter.execute
__main__.Interpreter.execute_repl
__main__.Interpreter.showtraceback
__main__.PyLTTex
__main__.PyLTTex.__init__
__main__.PyLTTex._log_message
__main__.PyLTTex.log
0 tests in 12 items.
0 passed and 0 failed.
Test passed.
TestResults(failed=0, attempted=0)
The functions that are inspected all belong to the PyLuaTeX interpreter code, i.e. testmod() basically inspects the pyluatex-interpreter.py file/module and not the code of the LaTeX session. I don't know how to change this.
Possible workaround:
doctest.run_docstring_examples(division, globals())
Merry Christmas :)