Example #1
0
import unittest
import sys

from extras import safe_hasattr

from testtools import TextTestResult
from testtools.compat import classtypes, istext, unicode_output_stream
from testtools.testsuite import filter_by_ids, iterate_tests, sorted_tests

defaultTestLoader = unittest.defaultTestLoader
defaultTestLoaderCls = unittest.TestLoader

if getattr(defaultTestLoader, 'discover', None) is None:
    try:
        import discover
        defaultTestLoader = discover.DiscoveringTestLoader()
        defaultTestLoaderCls = discover.DiscoveringTestLoader
        have_discover = True
    except ImportError:
        have_discover = False
else:
    have_discover = True


def list_test(test):
    """Return the test ids that would be run if test() was run.

    When things fail to import they can be represented as well, though
    we use an ugly hack (see http://bugs.python.org/issue19746 for details)
    to determine that. The difference matters because if a user is
    filtering tests to run on the returned ids, a failed import can reduce
Example #2
0
def test_remotely(soffice, discover_dirs, extra_path, logconf_path):
    import sys
    import os
    import os.path
    import discover
    import oxt_tool.remote

    logger = logging.getLogger('unokit')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.INFO)

    logfmt = logging.Formatter(('frontend %5d ' % os.getpid())
                               +'%(message)s')
    logchn = logging.StreamHandler()
    logchn.setFormatter(logfmt)
    logger = logging.getLogger('frontend')
    logger.addHandler(logchn)
    logger.setLevel(logging.INFO)

    working_dir = sys.argv[1]
    working_dir = os.path.abspath(working_dir)

    for path in sys.path:
        logger.info('sys.path: %s', path)

    if logconf_path:
        logconf_path = os.path.abspath(logconf_path)

    backend_path = sys.modules['oxt_tool'].__file__
    backend_path = os.path.dirname(backend_path)
    backend_path = os.path.join(backend_path, 'backend.py')
    backend_name = 'backend.TestRunnerJob'

    tss = []
    for d in discover_dirs:
        d = os.path.abspath(d)
        logger.info('discover tests: %s', d)
        testloader = discover.DiscoveringTestLoader()
        testsuite = testloader.discover(d)
        tss.append(testsuite)
    import unittest
    testsuite = unittest.TestSuite(tss)

    with oxt_tool.remote.new_remote_context(soffice=soffice) as context:
        logger.info('remote context created')
        factory = load_component(backend_path, backend_name)
        if factory:
            backendjob = factory.createInstanceWithContext(context)
            if backendjob:
                import cPickle
                from unokit.adapters import OutputStreamToFileLike
                pickled_testsuite = cPickle.dumps(testsuite)
                outputstream = OutputStreamToFileLike(sys.stderr)
                logstream = OutputStreamToFileLike(sys.stderr)
                args = dict(outputstream=outputstream,
                            logstream=logstream,
                            pickled_testsuite=pickled_testsuite,
                            extra_path=tuple(extra_path),
                            logconf_path=logconf_path,
                            working_dir=working_dir)
                args = dict_to_namedvalue(args)
                result = backendjob.execute(args)
                result = str(result)
                result = cPickle.loads(result)
                return 0 if result['successful'] else 1
    return -1