Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up[Infrastructure] Testing outputs #258
Comments
|
Here are example script/test files
@faif Hi. Can you please share your thoughts on this? |
|
Hi, I like this idea since it makes the outputs unit-testable. |
|
hey @faif Here is a basic example of before-after of this idea: CURRENT (input and then output) def main():
template_function(get_text, to_save=True)
print("-" * 30)
template_function(get_pdf, converter=convert_to_text)
print("-" * 30)
template_function(get_csv, to_save=True)
if __name__ == "__main__":
main()
OUTPUT = """
Got `plain-text`
Skip conversion
[SAVE]
`plain-text` was processed
------------------------------
Got `pdf`
[CONVERT]
`pdf as text` was processed
------------------------------
Got `csv`
Skip conversion
[SAVE]
`csv` was processed
"""PROPOSED HERE (interleaved) def main():
"""
>>> template_function(get_text, to_save=True)
Got `plain-text`
Skip conversion
[SAVE]
`plain-text` was processed
>>> template_function(get_pdf, converter=convert_to_text)
Got `pdf`
[CONVERT]
`pdf as text` was processed
>>> template_function(get_csv, to_save=True)
Got `csv`
Skip conversion
[SAVE]
`csv` was processed
"""
if __name__ == "__main__":
import doctest
doctest.testmod()I think the second example it is much-much easier to read. I took short and simple output and I do understand that some difficulties can occur with longer ones, but I believe that this is worth it. As for testing, it is as simple as As for auto-generated output vs human generated one.. auto-generated is not correct just because. It still needs review. |
|
I'm not very familiar with doctest so I'm not sure if it can replace all current functionality. You can pick a more complex use case and give it a try. I'm generally positive with the proposal. |
|
I created #283 for illustration purposes. Here are some things to point out:
|
|
To update on this issue, what is left to do:
|
|
I think we're almost done with substituting all files with doctests! The only one left is for abstract_factory.py which is ambiguous due to its random output for the The other thing left to do would be to update the contributing section of |
|
@gyermolenko got it and on it, thanks for the tip! |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

update on idea of testing outputs as docstrings (e.g. with
python -m doctest):I couldn't find easy way to generate docstrings for
def main()By "testing outputs" I mean to compare script output with
### OUTPUT ###section at the bottom of the file.Structuring scripts like that:
allows imports of
mainin tests to evaluate and compare outputs.It would also be more convenient to have
### OUTPUT ###section as variable or docstring, so we do not need to parse file for such comparisons