def __init__(self): self.in_robot = Context.in_robot() self.formatter = logging.Formatter( '%(asctime)s - %(levelname)s - %(message)s') self.threshold_level_as_str = self.get_threshold_level_as_str() self.threshold_level_as_int = self.get_log_level_from_str( self.threshold_level_as_str) if self.in_robot: self.logger = robot.api.logger else: # Stream handler is attached from log() since # that must be decided at run-time, but here we might as well # do the setup to keep log() clean. self.stream_handler = logging.StreamHandler(sys.stdout) self.stream_handler.setFormatter(self.formatter) # We have to instantiate a logger to something and this is a global # logger so we name it by this class. Later in this class' # log method, we manipulate the msg string to include the calling # page class name. logger = logging.getLogger(self.__class__.__name__) logger.setLevel(self.threshold_level_as_int) fh = logging.FileHandler("po_log.txt", "w") fh.setLevel(self.threshold_level_as_int) fh.setFormatter(self.formatter) logger.addHandler(fh) self.logger = logger
def __init__(self): self.in_robot = Context.in_robot() self.formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') self.threshold_level_as_str = self.get_threshold_level_as_str() self.threshold_level_as_int = self.get_log_level_from_str(self.threshold_level_as_str) if self.in_robot: self.logger = robot.api.logger else: # Stream handler is attached from log() since # that must be decided at run-time, but here we might as well # do the setup to keep log() clean. self.stream_handler = logging.StreamHandler(sys.stdout) self.stream_handler.setFormatter(self.formatter) # We have to instantiate a logger to something and this is a global # logger so we name it by this class. Later in this class' # log method, we manipulate the msg string to include the calling # page class name. logger = logging.getLogger(self.__class__.__name__) logger.setLevel(self.threshold_level_as_int) fh = logging.FileHandler("po_log.txt", "w") fh.setLevel(self.threshold_level_as_int) fh.setFormatter(self.formatter) logger.addHandler(fh) self.logger = logger
def is_device_available(self): """ Succeeds if the test server is available for receiving commands. This is best used with the `Wait Until Keyword Succeeds` keyword from the BuiltIn library like this: Example: | Wait Until Keyword Succeeds | 1 minute | 10 seconds | Is device available | """ logger = logging.getLogger() previous_loglevel = logger.getEffectiveLevel() logger.setLevel(logging.ERROR) status_code = 0 try: resp = self._get('version') status_code = resp.status_code except: raise finally: logger.setLevel(previous_loglevel) assert status_code == 200, "Device is not available"
import dbus import dbus.mainloop.glib import time import subprocess if __name__ != '__main__': from robot.api import logger else: try: from console_logger import LOGGER as logger except ImportError: import logging logger = logging.getLogger('console_logger') logger.setLevel(logging.DEBUG) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) client = None # This cleanup handler is not used when this library is imported in RF, only when run as standalone if __name__ == '__main__': def cleanupAtExit(): """ Called when this program is terminated, to perform the same cleanup as expected in Teardown when run within Robotframework