当前位置: 首页>>代码示例>>Python>>正文


Python LogPrinter.info方法代码示例

本文整理汇总了Python中coalib.output.printers.LogPrinter.LogPrinter.info方法的典型用法代码示例。如果您正苦于以下问题:Python LogPrinter.info方法的具体用法?Python LogPrinter.info怎么用?Python LogPrinter.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coalib.output.printers.LogPrinter.LogPrinter的用法示例。


在下文中一共展示了LogPrinter.info方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_logging

# 需要导入模块: from coalib.output.printers.LogPrinter import LogPrinter [as 别名]
# 或者: from coalib.output.printers.LogPrinter.LogPrinter import info [as 别名]
    def test_logging(self):
        uut = LogPrinter(StringPrinter(), timestamp_format="")
        uut.log_message(self.log_message, end="")
        self.assertEqual(uut.printer.string, str(self.log_message))

        uut = LogPrinter(StringPrinter(), log_level=LOG_LEVEL.DEBUG)
        uut.log_message(self.log_message, end="")
        self.assertEqual(
            uut.printer.string,
            "[ERROR][" + self.timestamp.strftime("%X") + "] " +
            Constants.COMPLEX_TEST_STRING)

        uut.printer.clear()
        uut.log(LOG_LEVEL.ERROR,
                Constants.COMPLEX_TEST_STRING,
                timestamp=self.timestamp,
                end="")
        self.assertEqual(
            uut.printer.string,
            "[ERROR][" + self.timestamp.strftime("%X") + "] " +
            Constants.COMPLEX_TEST_STRING)

        uut.printer.clear()
        uut.debug(Constants.COMPLEX_TEST_STRING,
                  "d",
                  timestamp=self.timestamp,
                  end="")
        self.assertEqual(
            uut.printer.string,
            "[DEBUG][" + self.timestamp.strftime("%X") + "] " +
            Constants.COMPLEX_TEST_STRING + " d")

        uut.printer.clear()
        uut.log_level = LOG_LEVEL.INFO
        uut.debug(Constants.COMPLEX_TEST_STRING,
                  timestamp=self.timestamp,
                  end="")
        self.assertEqual(uut.printer.string, "")

        uut.printer.clear()
        uut.info(Constants.COMPLEX_TEST_STRING,
                 "d",
                 timestamp=self.timestamp,
                 end="")
        self.assertEqual(
            uut.printer.string,
            "[INFO][" + self.timestamp.strftime("%X") + "] " +
            Constants.COMPLEX_TEST_STRING + " d")

        uut.log_level = LOG_LEVEL.WARNING
        uut.printer.clear()
        uut.debug(Constants.COMPLEX_TEST_STRING,
                  timestamp=self.timestamp,
                  end="")
        self.assertEqual(uut.printer.string, "")

        uut.printer.clear()
        uut.warn(Constants.COMPLEX_TEST_STRING,
                 "d",
                 timestamp=self.timestamp,
                 end="")
        self.assertEqual(
            uut.printer.string,
            "[WARNING][" + self.timestamp.strftime("%X") + "] " +
            Constants.COMPLEX_TEST_STRING + " d")

        uut.printer.clear()
        uut.err(Constants.COMPLEX_TEST_STRING,
                "d",
                timestamp=self.timestamp,
                end="")
        self.assertEqual(
            uut.printer.string,
            "[ERROR][" + self.timestamp.strftime("%X") + "] " +
            Constants.COMPLEX_TEST_STRING + " d")

        uut.log_level = LOG_LEVEL.DEBUG
        uut.printer.clear()
        uut.log_exception(
            "Something failed.",
            NotImplementedError(Constants.COMPLEX_TEST_STRING),
            timestamp=self.timestamp)
        self.assertTrue(uut.printer.string.startswith(
            "[ERROR][" + self.timestamp.strftime("%X") +
            "] Something failed.\n" +
            "[DEBUG][" + self.timestamp.strftime("%X") +
            "] Exception was:"))

        uut.log_level = LOG_LEVEL.INFO
        uut.printer.clear()
        logged = uut.log_exception(
            "Something failed.",
            NotImplementedError(Constants.COMPLEX_TEST_STRING),
            timestamp=self.timestamp,
            end="")
        self.assertTrue(uut.printer.string.startswith(
            "[ERROR][" + self.timestamp.strftime("%X") +
            "] Something failed."))
