#2668 <https://github.com/leo-editor/leo-editor/issues/2668> has passed 
by-hand tests. It should be completed later today.

I have just closed #2667 
<https://github.com/leo-editor/leo-editor/issues/2667> because no changes 
to Leo's documentation are needed!

*An excellent collaboration*

Viktor's testing was the essential first step. At first I thought that 
#2668 was a minor issue, but it isn't. Testing revealed that pip-installed 
Leo was missing the leo/test folder. execute-script requires this folder! 
And several unit tests require leo/test/test.leo.

Thomas suggested using g.__file__ to discover Leo's context. This was 
crucial!

I played around with adding the site-packages folder using 
sitecustomize.py, but then I realized that g.run_unit_tests could do this 
automatically.  Like this:

def run_unit_tests(tests: str=None, verbose: bool=False) -> None:
    """
    Run the unit tests given by the "tests" string.

    Run *all* unit tests if "tests" is not given.
    """
    if 'site-packages' in __file__:
        # Add site-packages to sys.path.
        parent_dir = g.os_path_finalize_join(g.app.loadDir, '..', '..')
        if parent_dir.endswith('site-packages'):
            if parent_dir not in sys.path:
                g.trace(f"Append {parent_dir!r} to sys.path")
                sys.path.append(parent_dir)
        else:
            g.trace('Can not happen: wrong parent directory', parent_dir)
            return
        # Run tests in site-packages/leo
        os.chdir(g.os_path_finalize_join(g.app.loadDir, '..'))
    else:
        # Run tests in leo-editor.
        os.chdir(g.os_path_finalize_join(g.app.loadDir, '..', '..'))
    verbosity = '-v' if verbose else ''
    command = f"{sys.executable} -m unittest {verbosity} {tests or ''} "
    g.execute_shell_commands(command)

*Summary*

#2668 is surprisingly important. Indeed, the very first thing we want to do 
after pip-installing Leo is to run the unit tests. Furthermore, #2668 
revealed serious errors in the distribution manifest.

Many thanks to Viktor and Thomas for their help.

Edward


-- 
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/c210cdc7-10b5-4b3b-a6da-c66841efd44bn%40googlegroups.com.

Reply via email to