def flushThreadLog(threadList):
    #global threadDict
    #global logThreadLock
    currentThread = threading.currentThread()
    for thread in threadList:
        if thread == currentThread:
            continue
        elif currentThread.getName() not in LOGGING_THREADS:
            for msg in threadDict[thread]['msgList']:
                logThreadLock.acquire()
                debug('flushThreadLog - lock acquired by thread %s' %
                      thread.threadId,
                      level=const.LEVEL4)
                try:
                    threadDict[currentThread]['msgList'].append(msg)
                except:
                    sys.__stdout__.write(sys.exc_info())
                    logThreadLock.release()
                    debug('flushThreadLog - lock released by thread %s' %
                          thread.threadId,
                          level=const.LEVEL4)
                logThreadLock.release()
                debug('flushThreadLog - lock released by thread %s' %
                      thread.threadId,
                      level=const.LEVEL4)
            threadDict.pop(thread, None)
        else:
            for msg in threadDict[thread]['msgList']:
                LOGGER.log_message(msg)
            threadDict.pop(thread, None)
Exemple #2
0
 def write(self, msg, level, html=False):
     with self.lock:
         thread = threading.currentThread().getName()
         if thread in self.LOGGING_THREADS:
             LOGGER.log_message(Message(msg, level, html))
         else:
             message = Message(msg, level, html)
             self._messages.setdefault(thread, []).append(message)
def debug(msg, html=True, timestamp=None, level=0):
    currentThread = threading.currentThread()
    if currentThread.getName() in LOGGING_THREADS:
        if level <= debugLogLevel:
            logMsg = Message(msg, 'DEBUG', html, timestamp=timestamp)
            LOGGER.log_message(logMsg)
    else:
        if level <= debugLogLevel:
            logMsg = Message(msg,'DEBUG',html,timestamp=timestamp)
            if currentThread in threadDict:
                threadDict[currentThread]['msgList'].append(logMsg)
            else:
                threadDict[currentThread]['msgList'] = []
                threadDict[currentThread]['msgList'].append(logMsg)
def debug(msg, html=True, timestamp=None, level=0):
    currentThread = threading.currentThread()
    if currentThread.getName() in LOGGING_THREADS:
        if level <= debugLogLevel:
            logMsg = Message(msg, 'DEBUG', html, timestamp=timestamp)
            LOGGER.log_message(logMsg)
    else:
        if level <= debugLogLevel:
            logMsg = Message(msg, 'DEBUG', html, timestamp=timestamp)
            if currentThread in threadDict:
                threadDict[currentThread]['msgList'].append(logMsg)
            else:
                threadDict[currentThread]['msgList'] = []
                threadDict[currentThread]['msgList'].append(logMsg)
def info(msg, html=False, also_console=True,timestamp=None):
    currentThread = threading.currentThread()
    if currentThread.getName() in LOGGING_THREADS:
        logMsg = Message(msg, 'INFO', html, timestamp=timestamp)
        LOGGER.log_message(logMsg)
        if also_console:
            sys.__stdout__.write('\n %s' %(msg))
    else:
        if also_console:
             sys.__stdout__.write("\n%s" %(msg))
        logMsg = Message(msg,'INFO',html,timestamp=timestamp)
        if currentThread in threadDict:
            threadDict[currentThread]['msgList'].append(logMsg)
        else:
            threadDict[currentThread]['msgList'] = []
            threadDict[currentThread]['msgList'].append(logMsg)
def info(msg, html=False, also_console=True, timestamp=None):
    currentThread = threading.currentThread()
    if currentThread.getName() in LOGGING_THREADS:
        logMsg = Message(msg, 'INFO', html, timestamp=timestamp)
        LOGGER.log_message(logMsg)
        if also_console:
            sys.__stdout__.write('\n %s' % (msg))
    else:
        if also_console:
            sys.__stdout__.write("\n%s" % (msg))
        logMsg = Message(msg, 'INFO', html, timestamp=timestamp)
        if currentThread in threadDict:
            threadDict[currentThread]['msgList'].append(logMsg)
        else:
            threadDict[currentThread]['msgList'] = []
            threadDict[currentThread]['msgList'].append(logMsg)
Exemple #7
0
def details(msg, html=True, also_console=True, timestamp=None):
    current_thread = threading.currentThread()
    if current_thread.getName() in LOGGING_THREADS:
        log_msg = Message(msg, 'INFO', html, timestamp=timestamp)
        LOGGER.log_message(log_msg)
        if also_console:
            sys.__stdout__.write('\n\x1b[5;36mINFO          : %s\x1b[0m' % msg)
    else:
        if also_console:
            sys.__stdout__.write("\n%s" % msg)
        log_msg = Message(msg, 'INFO', html, timestamp=timestamp)
        if current_thread in threadDict:
            threadDict[current_thread]['msg_list'].append(log_msg)
        else:
            threadDict[current_thread]['msg_list'] = []
            threadDict[current_thread]['msg_list'].append(log_msg)
