On Dec 17, 12:59 pm, "Edward K. Ream" <[email protected]> wrote:
> I just ran across a situation in which these dialogs are more than
> merely annoying. After running a script that created dozens of @auto
> nodes, saving the .leo file raised the dialog for each created @auto
> node.. This is unacceptable. Instead, Leo should raise at most one
> dialog that references messages in the log pane. This will avoid the
> user having to abort a read or save operation merely to avoid dozens
> (or hundreds) of dialogs.
Done at rev 4898.
This turned out to be quite a project, because there are many ways to
read and write files in Leo. The challenge was to write clean code,
and to ensure that Leo raises at most one error dialog for any
command.
This is also a milestone for Leo: it marks the first time that a unit
test was an essential part of the *design* of a new feature.
Here is the unit test (it's in unitTest.leo)::
QQQQQ
@test all top-level read/write commands give proper read/write error
dialogs
child = p.firstChild()
assert child
assert child.h == 'child',child.h
c.selectPosition(child)
table = (
'import-file',
'open-outline',
'read-at-auto-nodes',
'read-at-file-nodes',
'read-at-shadow-nodes',
# 'read-file-into-node',
# 'read-outline-only',
'save-file',
'save-file-as',
'save-file-to',
'write-at-auto-nodes',
'write-at-file-nodes',
'write-at-shadow-nodes',
'write-dirty-at-auto-nodes',
'write-dirty-at-file-nodes',
'write-dirty-at-shadow-nodes',
#'write-file-from-node',
'write-missing-at-file-nodes',
#'write-outline-only',
)
tags = (('init_error_dialogs',2), ('raise_error_dialogs',1))
d = g.app.unitTestDict
for commandName in table:
for tag,n in tags:
d[tag] = 0
c.k.simulateCommand(commandName)
for tag,n in tags:
assert d.get(tag) == n,'commandName: %s,tag: %s, n: %s' %
(commandName,tag,d.get(tag))
QQQQQ
The point is that the table lists all Leo commands that should raise
the error dialogs, and the test itself verifies that the dialog code
is called exactly once for each command. This is a non-trivial test,
and failed initially for several commands.
**Important**: the world won't end if I missed a command that should
raise these error dialogs, but I think I've got them all.
Here is the checkin log:
QQQQQ
Ensure that only a single file error dialog is ever raised, no matter
how many files contain errors.
This was quite a project. It was driven by a new unit test.
What I did:
Created c.init_error_dialogs & c.raise_error_dialogs.
These are called from the following methods:
c.importAnyFile
c.open
c.readAtAutoNodes
c.readAtFileNodes
at.readAll
c.save
c.saveAs
c.saveTo
fc.writeAtFileNodes
fc.writeAtShadowNodes
fc.writeDirtyAtFileNodes
2. Disabled log messages in several of the above methods during unit
testing.
3. Disabled runOpenFileDialog and runSaveFileDialog during unit
testing.
QQQQQ
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.