#!/usr/bin/env python # coding: utf-8 # # testing notebook # # notebooks are used to test informal ideas. in this workshop, we're learn about the nearness between informal and formal tests, and the value of formal testing. # # ![](https://github.com/deathbeds/drawins/raw/master/fight%20the%20ocean.jpg) # In[1]: ## trivia get_ipython().run_line_magic('pinfo', 'deprecated') get_ipython().run_line_magic('pinfo', 'programming') get_ipython().run_line_magic('pinfo', 'access') get_ipython().run_line_magic('pinfo', 'education') * Jan Hendrik Schön was a german research at bell labs that studied lasers, and their get_ipython().run_line_magic('pinfo', 'for') # ## software testing has a lot of flavors # # we are to focus on [unit testing](https://en.wikipedia.org/wiki/Unit_testing) # https://en.m.wikipedia.org/wiki/Software_testing # In[2]: ## communicating units of thought > A testing unit should focus on one tiny bit of functionality and prove it correct. # In[3]: https://docs.python-guide.org/writing/tests/ # ## the `vvvvv`s of big data # ![](https://github.com/deathbeds/drawins/raw/master/vvv%20forms.jpg) # # ![image.png](attachment:2011c69c-7565-4d29-8a31-c4938e3f5b1c.png) # # ![image.png](attachment:d9dbeb53-e076-4cfa-bfcb-f88f6bbc4090.png) # ## this week we focus on veracity. The Truth! # In[4]: https://www.merriam-webster.com/dictionary/veracity # In[5]: ### why is veracity important? # In[6]: https://en.m.wikipedia.org/wiki/Replication_crisis # ## structuralism: ferdinand saussure # # ### signification = signified(signifier) # # > The relationship between the signifier and signified is an arbitrary relationship: "there is no logical connection" between them. This differs from a symbol, which is "never wholly arbitrary." # In[7]: https://en.m.wikipedia.org/wiki/Signified_and_signifier # In[8]: #### signifier and signified in literate programming literature survives only with language. when narrative relies solely on language signs we suffer the arbitriness of signification. on the other hand, literate programs rely on a metalanguages (more than one language cooperating together) of signs in language and symbols in coded languages. in literate programming we can mitigate some lack of clarity by controlling what is expressed to our reader using programmatic symbols to complement language signs. in literate programming, we have a little more control over the expression of meaning in our work than with conventional literature. we rely on our expressions of code to reassure our readers that we are telling the truth. # In[9]: ## restart and run all we trust a notebook that will __restart and run all__ ### inside and outside the notebook dynamic or static, inside or outside, in the kernel or at rest, there are two very different states of the content in a notebook. notebooks, after we stop editting, remain static and at rest. we can increase the value of our work if we can find ways to make our writing valuable at rest. an efficient for literate programs authors is consider their notebooks so that, at rest, they may still provide you value. # ## formal testing # # the teacher's personal preference is use the final cell for testing, i personally, use the # [`__name__= "__main__"` convention](https://docs.python.org/3/library/__main__.html). # ### the last cell # #### test with `doctest` # In[22]: # NBVAL_SKIP if __name__ == "__main__": import doctest print(doctest.testmod()) # #### test with `unittest` # In[23]: # NBVAL_SKIP if __name__ == "__main__": import unittest unittest.main(argv=["discover"], exit=False) # #### test the notebook with `nbval and pytest` # In[24]: # NBVAL_SKIP if __name__ == "__main__" and "pytest" not in sys.modules: result = get_ipython().getoutput('pytest --nbval testing-notebooks.md.ipynb') print("\n".join(result[:10])) # #### test the script # In[25]: # NBVAL_SKIP if __name__ == "__main__" and "pytest" not in sys.modules: "convert notebook to script" "run pytest or unittest on the script" # In[26]: https://www.quansight.com/post/formal-interactive-notebook-testing # ## conclusion # In[27]: https://web.archive.org/web/20201111060706/https://github.com/deathbeds/LitAF # ![](https://github.com/deathbeds/drawins/raw/master/embrace%20the%20void.jpg) # ### homework # # * write a literate program that tests something # * test an api you know about # * test an api you've wanted to try # * try either standard lib of community tools # * formally test that notebook # * ci or binder # In[28]: ## discussion on lasting impact * what does it mean for science to have a lasting impact? * how does science and its literature effect language?