Ejemplo n.º 1
0
    def assert_log_config_load(self,
                               log_file,
                               exp_log_file,
                               log_level,
                               exp_log_level,
                               write_abs_path=False):

        with TestAreaContext("log_config_test") as work_area:
            work_area.copy_directory(self.case_directory)

            # Append config file
            with open(self.config_file, 'a') as cf:
                if log_file:
                    if write_abs_path:
                        log_file = os.path.join(
                            os.path.abspath(
                                os.path.split(self.config_file)[0]), log_file)

                    cf.write("\nLOG_FILE %s\n" % log_file)

                if log_level:
                    level = log_level
                    if sys.version_info[0] >= 3:
                        if not log_level.isalpha():
                            level = int(float(level))
                    cf.write("\nLOG_LEVEL %s\n" % level)

            log_config = LogConfig(self.config_file)

            self.assertTrue(os.path.isabs(log_config.log_file))

            self.assertEqual(os.path.normpath(log_config.log_file),
                             os.path.normpath(os.path.abspath(exp_log_file)))

            if isinstance(log_config.log_level, int):
                level = MessageLevelEnum.to_enum(log_config.log_level)
            else:
                level = log_config.log_level

            self.assertEqual(level, exp_log_level)
Ejemplo n.º 2
0
 def log(cls, log_level, message):
     """ Higher log_level indicates higher importance"""
     cls._write_log(MessageLevelEnum.to_enum(log_level), message)
Ejemplo n.º 3
0
 def init(cls, log_level, log_filename, verbose):
     if not cls._init(MessageLevelEnum.to_enum(log_level), log_filename,
                      verbose):
         raise IOError("Failed to open log handle for file:%s" %
                       log_filename)
Ejemplo n.º 4
0
 def init(cls, log_level, log_filename, verbose):
     cls._init(MessageLevelEnum.to_enum(log_level), log_filename, verbose)
Ejemplo n.º 5
0
    def assert_log_config_load(self,
                               log_file,
                               exp_log_file,
                               log_level,
                               exp_log_level,
                               write_abs_path=False):

        with TestAreaContext("log_config_test") as work_area:
            work_area.copy_directory(self.case_directory)

            config_dict = {}
            # Append config file
            with open(self.config_file, 'a') as cf:
                if log_file:
                    config_dict[ConfigKeys.LOG_FILE] = os.path.realpath(
                        os.path.join(
                            os.path.abspath(
                                os.path.split(self.config_file)[0]), log_file))

                    if write_abs_path:
                        log_file = config_dict[ConfigKeys.LOG_FILE]

                    cf.write("\nLOG_FILE %s\n" % log_file)

                else:
                    config_dict[ConfigKeys.LOG_FILE] = os.path.realpath(
                        os.path.join(
                            os.path.abspath(
                                os.path.split(self.config_file)[0]),
                            "log.txt"))

                if log_level:
                    level = log_level
                    if sys.version_info[0] >= 3:
                        if not log_level.isalpha():
                            level = int(float(level))
                    cf.write("\nLOG_LEVEL %s\n" % level)
                    if type(level) is str and level.isdigit():
                        config_dict[
                            ConfigKeys.LOG_LEVEL] = MessageLevelEnum.to_enum(
                                eval(level))
                    elif type(level) is str:
                        config_dict[ConfigKeys.
                                    LOG_LEVEL] = MessageLevelEnum.from_string(
                                        "LOG_" + level)
                    else:
                        config_dict[
                            ConfigKeys.LOG_LEVEL] = MessageLevelEnum.to_enum(
                                level)
                else:
                    config_dict[
                        ConfigKeys.LOG_LEVEL] = MessageLevelEnum.LOG_WARNING

            log_config = LogConfig(user_config_file=self.config_file)
            res_config = ResConfig(self.config_file)
            log_config_dict = LogConfig(config_dict=config_dict)
            self.assertEqual(log_config, log_config_dict)
            self.assertEqual(log_config, res_config.log_config)

            self.assertTrue(os.path.isabs(log_config.log_file))

            self.assertEqual(os.path.normpath(log_config.log_file),
                             os.path.normpath(os.path.abspath(exp_log_file)))

            if isinstance(log_config.log_level, int):
                level = MessageLevelEnum.to_enum(log_config.log_level)
            else:
                level = log_config.log_level

            self.assertEqual(level, exp_log_level)