开发者ID:AbdealiJK,项目名称:coala,代码行数:100,代码来源:LogPrinterTest.py

示例2: CoalaViewActivatable

# 需要导入模块: from coalib.output.printers.LogPrinter import LogPrinter [as 别名]
# 或者: from coalib.output.printers.LogPrinter.LogPrinter import info [as 别名]
class CoalaViewActivatable(GObject.Object, Gedit.ViewActivatable):
    """
    A class inherited from Gedit.ViewActivatable - it gets created for every
    gedit view. This class has a property `view` which is the Gedit.View that
    the class is related to. From the Gedit.View, the Gedit.Document associated
    to it can be got using `view.get_buffer()`.
    """
    __gtype_name__ = "CoalaViewActivatable"

    view = GObject.Property(type=Gedit.View)

    def __init__(self):
        GObject.Object.__init__(self)
        self.log_printer = LogPrinter(ConsolePrinter())

    def do_activate(self):
        """
        This function is called when the view is created - it will
        be called only once in a lifetime of a view.
        """
        self.register_marks()
        self.view.get_buffer().connect("saved", lambda x: self.analyze())

    def register_marks(self):
        """
        Creates mark-attributes for all result severities.
        """
        self.view.set_show_line_marks(True)
        for name, val in RESULT_SEVERITY.str_dict.items():
            attr = GtkSource.MarkAttributes()
            attr.set_icon_name(RESULT_SEVERITY_ICONS[val])
            attr.connect("query_tooltip_markup", self.show_mark_tooltip)
            self.view.set_mark_attributes(get_mark_category(name), attr, 0)
            self.log_printer.info("Mark attribute created for", name)

    def show_mark_tooltip(self, mark_attr, mark):
        result = getattr(mark, COALA_KEY + "Result")
        return str(result.origin) + ": " + str(result.message)

    def show_result(self, result):
        """
        Takes a result and shows it in gedit's UI.

        :param result: The result to display.
        """
        document = self.view.get_buffer()

        for sourcerange in result.affected_code:

            _iter = document.get_iter_at_line(sourcerange.start.line-1)
            mark = document.create_source_mark(
                None,
                get_mark_category(result.severity),
                _iter)
            setattr(mark, COALA_KEY + "Result", result)
            self.log_printer.info("Created mark at", sourcerange.start.line)

    def analyze(self):
        """
        This function fetches the location of the file in this view
        and runs coala on it.
        """
        document = self.view.get_buffer()
        location = document.get_location()
        if location == None:
            self.log_printer.warn("coala cannot run on unsaved files")
            return

        results = CoalaViewActivatable.run_coala(location.get_path())

        document.remove_source_marks(document.get_start_iter(),
                                     document.get_end_iter())
        for section_results in results.values():
            for result in section_results:
                self.show_result(result)

    @staticmethod
    def run_coala(path):
        """
        Run coala on the file at the given path. The config file is got using
        the `find-config` option of coala.

        :param path: The path of the file to analyze.
        :return:     The result dictionary from coala.
        """
        results = {}
        log_printer = LogPrinter(ConsolePrinter())
        cwd = os.getcwd()
        try:
            os.chdir(os.path.dirname(path))
            args = ["--find-config", "--limit-files", path, '-S',
                    'autoapply=false']
            sections, local_bears, global_bears, targets = (
                # Use `lambda *args: True` so that `gather_configuration` does
                # nothing when it needs to request settings from user.
                gather_configuration(lambda *args: True,
                                     log_printer,
                                     arg_list=args))

            for section_name in sections:
#.........这里部分代码省略.........
开发者ID:Asnelchristian,项目名称:coala-gedit,代码行数:103,代码来源:CoalaViewActivatable.py


注:本文中的coalib.output.printers.LogPrinter.LogPrinter.info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。