Gigantic Win: how to run unit tests "in place"

39 views
Skip to first unread message

Edward K. Ream

unread,
Nov 24, 2016, 10:47:35 AM11/24/16
to leo-e...@googlegroups.com
If you develop code using Leo, please read at least the executive summary. It might change your life. It certainly has changed mine.

Executive Summary

1. A preamble in each @test node makes it easy to run unit tests locally, without reloading Leo!

2. A local test;; abbreviation could create new @test nodes, with customized preambles.

3. A new reload-abbreviation command (#340) will allow you to change the preamble without reloading Leo.

This is huge: for the first time ever, test-driven development will be easy and natural in Leo.
 
Details

I developed these ideas while working on the new importers.  Experience shows that I almost never get regex's right at first.  Creating a unit test for each regex saved time almost instantly, despite some initial setup costs.

The setup cost is that local unit tests must start with a custom preamble:

g.cls()
if c.isChanged(): c.save()
import imp
import leo.plugins.importers.otl as otl
imp.reload(otl)
x = otl.Otl_Importer(c.importCommands, atAuto=False)

With this preamble, I can run the tests after changing the otl plugin without reloading leoPlugins.leo.  This was the beginning of the avalanche...

Here is typical code that follows the preamble:

pattern = x.otl_pattern
print(pattern)
table = (
    'body line',
    '\tline 1',
    '  \tlevel 2',
)
for line in table:
    m = pattern.match(line)
    print('%20r ==> (%r)(%r)' % (
        line, m and m.group(1), m and m.group(2)))

Using this @test node, I can modify the regex and see the results instantly. This saved about 20+ seconds per coding iteration, a gigantic win.

It is impossible to overstate the importance of this new work flow!

It has changed my life. It also got me thinking about a further improvement, namely creating custom preambles for new tests more easily.

Issue #340 proposes a new reload-abbreviations command. This will allow devs to change the preamble without reloading Leo.  The ultimate work flow will be:

- Modify the local test;; abbreviation so that it supports the code under test.
- Run reload-abbreviations.
- Create new tests with test;;

This will make true test-driven development feasible, for the first time ever in Leo.

Edward

Edward K. Ream

unread,
Nov 24, 2016, 11:52:00 AM11/24/16
to leo-editor
On Thursday, November 24, 2016 at 9:47:35 AM UTC-6, Edward K. Ream wrote:

Issue #340 proposes a new reload-abbreviations command. This will allow devs to change the preamble without reloading Leo. 

Doh! reload-abbreviations is not necessary. I recently concluded that @button is often preferable to abbreviations.

@button make-test
<< create an @test node with a preamble >>

When changing testing environments, just change the preamble in @button make-test.

No need for reload-abbreviations.  We are ready to rock and roll.

EKR
Reply all
Reply to author
Forward
0 new messages