Esempio n. 1
0
def lint(target_file,
         config_file,
         output,
         enable_disable_ids,
         msg_info,
         group="slidelint.pluggins"):
    """ main function that bring all thing together: loads slidelint pluggins,
    parses config file, handles command-line options, runs checkers and
    formats output.

    It takes:

        * target_file - path to pdf file or None
        * config_file - path to config file or None
        * output - it's a dict object for controlling results output:
            format - format of the output report, it's None
                     or one of [text', 'parseable', 'colorized',
                     'msvs', 'html'],
            files_output - file path, empty string or None, if empty
                           string than report will be
                           written to file otherwise printed to stdout,
            ids - if True then messages ids will be added to report
        * enable_disable_ids - command-line options for enabling/disabling
                               messages/checkers/categories, takes
        * msg_info -  ['list of messages ids,], None, or 'All' """
    pluggins = PlugginsHandler(group=group)
    config = LintConfig(config_file)
    config.compose(pluggins.checkers, *enable_disable_ids)
    if msg_info:
        # displaying help messages
        rezult = []
        for checker in pluggins.load_checkers():
            kwargs = {'msg_info': msg_info}
            kwargs.update(config.get_checker_args(checker.name))
            rezult += list(checker.check(**kwargs))
        msg_ids = []
        output['ids'] = True
    else:
        # run checkers
        # mute messaging from appearing in report
        msg_ids = config.disable_messages
        checkers = pluggins.load_checkers(
            categories=config.categories,
            checkers=config.checkers_ids,
            disabled_categories=config.disable_categories,
            disabled_checkers=config.disable_checkers)
        # lets run all checkers separately in different processes
        rezult = MultiprocessingManager()
        for checker in checkers:
            kwargs = {'target_file': target_file}
            kwargs.update(config.get_checker_args(checker.name))
            rezult.append(checker.check, kwargs)
    return output_handler(target_file, rezult, msg_ids, output['format'],
                          output['files_output'], output['ids'])
Esempio n. 2
0
def lint(target_file, config_file, output, enable_disable_ids,
         msg_info, group="slidelint.pluggins"):
    """ main function that bring all thing together: loads slidelint pluggins,
    parses config file, handles command-line options, runs checkers and
    formats output.

    It takes:

        * target_file - path to pdf file or None
        * config_file - path to config file or None
        * output - it's a dict object for controlling results output:
            format - format of the output report, it's None
                     or one of [text', 'parseable', 'colorized',
                     'msvs', 'html'],
            files_output - file path, empty string or None, if empty
                           string than report will be
                           written to file otherwise printed to stdout,
            ids - if True then messages ids will be added to report
        * enable_disable_ids - command-line options for enabling/disabling
                               messages/checkers/categories, takes
        * msg_info -  ['list of messages ids,], None, or 'All' """
    pluggins = PlugginsHandler(group=group)
    config = LintConfig(config_file)
    config.compose(pluggins.checkers, *enable_disable_ids)
    if msg_info:
        # displaying help messages
        rezult = []
        for checker in pluggins.load_checkers():
            kwargs = {'msg_info': msg_info}
            kwargs.update(config.get_checker_args(checker.name))
            rezult += list(checker.check(**kwargs))
        msg_ids = []
        output['ids'] = True
    else:
        # run checkers
        # mute messaging from appearing in report
        msg_ids = config.disable_messages
        checkers = pluggins.load_checkers(
            categories=config.categories,
            checkers=config.checkers_ids,
            disabled_categories=config.disable_categories,
            disabled_checkers=config.disable_checkers
        )
        # lets run all checkers separately in different processes
        rezult = MultiprocessingManager()
        for checker in checkers:
            kwargs = {'target_file': target_file}
            kwargs.update(config.get_checker_args(checker.name))
            rezult.append(checker.check, kwargs)
    return output_handler(target_file, rezult, msg_ids, output['format'],
                          output['files_output'], output['ids'])
Esempio n. 3
0
class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.handler = PlugginsHandler("")
        self.handler.checkers = ALL_ENTRIES

    def test_all_categiries(self):
        rez = self.handler.load_checkers()
        should_be = REZ_ENTRIES
        testfixtures.compare(rez, should_be)

    def test_enable_category(self):
        rez = self.handler.load_checkers(categories=['CategoryB', 'CategoryD'])
        should_be = REZ_ENTRIES[3:5] + [REZ_ENTRIES[6]]
        testfixtures.compare(rez, should_be)

    def test_disable_category(self):
        rez = self.handler.load_checkers(
            disabled_categories=['CategoryA', 'CategoryD'])
        should_be = REZ_ENTRIES[3:6]
        testfixtures.compare(rez, should_be)

    def test_enable_checker(self):
        rez = self.handler.load_checkers(
            disabled_categories=['AllCategories'],
            checkers=['checkera', 'checkere'])
        should_be = [REZ_ENTRIES[0], REZ_ENTRIES[4]]
        testfixtures.compare(rez, should_be)

    def test_disable_checker(self):
        rez = self.handler.load_checkers(
            disabled_checkers=['checkera', 'checkerf', 'checkerg'])
        should_be = REZ_ENTRIES[1:5]
        testfixtures.compare(rez, should_be)

    def test_mixed(self):
        rez = self.handler.load_checkers(
            categories=['CategoryA', 'CategoryB', 'CategoryD'],
            disabled_categories=['CategoryA'],
            checkers=['checkerb', 'checkerf'],
            disabled_checkers=['checkere', 'checkerg'])
        should_be = [REZ_ENTRIES[3], REZ_ENTRIES[1], REZ_ENTRIES[5]]
        testfixtures.compare(rez, should_be)
Esempio n. 4
0
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.handler = PlugginsHandler("")
        self.handler.checkers = ALL_ENTRIES

    def test_all_categiries(self):
        rez = self.handler.load_checkers()
        should_be = REZ_ENTRIES
        testfixtures.compare(rez, should_be)

    def test_enable_category(self):
        rez = self.handler.load_checkers(categories=['CategoryB', 'CategoryD'])
        should_be = REZ_ENTRIES[3:5] + [REZ_ENTRIES[6]]
        testfixtures.compare(rez, should_be)

    def test_disable_category(self):
        rez = self.handler.load_checkers(
            disabled_categories=['CategoryA', 'CategoryD'])
        should_be = REZ_ENTRIES[3:6]
        testfixtures.compare(rez, should_be)

    def test_enable_checker(self):
        rez = self.handler.load_checkers(disabled_categories=['AllCategories'],
                                         checkers=['checkera', 'checkere'])
        should_be = [REZ_ENTRIES[0], REZ_ENTRIES[4]]
        testfixtures.compare(rez, should_be)

    def test_disable_checker(self):
        rez = self.handler.load_checkers(
            disabled_checkers=['checkera', 'checkerf', 'checkerg'])
        should_be = REZ_ENTRIES[1:5]
        testfixtures.compare(rez, should_be)

    def test_mixed(self):
        rez = self.handler.load_checkers(
            categories=['CategoryA', 'CategoryB', 'CategoryD'],
            disabled_categories=['CategoryA'],
            checkers=['checkerb', 'checkerf'],
            disabled_checkers=['checkere', 'checkerg'])
        should_be = [REZ_ENTRIES[3], REZ_ENTRIES[1], REZ_ENTRIES[5]]
        testfixtures.compare(rez, should_be)