Yesterday will surely rank as one of the most important days in Leo's history.
tl;dr: It will be straightforward to provide complete coverage tests for most of Leo!
Like all momentous Ahas, it has suddenly become difficult to remember what the world looked like before the Aha. I am writing this post in the middle of the night, attempting to recreate the Aha, explain the way forward, and get back to sleep :-)
A slow-motion Aha
Yesterday I thought I was finally done with work on Leo. At last, I could start studying web technologies. Indeed, yesterday I completed the
"Hello World" example for VS Code plugins. But then fate intervened.
My subconscious nagged me about completing the elimination of c.onBodyChanged. This is
#1733. Yesterday I reopened this item, removed the "Won'tDo" label, and reassigned it to Leo 6.4. I did this because I saw that after simplifying c.onBodyChanged it would be easy to replace c.onBodyChanged with a
small amount of code, given in #1733.
I eliminated several calls to c.onBodyChanged using this strategy. I ran all unit tests, and they all passed.
So far, seemingly so good.
But now my subconscious started screaming at me: "Why are you doing this work? You have no idea whether your changes have been covered by unit tests. Admit it. You are flying blind."
According to github, I created
#1758 (Cover most of Leo with unit tests)
two days ago
. I am quite sure that when I created this item I did not have any idea how to do it! But presumably, this item primed my mental pump. That's probably why my subconscious was screaming at me yesterday.
Yesterday afternoon Rebecca and I took a long walk in some lovely woods overlooking the University of Wisconsin. After the walk, I saw the start of the way forward.
Strangely, I don't remember the exact moment. I remember discussing unit testing with Rebecca after the walk. Before dinner, I wrote a script to convert unit tests for edit commands in unitTest.leo to "traditional" unit tests.
It was only after discussing that script with Rebecca at dinner that I started to realize what I had just done! As I talked, I got more and more excited. The building excitement was similar to the "hand-waving Aha" about synchronizing tokens in leoAst.py.
The first conversion script
- Copy @file activeUnitTests.txt-->Organized by file-->leoEditCommands
from unitTest.leo to the top-level node of leoPy.leo.
- Create a new top-level node called 'new-tests'.
- Run the script.
The second comment also shows the output of the script, which is a "traditional" unit test.
Important: The script creates a list of Leo nodes. I'll copy these nodes to leoEditCommands.py. But like all other nodes in @file trees, the nodes create flat text in the external file. This means...
Aha 1: pytest does not have to know about Leo outlines!
Support classes
A new file, leo/core/leoTest2.py, will define the classes and helpers needed to make the new tests work. I'll adjust the conversion script to bring the generated nodes into "alignment" with the code in leoTest.py.
Aha 2: The kinds of support that leoTest2.py is much simpler than that contained in leoTest.py!
leoTest.py creates "flat" unit tests for python's unittest module. It's messy. In contrast, leoTest2.py just needs to define some base classes and simple support helpers.
Aha 3: here is no way to run coverage tests from unitTest.leo. unitTest.leo must go.
None of these three Ahas were clear to me until my dinner with my muse :-)
Summary
Running coverage tests is the crucial first step. Coverage failures will guide the testing process.
Scripts will convert unit tests in unitTest.leo to corresponding nodes containing traditional unit tests. I'll copy the generated nodes to the corresponding source files. The actual unit tests will be flat text in the external source file.
A new file, leoTest2.py, will provide support for the new testing framework. leoTest2.py will be much simpler than leoTest.py because it doesn't need to convert outlines to tests.
unitTest.leo must go. It was a useful dead end.
The ekr-undo9 branch contains preliminary work on the new testing framework.
I had expected that my sabbatical would be refreshing. I did not expect a huge breakthrough in Leo's world.
Edward