Esempio n. 1
0
def tf_launch(prefix, cleanup_tests = None):
    if len(sys.argv) == 1 and sys.argv[0] == '':
        return
    sname = sys.argv[0]
    pname = re.sub('.py$', '', sname)
    if sname.endswith('.py') and not os.path.exists(pname):
        print("creating symlink: %s -> %s" % (pname, sname))
        os.symlink(sname, pname)
    elif sys._getframe(1).f_code.co_name in ['?', '<module>']:
        if sname.endswith('.py'):
            testhelp.main(sys.argv)
            if None != cleanup_tests:
                cleanup_tests()
        else:
            tf_main(sys.argv, prefix=prefix)
Esempio n. 2
0
def ez_launch(modname,
              main=None,
              setup=None,
              cleanup=None,
              test=None,
              logfile=''):
    """
    For a simple (non-tool-style) program, figure out what needs to happen and
    call the invoker's 'main' callback.
    """
    if len(sys.argv) == 1 and sys.argv[0] == '':
        return
    if modname != '__main__':
        return
    sname = sys.argv[0]
    pname = re.sub('.py$', '', sname)
    if (sname.endswith('.py') and
            not os.path.exists(pname) and '-L' in sys.argv):
        print("creating symlink: %s -> %s" % (pname, sname))
        os.symlink(sname, pname)
    elif sys._getframe(1).f_code.co_name in ['?', '<module>']:
        if sname.endswith('.py'):
            if '-d' in sys.argv:
                sys.argv.remove('-d')
                pdb.set_trace()
            if test is None:
                unittest.main()
            else:
                if setup is not None:
                    setup()
                keep = testhelp.main(sys.argv, test, logfile=logfile)
                if not keep and cleanup is not None:
                    cleanup()
        elif main is not None:
            main(sys.argv)
Esempio n. 3
0
def tf_launch(prefix, noarg='help', cleanup_tests=None, testclass='',
              logfile=''):
    """
    Launch a toolframe'd program
    """
    if len(sys.argv) == 1 and sys.argv[0] == '':
        return
    sname = sys.argv[0]
    pname = re.sub('.py$', '', sname)
    if sname.endswith('.py') and not os.path.exists(pname):
        print("creating symlink: %s -> %s" % (pname, sname))
        os.symlink(sname, pname)
    elif sys._getframe(1).f_code.co_name in ['?', '<module>']:
        if sname.endswith('.py'):
            keep = testhelp.main(sys.argv, testclass, logfile=logfile)
            if not keep and cleanup_tests is not None:
                cleanup_tests()
        else:
            tf_main(sys.argv, prefix=prefix, noarg=noarg)
Esempio n. 4
0
# ---------------------------------------------------------------------------
def tpb_cleanup_tests():
    global testdir
    if os.path.basename(os.getcwd()) == testdir:
        os.chdir('..')
    if os.path.isdir(testdir):
        rmrf(testdir)
        
# ---------------------------------------------------------------------------
class TpbtoolsTest(unittest.TestCase):
    # -----------------------------------------------------------------------
    def setUp(self):
        global testdir
        testdir = testhelp.into_test_dir()
        
    # -----------------------------------------------------------------------
    def test_expand(self):
        home = os.environ['HOME']
        logname = os.environ['LOGNAME']
        
        assert(expand('$HOME') == home)
        assert(expand('~') == home)
        assert(expand('~%s' % logname) == home)
        assert(expand('### $PYTHONPATH ###')
               == '### %s ###' % os.environ['PYTHONPATH'])
        
# ---------------------------------------------------------------------------
if __name__ == '__main__':
    if not testhelp.main(sys.argv):
        tpb_cleanup_tests()