Exemple #8
0
def fail(msg, html=True, also_console=True, timestamp=None):
    font_tag = '<font color=\"red\"><b> FAIL: '
    font_end_tag = '</b></font>'
    failmsg = "%s %s %s" % (font_tag, msg, font_end_tag)
    current_thread = threading.currentThread()
    sys.__stdout__.write('\n\x1b[38;5;1mFAIL: %s\x1b[0m' % msg)
    if current_thread.getName() in LOGGING_THREADS:
        log_msg = Message(failmsg, 'FAIL', html, timestamp=timestamp)
        LOGGER.log_message(log_msg)
        if also_console:
            sys.__stdout__.write('\n %s' % msg)
    else:
        if also_console:
            sys.__stdout__.write("\n%s" % msg)
        log_msg = Message(msg, 'FAIL', html, timestamp=timestamp)
        if current_thread in threadDict:
            threadDict[current_thread]['msg_list'].append(log_msg)
        else:
            threadDict[current_thread]['msg_list'] = []
            threadDict[current_thread]['msg_list'].append(log_msg)
def flushThreadLog(threadList):
    #global threadDict
    #global logThreadLock
    currentThread = threading.currentThread()
    for thread in threadList:
        if thread == currentThread:
            continue
        elif currentThread.getName() not in LOGGING_THREADS:
            for msg in threadDict[thread]['msgList']:
                logThreadLock.acquire()
                debug('flushThreadLog - lock acquired by thread %s' %thread.threadId, level=const.LEVEL4)
                try:
                    threadDict[currentThread]['msgList'].append(msg)
                except:
                    sys.__stdout__.write(sys.exc_info())
                    logThreadLock.release()
                    debug('flushThreadLog - lock released by thread %s' %thread.threadId, level=const.LEVEL4)
                logThreadLock.release()
                debug('flushThreadLog - lock released by thread %s' %thread.threadId, level=const.LEVEL4)
            threadDict.pop(thread, None)
        else:
            for msg in threadDict[thread]['msgList']:
                LOGGER.log_message(msg)
            threadDict.pop(thread, None)
Exemple #10
0
import logging
import re

from robot import run
from robot.api import TestSuite, get_model
from robot.errors import DataError
from robot.output.logger import LOGGER

from avocado.core import output, test
from avocado.core.nrunner import Runnable
from avocado.core.plugin_interfaces import CLI, Resolver
from avocado.core.resolver import (ReferenceResolution,
                                   ReferenceResolutionResult, check_file)

LOGGER.unregister_console_logger()


def find_tests(reference, test_suite):

    model = get_model(reference)
    data = TestSuite.from_model(model)

    test_suite[data.name] = []
    for test_case in data.tests:
        test_suite[data.name].append({'test_name': test_case,
                                      'test_source': data.source})
    for child_data in data.suites:
        find_tests(child_data, test_suite)
    return test_suite
Exemple #11
0
try:
    from robot.common import UserErrorHandler
    from robot.common.model import BaseTestSuite
    from robot.running import TestSuite
    from robot.running.model import RunnableTestSuite, RunnableTestCase
    from robot.conf import RobotSettings
    from robot.running.namespace import Namespace
    from robot.utils import (ArgumentParser, get_timestamp, normalize,
                            elapsed_time_to_string, eq, normalize_tags,
                            unescape, get_elapsed_time)
    from robot import version
    ROBOT_VERSION = version.get_version()
    from robot.errors import DataError, Information
    from robot.output.logger import LOGGER
    LOGGER.disable_automatic_console_logger()
except ImportError, error:
    print """All needed Robot modules could not be imported.
Check your Robot installation."""
    print "Error was: %s" % (error)
    raise error


def XmlTestSuite(suite):
    if ROBOT_VERSION < '2.7':
        from robot.output import TestSuite
        return TestSuite(suite)
    from robot.result import ExecutionResult
    return ExecutionResult(suite).suite

def RobotTestOutput(suite):
 def wrapped_f(q, *args):
     ''' Calls the decorated function and puts the result in a queue '''
     LOGGER.unregister_xml_logger()
     ret = BuiltIn().run_keyword(keyword, *args)
     q.put(ret)
Exemple #13
0
import logging
import re

from avocado.core import loader
from avocado.core import output
from avocado.core import test
from avocado.core.plugin_interfaces import CLI
from robot import run
from robot.errors import DataError
from robot.parsing.model import TestData
from robot.model import SuiteNamePatterns
from robot.output.logger import LOGGER


LOGGER.unregister_console_logger()


class RobotTest(test.SimpleTest):

    """
    Run a Robot command as a SIMPLE test.
    """

    def __init__(self,
                 name,
                 params=None,
                 base_logdir=None,
                 job=None,
                 executable=None):
        super(RobotTest, self).__init__(name, params, base_logdir, job,
Exemple #14
0
 def emit(self, record):
     message = self.format(record)
     level = MAP.get(record.levelname, record.levelname)
     LOGGER.log_message(Message(message, level, False))
Exemple #15
0
 def _log_all_messages(self):
     for thread in list(self._messages):
         # Only way to get custom timestamps currently is with print
         print("*HTML* <b>Messages by '%s'</b>" % thread)
         for message in self._messages.pop(thread):
             LOGGER.log_message(message)
Exemple #16
0
 def _log_messages_by_thread(self, name, html=False):
     msg = 'Run Thread %s' % name
     LOGGER.log_message(Message(msg, 'INFO', html))
     for message in self._messages.pop(name, []):
         LOGGER.log_message(message)