On Mon, Nov 12, 2012 at 6:24 AM, Edward K. Ream <[email protected]> wrote:

> This kind of Leo hack must be removed asap: we can't assume that most people 
> who are interested in stc will use Leo!

Never mind.  I'm going to leave @testclass as it is.

After I wrote the original (confused) post, I realized that stc unit
testing code can't use *any* Leo tricks, so I may as well use a
completely standard organization, namely external unit-testing files.

The following Leo script, run from statictypechecking.leo, will run
all files in the "test" directory::

    import imp
    import glob
    import unittest

    if c.isChanged():
        c.save()

    test_dir = g.os_path_finalize_join(
        g.os_path_dirname(c.fileName()),'test')
    assert g.os_path_exists(test_dir),test_dir
    pattern = g.os_path_finalize_join(test_dir,'*.py')

    for fn in glob.glob(pattern):
        module_fn = g.shortFileName(fn[:-3])
        try:
            file_ = None
            file_,pathname,description = imp.find_module(
                module_fn,[test_dir])
            module = imp.load_module(
                module_fn,file_,pathname, description)
                # equivalent to imp.reload
            suite = unittest.TestLoader().\
                loadTestsFromModule(module)
            unittest.TextTestRunner(verbosity=1).run(suite)
        finally:
            if file_: file_.close()

No, this isn't as flexible as selecting the desired @test trees, but I
can simulate that by moving code into and out of the test directory.
Furthermore, I can use standard unittest filters to select desired
tests as well.  In short, this is a reasonable start.

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.

Reply via email to