コード例 #1
0
ファイル: standard_formatters.py プロジェクト: tkruse/unilint
def register_standard_formatters():
    '''3 simple formatting functions'''

    def print_brief(unused_options, issue_list, basepath):
        'prints relpath, location, message'
        if issue_list is None:
            return
        for issue in issue_list:
            issuepath = issue.path or basepath
            if basepath != issuepath:
                loc_str = os.path.relpath(issuepath, basepath)
            else:
                loc_str = issuepath
            location = ("%s :%s:%s:" %
                        (loc_str,
                         str(issue.line_number_start or '').ljust(3),
                         str(issue.line_position or '').ljust(3)))
            location = location.ljust(20)
            sys.stdout.write("%s   %s\n" % (location, issue.message))

    def print_full(unused_options, issue_list, basepath):
        'prints all issue information'
        print_formatted('[$C\t$S\t$T]$F:$L:$P:\t$M', issue_list, basepath)

    def print_short(unused_options, issue_list, basepath):
        'prints filename, line and message'
        print_formatted('$f:$L: $M', issue_list, basepath)

    register_formatter('brief', print_brief)
    register_formatter('full', print_full)
    register_formatter('short', print_short)
コード例 #2
0
ファイル: test_unilint_main.py プロジェクト: tkruse/unilint
 def test_register_formatter(self):
     def foo_fun():
         pass
     register_formatter('foo', foo_fun)
     self.assertTrue('foo' in FORMATTERS)
     self.assertEqual(foo_fun, FORMATTERS['foo'])