本文整理汇总了Python中pylint.lint.PyLinter.error_mode方法的典型用法代码示例。如果您正苦于以下问题:Python PyLinter.error_mode方法的具体用法?Python PyLinter.error_mode怎么用?Python PyLinter.error_mode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylint.lint.PyLinter
的用法示例。
在下文中一共展示了PyLinter.error_mode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import error_mode [as 别名]
#.........这里部分代码省略.........
self.assertTrue(':C0112 (empty-docstring): *Empty %s docstring*' in output)
def test_lint_ext_module_with_file_output(self):
self.linter.set_reporter(text.TextReporter())
if sys.version_info < (3, 0):
strio = 'StringIO'
else:
strio = 'io'
self.linter.config.files_output = True
pylint_strio = 'pylint_%s.txt' % strio
try:
self.linter.check(strio)
self.assertTrue(os.path.exists(pylint_strio))
self.assertTrue(os.path.exists('pylint_global.txt'))
finally:
try:
os.remove(pylint_strio)
os.remove('pylint_global.txt')
except:
pass
def test_enable_report(self):
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
self.linter.disable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), False)
self.linter.enable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
def test_report_output_format_aliased(self):
text.register(self.linter)
self.linter.set_option('output-format', 'text')
self.assertEqual(self.linter.reporter.__class__.__name__, 'TextReporter')
def test_report_output_format_custom(self):
this_module = sys.modules[__name__]
class TestReporter(object):
pass
this_module.TestReporter = TestReporter
class_name = ".".join((this_module.__name__, 'TestReporter'))
self.linter.set_option('output-format', class_name)
self.assertEqual(self.linter.reporter.__class__.__name__, 'TestReporter')
def test_set_option_1(self):
linter = self.linter
linter.set_option('disable', 'C0111,W0142')
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0142'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('star-args'))
# no name for W0113
def test_set_option_2(self):
linter = self.linter
linter.set_option('disable', ('C0111', 'W0142') )
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0142'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('star-args'))
# no name for W0113
def test_enable_checkers(self):
self.linter.disable('design')
self.assertFalse('design' in [c.name for c in self.linter.prepare_checkers()])
self.linter.enable('design')
self.assertTrue('design' in [c.name for c in self.linter.prepare_checkers()])
def test_errors_only(self):
linter = self.linter
self.linter.error_mode()
checkers = self.linter.prepare_checkers()
checker_names = set(c.name for c in checkers)
should_not = set(('design', 'format', 'imports', 'metrics',
'miscellaneous', 'similarities'))
self.assertSetEqual(set(), should_not & checker_names)
def test_disable_similar(self):
self.linter.set_option('disable', 'RP0801')
self.linter.set_option('disable', 'R0801')
self.assertFalse('similarities' in [c.name for c in self.linter.prepare_checkers()])
def test_disable_alot(self):
"""check that we disabled a lot of checkers"""
self.linter.set_option('reports', False)
self.linter.set_option('disable', 'R,C,W')
checker_names = [c.name for c in self.linter.prepare_checkers()]
for cname in ('design', 'metrics', 'similarities',
'imports'): # as a Fatal message that should be ignored
self.assertFalse(cname in checker_names, cname)
def test_addmessage(self):
self.linter.set_reporter(TestReporter())
self.linter.open()
self.linter.set_current_module('0123')
self.linter.add_message('C0301', line=1, args=(1, 2))
self.linter.add_message('line-too-long', line=2, args=(3, 4))
self.assertEqual(
['C: 1: Line too long (1/2)', 'C: 2: Line too long (3/4)'],
self.linter.reporter.messages)
示例2: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import error_mode [as 别名]
#.........这里部分代码省略.........
text.register(self.linter)
self.linter.set_option('output-format', 'text')
self.assertEqual(self.linter.reporter.__class__.__name__, 'TextReporter')
def test_report_output_format_custom(self):
this_module = sys.modules[__name__]
class TestReporter(object):
pass
this_module.TestReporter = TestReporter
class_name = ".".join((this_module.__name__, 'TestReporter'))
self.linter.set_option('output-format', class_name)
self.assertEqual(self.linter.reporter.__class__.__name__, 'TestReporter')
def test_set_option_1(self):
linter = self.linter
linter.set_option('disable', 'C0111,W0234')
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0234'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('non-iterator-returned'))
def test_set_option_2(self):
linter = self.linter
linter.set_option('disable', ('C0111', 'W0234') )
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0234'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('non-iterator-returned'))
def test_enable_checkers(self):
self.linter.disable('design')
self.assertFalse('design' in [c.name for c in self.linter.prepare_checkers()])
self.linter.enable('design')
self.assertTrue('design' in [c.name for c in self.linter.prepare_checkers()])
def test_errors_only(self):
linter = self.linter
self.linter.error_mode()
checkers = self.linter.prepare_checkers()
checker_names = set(c.name for c in checkers)
should_not = set(('design', 'format', 'metrics',
'miscellaneous', 'similarities'))
self.assertSetEqual(set(), should_not & checker_names)
def test_disable_similar(self):
self.linter.set_option('disable', 'RP0801')
self.linter.set_option('disable', 'R0801')
self.assertFalse('similarities' in [c.name for c in self.linter.prepare_checkers()])
def test_disable_alot(self):
"""check that we disabled a lot of checkers"""
self.linter.set_option('reports', False)
self.linter.set_option('disable', 'R,C,W')
checker_names = [c.name for c in self.linter.prepare_checkers()]
for cname in ('design', 'metrics', 'similarities'):
self.assertFalse(cname in checker_names, cname)
def test_addmessage(self):
self.linter.set_reporter(TestReporter())
self.linter.open()
self.linter.set_current_module('0123')
self.linter.add_message('C0301', line=1, args=(1, 2))
self.linter.add_message('line-too-long', line=2, args=(3, 4))
self.assertEqual(
['C: 1: Line too long (1/2)', 'C: 2: Line too long (3/4)'],
self.linter.reporter.messages)
def test_init_hooks_called_before_load_plugins(self):
self.assertRaises(RuntimeError,
Run, ['--load-plugins', 'unexistant', '--init-hook', 'raise RuntimeError'])
self.assertRaises(RuntimeError,
Run, ['--init-hook', 'raise RuntimeError', '--load-plugins', 'unexistant'])
def test_analyze_explicit_script(self):
self.linter.set_reporter(TestReporter())
self.linter.check(os.path.join(os.path.dirname(__file__), 'data', 'ascript'))
self.assertEqual(
['C: 2: Line too long (175/100)'],
self.linter.reporter.messages)
def test_html_reporter_missing_files(self):
output = six.StringIO()
self.linter.set_reporter(html.HTMLReporter(output))
self.linter.set_option('output-format', 'html')
self.linter.check('troppoptop.py')
self.linter.generate_reports()
value = output.getvalue()
self.assertIn('troppoptop.py', value)
self.assertIn('fatal', value)
def test_python3_checker_disabled(self):
checker_names = [c.name for c in self.linter.prepare_checkers()]
self.assertNotIn('python3', checker_names)
self.linter.set_option('enable', 'python3')
checker_names = [c.name for c in self.linter.prepare_checkers()]
self.assertIn('python3', checker_names)
示例3: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import error_mode [as 别名]
#.........这里部分代码省略.........
self.assert_(not linter.is_message_enabled('E1101', 51))
# meth6
self.assert_(not linter.is_message_enabled('E1101', 57))
self.assert_(linter.is_message_enabled('E1101', 61))
self.assert_(not linter.is_message_enabled('E1101', 64))
self.assert_(not linter.is_message_enabled('E1101', 66))
self.assert_(linter.is_message_enabled('E0602', 57))
self.assert_(linter.is_message_enabled('E0602', 61))
self.assert_(not linter.is_message_enabled('E0602', 62))
self.assert_(linter.is_message_enabled('E0602', 64))
self.assert_(linter.is_message_enabled('E0602', 66))
# meth7
self.assert_(not linter.is_message_enabled('E1101', 70))
self.assert_(linter.is_message_enabled('E1101', 72))
self.assert_(linter.is_message_enabled('E1101', 75))
self.assert_(linter.is_message_enabled('E1101', 77))
def test_list_messages(self):
sys.stdout = StringIO()
try:
# just invoke it, don't check the output
self.linter.list_messages()
finally:
sys.stdout = sys.__stdout__
def test_lint_ext_module_with_file_output(self):
if sys.version_info < (3, 0):
strio = 'StringIO'
else:
strio = 'io'
self.linter.config.files_output = True
pylint_strio = 'pylint_%s.txt' % strio
try:
self.linter.check(strio)
self.assert_(os.path.exists(pylint_strio))
self.assert_(os.path.exists('pylint_global.txt'))
finally:
try:
os.remove(pylint_strio)
os.remove('pylint_global.txt')
except:
pass
def test_enable_report(self):
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
self.linter.disable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), False)
self.linter.enable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
def test_set_option_1(self):
linter = self.linter
linter.set_option('disable', 'C0111,W0142')
self.assert_(not linter.is_message_enabled('C0111'))
self.assert_(not linter.is_message_enabled('W0142'))
self.assert_(linter.is_message_enabled('W0113'))
def test_set_option_2(self):
linter = self.linter
linter.set_option('disable', ('C0111', 'W0142') )
self.assert_(not linter.is_message_enabled('C0111'))
self.assert_(not linter.is_message_enabled('W0142'))
self.assert_(linter.is_message_enabled('W0113'))
def test_enable_checkers(self):
self.linter.disable('design')
self.assertFalse('design' in [c.name for c in self.linter.prepare_checkers()])
self.linter.enable('design')
self.assertTrue('design' in [c.name for c in self.linter.prepare_checkers()])
def test_errors_only(self):
linter = self.linter
self.linter.error_mode()
checkers = self.linter.prepare_checkers()
checker_names = tuple(c.name for c in checkers)
should_not = ('design', 'format', 'imports', 'metrics',
'miscellaneous', 'similarities')
self.assertFalse(any(name in checker_names for name in should_not))
def test_disable_similar(self):
# XXX we have to disable them both, that's no good
self.linter.set_option('reports', False)
self.linter.set_option('disable', 'R0801')
self.assertFalse('similarities' in [c.name for c in self.linter.prepare_checkers()])
def test_disable_alot(self):
"""check that we disabled a lot of checkers"""
self.linter.set_option('reports', False)
# FIXME should it be necessary to explicitly desactivate failures ?
self.linter.set_option('disable', 'R,C,W')
checker_names = [c.name for c in self.linter.prepare_checkers()]
should_not = ('design', 'metrics', 'similarities')
rest = [name for name in checker_names if name in should_not]
self.assertListEqual(rest, [])
self.linter.set_option('disable', 'R,C,W,F')
checker_names = [c.name for c in self.linter.prepare_checkers()]
should_not += ('format', 'imports')
rest = [name for name in checker_names if name in should_not]
self.assertListEqual(rest, [])
示例4: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import error_mode [as 别名]
#.........这里部分代码省略.........
self.linter.set_reporter(text.TextReporter())
self.linter.config.files_output = True
self.linter.should_analyze_file = lambda *args: False
self.linter.check('logilab')
self.assertTrue(os.path.exists('pylint_logilab.txt'))
self.assertFalse(os.path.exists('pylint_logilab_common.txt'))
def test_enable_report(self):
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
self.linter.disable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), False)
self.linter.enable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
def test_report_output_format_aliased(self):
text.register(self.linter)
self.linter.set_option('output-format', 'text')
self.assertEqual(self.linter.reporter.__class__.__name__, 'TextReporter')
def test_report_output_format_custom(self):
this_module = sys.modules[__name__]
class TestReporter(object):
pass
this_module.TestReporter = TestReporter
class_name = ".".join((this_module.__name__, 'TestReporter'))
self.linter.set_option('output-format', class_name)
self.assertEqual(self.linter.reporter.__class__.__name__, 'TestReporter')
def test_set_option_1(self):
linter = self.linter
linter.set_option('disable', 'C0111,W0142')
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0142'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('star-args'))
# no name for W0113
def test_set_option_2(self):
linter = self.linter
linter.set_option('disable', ('C0111', 'W0142') )
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0142'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('star-args'))
# no name for W0113
def test_enable_checkers(self):
self.linter.disable('design')
self.assertFalse('design' in [c.name for c in self.linter.prepare_checkers()])
self.linter.enable('design')
self.assertTrue('design' in [c.name for c in self.linter.prepare_checkers()])
def test_errors_only(self):
linter = self.linter
self.linter.error_mode()
checkers = self.linter.prepare_checkers()
checker_names = set(c.name for c in checkers)
should_not = set(('design', 'format', 'imports', 'metrics',
'miscellaneous', 'similarities'))
self.assertSetEqual(set(), should_not & checker_names)
def test_disable_similar(self):
self.linter.set_option('disable', 'RP0801')
self.linter.set_option('disable', 'R0801')
self.assertFalse('similarities' in [c.name for c in self.linter.prepare_checkers()])
def test_disable_alot(self):
"""check that we disabled a lot of checkers"""
self.linter.set_option('reports', False)
self.linter.set_option('disable', 'R,C,W')
checker_names = [c.name for c in self.linter.prepare_checkers()]
for cname in ('design', 'metrics', 'similarities',
'imports'): # as a Fatal message that should be ignored
self.assertFalse(cname in checker_names, cname)
def test_addmessage(self):
self.linter.set_reporter(TestReporter())
self.linter.open()
self.linter.set_current_module('0123')
self.linter.add_message('C0301', line=1, args=(1, 2))
self.linter.add_message('line-too-long', line=2, args=(3, 4))
self.assertEqual(
['C: 1: Line too long (1/2)', 'C: 2: Line too long (3/4)'],
self.linter.reporter.messages)
def test_init_hooks_called_before_load_plugins(self):
self.assertRaises(RuntimeError,
Run, ['--load-plugins', 'unexistant', '--init-hook', 'raise RuntimeError'])
self.assertRaises(RuntimeError,
Run, ['--init-hook', 'raise RuntimeError', '--load-plugins', 'unexistant'])
def test_analyze_explicit_script(self):
self.linter.set_reporter(TestReporter())
self.linter.check(self.datapath('ascript'))
self.assertEqual(
['C: 2: Line too long (175/80)'],
self.linter.reporter.messages)
示例5: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import error_mode [as 别名]
#.........这里部分代码省略.........
self.linter.enable("RP0001")
self.assertEqual(self.linter.report_is_enabled("RP0001"), True)
def test_report_output_format_aliased(self):
text.register(self.linter)
self.linter.set_option("output-format", "text")
self.assertEqual(self.linter.reporter.__class__.__name__, "TextReporter")
def test_report_output_format_custom(self):
this_module = sys.modules[__name__]
class TestReporter(object):
pass
this_module.TestReporter = TestReporter
class_name = ".".join((this_module.__name__, "TestReporter"))
self.linter.set_option("output-format", class_name)
self.assertEqual(self.linter.reporter.__class__.__name__, "TestReporter")
def test_set_option_1(self):
linter = self.linter
linter.set_option("disable", "C0111,W0142")
self.assertFalse(linter.is_message_enabled("C0111"))
self.assertFalse(linter.is_message_enabled("W0142"))
self.assertTrue(linter.is_message_enabled("W0113"))
self.assertFalse(linter.is_message_enabled("missing-docstring"))
self.assertFalse(linter.is_message_enabled("star-args"))
# no name for W0113
def test_set_option_2(self):
linter = self.linter
linter.set_option("disable", ("C0111", "W0142"))
self.assertFalse(linter.is_message_enabled("C0111"))
self.assertFalse(linter.is_message_enabled("W0142"))
self.assertTrue(linter.is_message_enabled("W0113"))
self.assertFalse(linter.is_message_enabled("missing-docstring"))
self.assertFalse(linter.is_message_enabled("star-args"))
# no name for W0113
def test_enable_checkers(self):
self.linter.disable("design")
self.assertFalse("design" in [c.name for c in self.linter.prepare_checkers()])
self.linter.enable("design")
self.assertTrue("design" in [c.name for c in self.linter.prepare_checkers()])
def test_errors_only(self):
linter = self.linter
self.linter.error_mode()
checkers = self.linter.prepare_checkers()
checker_names = set(c.name for c in checkers)
should_not = set(("design", "format", "imports", "metrics", "miscellaneous", "similarities"))
self.assertSetEqual(set(), should_not & checker_names)
def test_disable_similar(self):
self.linter.set_option("disable", "RP0801")
self.linter.set_option("disable", "R0801")
self.assertFalse("similarities" in [c.name for c in self.linter.prepare_checkers()])
def test_disable_alot(self):
"""check that we disabled a lot of checkers"""
self.linter.set_option("reports", False)
self.linter.set_option("disable", "R,C,W")
checker_names = [c.name for c in self.linter.prepare_checkers()]
for cname in ("design", "metrics", "similarities", "imports"): # as a Fatal message that should be ignored
self.assertFalse(cname in checker_names, cname)
def test_addmessage(self):
self.linter.set_reporter(TestReporter())
self.linter.open()
self.linter.set_current_module("0123")
self.linter.add_message("C0301", line=1, args=(1, 2))
self.linter.add_message("line-too-long", line=2, args=(3, 4))
self.assertEqual(["C: 1: Line too long (1/2)", "C: 2: Line too long (3/4)"], self.linter.reporter.messages)
def test_init_hooks_called_before_load_plugins(self):
self.assertRaises(RuntimeError, Run, ["--load-plugins", "unexistant", "--init-hook", "raise RuntimeError"])
self.assertRaises(RuntimeError, Run, ["--init-hook", "raise RuntimeError", "--load-plugins", "unexistant"])
def test_analyze_explicit_script(self):
self.linter.set_reporter(TestReporter())
self.linter.check(os.path.join(os.path.dirname(__file__), "data", "ascript"))
self.assertEqual(["C: 2: Line too long (175/100)"], self.linter.reporter.messages)
def test_html_reporter_missing_files(self):
output = six.StringIO()
self.linter.set_reporter(html.HTMLReporter(output))
self.linter.set_option("output-format", "html")
self.linter.check("troppoptop.py")
self.linter.generate_reports()
value = output.getvalue()
self.assertIn("troppoptop.py", value)
self.assertIn("fatal", value)
def test_python3_checker_disabled(self):
checker_names = [c.name for c in self.linter.prepare_checkers()]
self.assertNotIn("python3", checker_names)
self.linter.set_option("enable", "python3")
checker_names = [c.name for c in self.linter.prepare_checkers()]
self.assertIn("python3", checker_names)
示例6: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import error_mode [as 别名]
#.........这里部分代码省略.........
self.linter.should_analyze_file = lambda *args: False
self.linter.check('os')
self.assertFalse(os.path.exists('pylint_os.txt'))
def test_enable_report(self):
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
self.linter.disable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), False)
self.linter.enable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
def test_report_output_format_aliased(self):
text.register(self.linter)
self.linter.set_option('output-format', 'text')
self.assertEqual(self.linter.reporter.__class__.__name__, 'TextReporter')
def test_report_output_format_custom(self):
this_module = sys.modules[__name__]
class TestReporter(object):
pass
this_module.TestReporter = TestReporter
class_name = ".".join((this_module.__name__, 'TestReporter'))
self.linter.set_option('output-format', class_name)
self.assertEqual(self.linter.reporter.__class__.__name__, 'TestReporter')
def test_set_option_1(self):
linter = self.linter
linter.set_option('disable', 'C0111,W0142')
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0142'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('star-args'))
# no name for W0113
def test_set_option_2(self):
linter = self.linter
linter.set_option('disable', ('C0111', 'W0142') )
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0142'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('star-args'))
# no name for W0113
def test_enable_checkers(self):
self.linter.disable('design')
self.assertFalse('design' in [c.name for c in self.linter.prepare_checkers()])
self.linter.enable('design')
self.assertTrue('design' in [c.name for c in self.linter.prepare_checkers()])
def test_errors_only(self):
linter = self.linter
self.linter.error_mode()
checkers = self.linter.prepare_checkers()
checker_names = set(c.name for c in checkers)
should_not = set(('design', 'format', 'imports', 'metrics',
'miscellaneous', 'similarities'))
self.assertSetEqual(set(), should_not & checker_names)
def test_disable_similar(self):
self.linter.set_option('disable', 'RP0801')
self.linter.set_option('disable', 'R0801')
self.assertFalse('similarities' in [c.name for c in self.linter.prepare_checkers()])
def test_disable_alot(self):
"""check that we disabled a lot of checkers"""
self.linter.set_option('reports', False)
self.linter.set_option('disable', 'R,C,W')
checker_names = [c.name for c in self.linter.prepare_checkers()]
for cname in ('design', 'metrics', 'similarities',
'imports'): # as a Fatal message that should be ignored
self.assertFalse(cname in checker_names, cname)
def test_addmessage(self):
self.linter.set_reporter(TestReporter())
self.linter.open()
self.linter.set_current_module('0123')
self.linter.add_message('C0301', line=1, args=(1, 2))
self.linter.add_message('line-too-long', line=2, args=(3, 4))
self.assertEqual(
['C: 1: Line too long (1/2)', 'C: 2: Line too long (3/4)'],
self.linter.reporter.messages)
def test_add_renamed_message(self):
self.linter.add_renamed_message('C9999', 'old-bad-name', 'invalid-name')
self.assertEqual('invalid-name',
self.linter.check_message_id('C9999').symbol)
self.assertEqual('invalid-name',
self.linter.check_message_id('old-bad-name').symbol)
def test_renamed_message_register(self):
class Checker(object):
msgs = {'W1234': ('message', 'msg-symbol', 'msg-description',
{'old_names': [('W0001', 'old-symbol')]})}
self.linter.register_messages(Checker())
self.assertEqual('msg-symbol',
self.linter.check_message_id('W0001').symbol)
self.assertEqual('msg-symbol',
self.linter.check_message_id('old-symbol').symbol)
示例7: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import error_mode [as 别名]
#.........这里部分代码省略.........
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
def test_report_output_format_aliased(self):
text.register(self.linter)
self.linter.set_option('output-format', 'text')
self.assertEqual(self.linter.reporter.__class__.__name__, 'TextReporter')
def test_set_option_1(self):
linter = self.linter
linter.set_option('disable', 'C0111,W0234')
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0234'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('non-iterator-returned'))
def test_set_option_2(self):
linter = self.linter
linter.set_option('disable', ('C0111', 'W0234') )
self.assertFalse(linter.is_message_enabled('C0111'))
self.assertFalse(linter.is_message_enabled('W0234'))
self.assertTrue(linter.is_message_enabled('W0113'))
self.assertFalse(linter.is_message_enabled('missing-docstring'))
self.assertFalse(linter.is_message_enabled('non-iterator-returned'))
def test_enable_checkers(self):
self.linter.disable('design')
self.assertFalse('design' in [c.name for c in self.linter.prepare_checkers()])
self.linter.enable('design')
self.assertTrue('design' in [c.name for c in self.linter.prepare_checkers()])
def test_errors_only(self):
linter = self.linter
self.linter.error_mode()
checkers = self.linter.prepare_checkers()
checker_names = set(c.name for c in checkers)
should_not = set(('design', 'format', 'metrics',
'miscellaneous', 'similarities'))
self.assertSetEqual(set(), should_not & checker_names)
def test_disable_similar(self):
self.linter.set_option('disable', 'RP0801')
self.linter.set_option('disable', 'R0801')
self.assertFalse('similarities' in [c.name for c in self.linter.prepare_checkers()])
def test_disable_alot(self):
"""check that we disabled a lot of checkers"""
self.linter.set_option('reports', False)
self.linter.set_option('disable', 'R,C,W')
checker_names = [c.name for c in self.linter.prepare_checkers()]
for cname in ('design', 'metrics', 'similarities'):
self.assertFalse(cname in checker_names, cname)
def test_addmessage(self):
self.linter.set_reporter(TestReporter())
self.linter.open()
self.linter.set_current_module('0123')
self.linter.add_message('C0301', line=1, args=(1, 2))
self.linter.add_message('line-too-long', line=2, args=(3, 4))
self.assertEqual(
['C: 1: Line too long (1/2)', 'C: 2: Line too long (3/4)'],
self.linter.reporter.messages)
def test_addmessage_invalid(self):
self.linter.set_reporter(TestReporter())
self.linter.open()