Hello Edward,

Edward K. Ream schrieb am Samstag, 13. Februar 2021 um 13:58:26 UTC+1:

> This Engineering Notebook post shows the workflows I use to unit tests for 
> leoserver.py. I won't say much about the unit tests themselves. If you are 
> interested in the details, see the TestLeoServer class in leoserver.py and 
> the _get_action_list function in leoserver.py.
>
> *The big Aha*
>
> Unit tests must run *in the server*. Running unit tests from the client 
> doesn't work. Just run unit tests on leoserver.py, as with any other python 
> file.
>
> No, such tests won't test the actual communication code. For that we need 
> to run leoclient.py.  I use # pragma: no cover to tell coverage.py that 
> we don't need to cover comm-related code.
>
> *Three driver scripts*
>
> Whenever I change leoserver.py or leoclient.py, I run three tests, bound 
> to Ctrl-4, Ctrl-5, and Ctrl-6. I run them in this order until all tests 
> pass and coverage is 100%.
>
> *@command run-server @key=Ctrl-4*
>
> g.cls()
> import time
> if c.changed:
>     c.save()
> g.execute_shell_commands('start cmd /k "python leoserver.py"')
> time.sleep(0.5)
> g.execute_shell_commands('start cmd /k "python leoclient.py"')
>
> This Leo script runs the client and server in two processes, each distinct 
> from Leo. This script *does* test the communication between client and 
> server. I always run this script first.
>
> The commands shown above work only on Windows.  If you like, you can 
> easily modify them to work on other platforms.
>

Is there a specific reason, why you make it Windows specific here - and - 
don't use the same generic variant, that you use below for '@command 
unit-test ...'?

I did not try it out myself yet - but -

g.cls()
import time
if c.changed:
    c.save()
g.execute_shell_commands('python -m leo.core.leoserver')
time.sleep(0.5)
g.execute_shell_commands('python -m leo.core.leoclient')

should work in a portable way ...

*@command unit-test @key=Ctrl-5*
>
> """Run unittest on leoserver.py: good for debugging."""
> g.cls()
> import os
> if c.changed:
>     c.save()
> prolog = "python -m pytest --cov-report html --cov-report term-missing 
> --cov "
> os.chdir(os.path.join(g.app.loadDir, '..', '..'))
> # leoserver.main detects and removes the --unittest command-line arg.
> g.execute_shell_commands('python -m leo.core.leoserver --unittest')
>
> Next, I run this script. The script runs all unit tests in the 
> TestLeoServer class using python's unittest module. I prefer to do this 
> before running coverage tests so I can see all output.
>

With kind regards,

Viktor

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/450c5d32-5cd4-4512-b54d-79ffe9c83be8n%40googlegroups.com.

Reply via email to