It *is* possible to run unit tests from pip-installed Leo

10 views
Skip to first unread message

Edward K. Ream

unread,
May 23, 2022, 7:58:50 AM5/23/22
to leo-editor
#2668 has passed by-hand tests. It should be completed later today.

I have just closed #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


Viktor Ransmayr

unread,
May 23, 2022, 2:42:03 PM5/23/22
to leo-e...@googlegroups.com
Hello Edward,

Am Mo., 23. Mai 2022 um 13:58 Uhr schrieb Edward K. Ream <edre...@gmail.com>:
#2668 has passed by-hand tests. It should be completed later today.

Looking forward to test #2668,  once it's available,  in all environments available to me ...

I'm happy, that I was able to provide the initial trigger for this improvement - and - more importantly, I'd like to thank Thomas for making the initial suggestion for it to you !

With kind regards,

Viktor

Reply all
Reply to author
Forward
0 new messages