本文整理汇总了Python中pylint.lint.PyLinter.set_current_module方法的典型用法代码示例。如果您正苦于以下问题:Python PyLinter.set_current_module方法的具体用法?Python PyLinter.set_current_module怎么用?Python PyLinter.set_current_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylint.lint.PyLinter
的用法示例。
在下文中一共展示了PyLinter.set_current_module方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_html_reporter_msg_template
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
def test_html_reporter_msg_template(self):
expected = '''
<html>
<body>
<div>
<div>
<h2>Messages</h2>
<table>
<tr class="header">
<th>category</th>
<th>msg_id</th>
</tr>
<tr class="even">
<td>warning</td>
<td>W0332</td>
</tr>
</table>
</div>
</div>
</body>
</html>'''.strip().splitlines()
output = six.StringIO()
linter = PyLinter(reporter=HTMLReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option('msg-template', '{category}{msg_id}')
linter.open()
linter.set_current_module('0123')
linter.add_message('lowercase-l-suffix', line=1)
linter.reporter.display_results(Section())
self.assertEqual(output.getvalue().splitlines(), expected)
示例2: test_simple_json_output
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
def test_simple_json_output():
output = StringIO()
reporter = JSONReporter()
linter = PyLinter(reporter=reporter)
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.open()
linter.set_current_module("0123")
linter.add_message("line-too-long", line=1, args=(1, 2))
# we call this method because we didn't actually run the checkers
reporter.display_messages(None)
expected_result = [
[
("column", 0),
("line", 1),
("message", "Line too long (1/2)"),
("message-id", "C0301"),
("module", "0123"),
("obj", ""),
("path", "0123"),
("symbol", "line-too-long"),
("type", "convention"),
]
]
report_result = json.loads(output.getvalue())
report_result = [sorted(report_result[0].items(), key=lambda item: item[0])]
assert report_result == expected_result
示例3: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(TestCase):
def setUp(self):
self.linter = PyLinter(reporter=TextReporter())
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
os.environ.pop('PYLINTRC', None)
def test_template_option(self):
# self.linter.set_reporter(TextReporter())
expected = ( '************* Module 0123\n'
'C0301:001\n'
'C0301:002\n'
)
output = StringIO()
self.linter.reporter.set_output(output)
self.linter.set_option('msg-template', '{msg_id}:{line:03d}')
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.assertMultiLineEqual(output.getvalue(), expected)
示例4: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(unittest.TestCase):
def setUp(self):
self.linter = PyLinter(reporter=TextReporter())
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
os.environ.pop('PYLINTRC', None)
def test_template_option(self):
output = six.StringIO()
self.linter.reporter.set_output(output)
self.linter.set_option('msg-template', '{msg_id}:{line:03d}')
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.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'C0301:001\n'
'C0301:002\n')
def test_parseable_output_deprecated(self):
with warnings.catch_warnings(record=True) as cm:
warnings.simplefilter("always")
ParseableTextReporter()
self.assertEqual(len(cm), 1)
self.assertIsInstance(cm[0].message, DeprecationWarning)
def test_parseable_output_regression(self):
output = six.StringIO()
with warnings.catch_warnings(record=True):
linter = PyLinter(reporter=ParseableTextReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option('output-format', 'parseable')
linter.open()
linter.set_current_module('0123')
linter.add_message('line-too-long', line=1, args=(1, 2))
self.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'0123:1: [C0301(line-too-long), ] '
'Line too long (1/2)\n')
def test_display_results_is_renamed(self):
class CustomReporter(TextReporter):
def _display(self, layout):
return None
reporter = CustomReporter()
with self.assertRaises(AttributeError):
reporter.display_results
示例5: test_parseable_output_regression
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
def test_parseable_output_regression(self):
output = six.StringIO()
linter = PyLinter(reporter=ParseableTextReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option('output-format', 'parseable')
linter.open()
linter.set_current_module('0123')
linter.add_message('line-too-long', line=1, args=(1, 2))
self.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'0123:1: [C0301(line-too-long), ] '
'Line too long (1/2)\n')
示例6: test_parseable_output_regression
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
def test_parseable_output_regression():
output = StringIO()
with warnings.catch_warnings(record=True):
linter = PyLinter(reporter=ParseableTextReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option('output-format', 'parseable')
linter.open()
linter.set_current_module('0123')
linter.add_message('line-too-long', line=1, args=(1, 2))
assert output.getvalue() == \
'************* Module 0123\n' \
'0123:1: [C0301(line-too-long), ] ' \
'Line too long (1/2)\n'
示例7: test_html_reporter_type
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
def test_html_reporter_type(self):
# Integration test for issue #263
# https://bitbucket.org/logilab/pylint/issue/263/html-report-type-problems
expected = '''<html>
<body>
<div>
<div>
<h2>Messages</h2>
<table>
<tr class="header">
<th>type</th>
<th>module</th>
<th>object</th>
<th>line</th>
<th>col_offset</th>
<th>message</th>
</tr>
<tr class="even">
<td>convention</td>
<td>0123</td>
<td> </td>
<td>1</td>
<td>0</td>
<td>Exactly one space required before comparison
a< 5: print "zero"</td>
</tr>
</table>
</div>
</div>
</body>
</html>
'''
output = six.StringIO()
with testutils.catch_warnings():
linter = PyLinter(reporter=HTMLReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.open()
linter.set_current_module('0123')
linter.add_message('bad-whitespace', line=1,
args=('Exactly one', 'required', 'before',
'comparison', 'a< 5: print "zero"'))
linter.reporter.display_reports(Section())
self.assertMultiLineEqual(output.getvalue(), expected)
示例8: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(unittest.TestCase):
def setUp(self):
self.linter = PyLinter(reporter=TextReporter())
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
os.environ.pop('PYLINTRC', None)
def test_template_option(self):
output = six.StringIO()
self.linter.reporter.set_output(output)
self.linter.set_option('msg-template', '{msg_id}:{line:03d}')
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.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'C0301:001\n'
'C0301:002\n')
def test_parseable_output_regression(self):
output = six.StringIO()
linter = PyLinter(reporter=ParseableTextReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option('output-format', 'parseable')
linter.open()
linter.set_current_module('0123')
linter.add_message('line-too-long', line=1, args=(1, 2))
self.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'0123:1: [C0301(line-too-long), ] '
'Line too long (1/2)\n')
示例9: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(unittest.TestCase):
def setUp(self):
self.linter = PyLinter(reporter=TextReporter())
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
os.environ.pop('PYLINTRC', None)
def test_add_message_is_deprecated(self):
if __pkginfo__.numversion >= (1, 6, 0):
with self.assertRaises(AttributeError):
BaseReporter().add_message
with warnings.catch_warnings(record=True) as cm:
warnings.simplefilter("always")
BaseReporter().add_message(None, None, None)
self.assertEqual(len(cm), 1)
self.assertIsInstance(cm[0].message, DeprecationWarning)
msg = ('This method is deprecated, use handle_message '
'instead. It will be removed in Pylint 1.6.')
self.assertEqual(str(cm[0].message), msg)
def test_template_option(self):
output = six.StringIO()
self.linter.reporter.set_output(output)
self.linter.set_option('msg-template', '{msg_id}:{line:03d}')
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.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'C0301:001\n'
'C0301:002\n')
def test_parseable_output_deprecated(self):
with warnings.catch_warnings(record=True) as cm:
warnings.simplefilter("always")
ParseableTextReporter()
self.assertEqual(len(cm), 1)
self.assertIsInstance(cm[0].message, DeprecationWarning)
def test_parseable_output_regression(self):
output = six.StringIO()
with warnings.catch_warnings(record=True):
linter = PyLinter(reporter=ParseableTextReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option('output-format', 'parseable')
linter.open()
linter.set_current_module('0123')
linter.add_message('line-too-long', line=1, args=(1, 2))
self.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'0123:1: [C0301(line-too-long), ] '
'Line too long (1/2)\n')
def test_html_reporter_msg_template(self):
expected = '''
<html>
<body>
<div>
<div>
<h2>Messages</h2>
<table>
<tr class="header">
<th>category</th>
<th>msg_id</th>
</tr>
<tr class="even">
<td>warning</td>
<td>W0332</td>
</tr>
</table>
</div>
</div>
</body>
</html>'''.strip().splitlines()
output = six.StringIO()
linter = PyLinter(reporter=HTMLReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option('msg-template', '{category}{msg_id}')
linter.open()
linter.set_current_module('0123')
linter.add_message('lowercase-l-suffix', line=1)
linter.reporter.display_results(Section())
self.assertEqual(output.getvalue().splitlines(), expected)
@unittest.expectedFailure
def test_html_reporter_type(self):
# Integration test for issue #263
# https://bitbucket.org/logilab/pylint/issue/263/html-report-type-problems
#.........这里部分代码省略.........
示例10: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(unittest.TestCase):
def setUp(self):
self.linter = PyLinter()
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
self.linter.set_reporter(TestReporter())
def init_linter(self):
linter = self.linter
linter.open()
linter.set_current_module('toto')
linter.file_state = FileState('toto')
return linter
def test_pylint_visit_method_taken_in_account(self):
class CustomChecker(checkers.BaseChecker):
__implements__ = interfaces.IAstroidChecker
name = 'custom'
msgs = {'W9999': ('', 'custom', '')}
@check_messages('custom')
def visit_class(self, _):
pass
self.linter.register_checker(CustomChecker(self.linter))
self.linter.open()
out = six.moves.StringIO()
self.linter.set_reporter(text.TextReporter(out))
self.linter.check('abc')
def test_enable_message(self):
linter = self.init_linter()
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102'))
linter.disable('W0101', scope='package')
linter.disable('W0102', scope='module', line=1)
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertFalse(linter.is_message_enabled('W0102', 1))
linter.set_current_module('tutu')
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102'))
linter.enable('W0101', scope='package')
linter.enable('W0102', scope='module', line=1)
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102', 1))
def test_enable_message_category(self):
linter = self.init_linter()
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0202'))
linter.disable('W', scope='package')
linter.disable('C', scope='module', line=1)
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0202'))
self.assertFalse(linter.is_message_enabled('C0202', line=1))
linter.set_current_module('tutu')
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0202'))
linter.enable('W', scope='package')
linter.enable('C', scope='module', line=1)
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0202'))
self.assertTrue(linter.is_message_enabled('C0202', line=1))
def test_message_state_scope(self):
class FakeConfig(object):
confidence = ['HIGH']
linter = self.init_linter()
linter.disable('C0202')
self.assertEqual(MSG_STATE_SCOPE_CONFIG,
linter.get_message_state_scope('C0202'))
linter.disable('W0101', scope='module', line=3)
self.assertEqual(MSG_STATE_SCOPE_CONFIG,
linter.get_message_state_scope('C0202'))
self.assertEqual(MSG_STATE_SCOPE_MODULE,
linter.get_message_state_scope('W0101', 3))
linter.enable('W0102', scope='module', line=3)
self.assertEqual(MSG_STATE_SCOPE_MODULE,
linter.get_message_state_scope('W0102', 3))
linter.config = FakeConfig()
self.assertEqual(
MSG_STATE_CONFIDENCE,
linter.get_message_state_scope('this-is-bad',
confidence=interfaces.INFERENCE))
def test_enable_message_block(self):
linter = self.init_linter()
linter.open()
filepath = join(INPUTDIR, 'func_block_disable_msg.py')
linter.set_current_module('func_block_disable_msg')
astroid = linter.get_ast(filepath, 'func_block_disable_msg')
linter.process_tokens(tokenize_module(astroid))
fs = linter.file_state
fs.collect_block_lines(linter.msgs_store, astroid)
# global (module level)
self.assertTrue(linter.is_message_enabled('W0613'))
#.........这里部分代码省略.........
示例11: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(TestCase):
def setUp(self):
self.linter = PyLinter()
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
self.linter.set_reporter(TestReporter())
def test_message_help(self):
msg = self.linter.get_message_help('F0001', checkerref=True)
expected = ':F0001 (fatal):\n Used when an error occurred preventing the analysis of a module (unable to\n find it for instance). This message belongs to the master checker.'
self.assertMultiLineEqual(msg, expected)
self.assertRaises(UnknownMessage, self.linter.get_message_help, 'YB12')
def test_enable_message(self):
linter = self.linter
linter.open()
linter.set_current_module('toto')
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102'))
linter.disable('W0101', scope='package')
linter.disable('W0102', scope='module', line=1)
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertFalse(linter.is_message_enabled('W0102', 1))
linter.set_current_module('tutu')
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102'))
linter.enable('W0101', scope='package')
linter.enable('W0102', scope='module', line=1)
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102', 1))
def test_enable_message_category(self):
linter = self.linter
linter.open()
linter.set_current_module('toto')
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
linter.disable('W', scope='package')
linter.disable('C', scope='module', line=1)
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
self.assertFalse(linter.is_message_enabled('C0121', line=1))
linter.set_current_module('tutu')
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
linter.enable('W', scope='package')
linter.enable('C', scope='module', line=1)
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
self.assertTrue(linter.is_message_enabled('C0121', line=1))
def test_message_state_scope(self):
linter = self.linter
linter.open()
linter.disable('C0121')
self.assertEqual(MSG_STATE_SCOPE_CONFIG,
linter.get_message_state_scope('C0121'))
linter.disable('W0101', scope='module', line=3)
self.assertEqual(MSG_STATE_SCOPE_CONFIG,
linter.get_message_state_scope('C0121'))
self.assertEqual(MSG_STATE_SCOPE_MODULE,
linter.get_message_state_scope('W0101', 3))
linter.enable('W0102', scope='module', line=3)
self.assertEqual(MSG_STATE_SCOPE_MODULE,
linter.get_message_state_scope('W0102', 3))
def test_enable_message_block(self):
linter = self.linter
linter.open()
filepath = join(INPUTDIR, 'func_block_disable_msg.py')
linter.set_current_module('func_block_disable_msg')
astroid = linter.get_astroid(filepath, 'func_block_disable_msg')
linter.process_tokens(tokenize_module(astroid))
orig_state = linter._module_msgs_state.copy()
linter._module_msgs_state = {}
linter._suppression_mapping = {}
linter.collect_block_lines(astroid, orig_state)
# global (module level)
self.assertTrue(linter.is_message_enabled('W0613'))
self.assertTrue(linter.is_message_enabled('E1101'))
# meth1
self.assertTrue(linter.is_message_enabled('W0613', 13))
# meth2
self.assertFalse(linter.is_message_enabled('W0613', 18))
# meth3
self.assertFalse(linter.is_message_enabled('E1101', 24))
self.assertTrue(linter.is_message_enabled('E1101', 26))
# meth4
self.assertFalse(linter.is_message_enabled('E1101', 32))
self.assertTrue(linter.is_message_enabled('E1101', 36))
# meth5
self.assertFalse(linter.is_message_enabled('E1101', 42))
self.assertFalse(linter.is_message_enabled('E1101', 43))
self.assertTrue(linter.is_message_enabled('E1101', 46))
self.assertFalse(linter.is_message_enabled('E1101', 49))
self.assertFalse(linter.is_message_enabled('E1101', 51))
# meth6
#.........这里部分代码省略.........
示例12: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(TestCase):
def setUp(self):
self.linter = PyLinter()
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
self.linter.set_reporter(TestReporter())
def init_linter(self):
linter = self.linter
linter.open()
linter.set_current_module('toto')
linter.file_state = FileState('toto')
return linter
def test_enable_message(self):
linter = self.init_linter()
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102'))
linter.disable('W0101', scope='package')
linter.disable('W0102', scope='module', line=1)
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertFalse(linter.is_message_enabled('W0102', 1))
linter.set_current_module('tutu')
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102'))
linter.enable('W0101', scope='package')
linter.enable('W0102', scope='module', line=1)
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102', 1))
def test_enable_message_category(self):
linter = self.init_linter()
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
linter.disable('W', scope='package')
linter.disable('C', scope='module', line=1)
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
self.assertFalse(linter.is_message_enabled('C0121', line=1))
linter.set_current_module('tutu')
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
linter.enable('W', scope='package')
linter.enable('C', scope='module', line=1)
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
self.assertTrue(linter.is_message_enabled('C0121', line=1))
def test_message_state_scope(self):
linter = self.init_linter()
fs = linter.file_state
linter.disable('C0121')
self.assertEqual(MSG_STATE_SCOPE_CONFIG,
fs._message_state_scope('C0121'))
linter.disable('W0101', scope='module', line=3)
self.assertEqual(MSG_STATE_SCOPE_CONFIG,
fs._message_state_scope('C0121'))
self.assertEqual(MSG_STATE_SCOPE_MODULE,
fs._message_state_scope('W0101', 3))
linter.enable('W0102', scope='module', line=3)
self.assertEqual(MSG_STATE_SCOPE_MODULE,
fs._message_state_scope('W0102', 3))
def test_enable_message_block(self):
linter = self.init_linter()
linter.open()
filepath = join(INPUTDIR, 'func_block_disable_msg.py')
linter.set_current_module('func_block_disable_msg')
astroid = linter.get_ast(filepath, 'func_block_disable_msg')
linter.process_tokens(tokenize_module(astroid))
fs = linter.file_state
fs.collect_block_lines(linter.msgs_store, astroid)
# global (module level)
self.assertTrue(linter.is_message_enabled('W0613'))
self.assertTrue(linter.is_message_enabled('E1101'))
# meth1
self.assertTrue(linter.is_message_enabled('W0613', 13))
# meth2
self.assertFalse(linter.is_message_enabled('W0613', 18))
# meth3
self.assertFalse(linter.is_message_enabled('E1101', 24))
self.assertTrue(linter.is_message_enabled('E1101', 26))
# meth4
self.assertFalse(linter.is_message_enabled('E1101', 32))
self.assertTrue(linter.is_message_enabled('E1101', 36))
# meth5
self.assertFalse(linter.is_message_enabled('E1101', 42))
self.assertFalse(linter.is_message_enabled('E1101', 43))
self.assertTrue(linter.is_message_enabled('E1101', 46))
self.assertFalse(linter.is_message_enabled('E1101', 49))
self.assertFalse(linter.is_message_enabled('E1101', 51))
# meth6
self.assertFalse(linter.is_message_enabled('E1101', 57))
self.assertTrue(linter.is_message_enabled('E1101', 61))
self.assertFalse(linter.is_message_enabled('E1101', 64))
self.assertFalse(linter.is_message_enabled('E1101', 66))
#.........这里部分代码省略.........
示例13: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(unittest.TestCase):
def setUp(self):
self.linter = PyLinter()
self.linter.disable("I")
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
self.linter.set_reporter(TestReporter())
def init_linter(self):
linter = self.linter
linter.open()
linter.set_current_module("toto")
linter.file_state = FileState("toto")
return linter
def test_enable_message(self):
linter = self.init_linter()
self.assertTrue(linter.is_message_enabled("W0101"))
self.assertTrue(linter.is_message_enabled("W0102"))
linter.disable("W0101", scope="package")
linter.disable("W0102", scope="module", line=1)
self.assertFalse(linter.is_message_enabled("W0101"))
self.assertFalse(linter.is_message_enabled("W0102", 1))
linter.set_current_module("tutu")
self.assertFalse(linter.is_message_enabled("W0101"))
self.assertTrue(linter.is_message_enabled("W0102"))
linter.enable("W0101", scope="package")
linter.enable("W0102", scope="module", line=1)
self.assertTrue(linter.is_message_enabled("W0101"))
self.assertTrue(linter.is_message_enabled("W0102", 1))
def test_enable_message_category(self):
linter = self.init_linter()
self.assertTrue(linter.is_message_enabled("W0101"))
self.assertTrue(linter.is_message_enabled("C0121"))
linter.disable("W", scope="package")
linter.disable("C", scope="module", line=1)
self.assertFalse(linter.is_message_enabled("W0101"))
self.assertTrue(linter.is_message_enabled("C0121"))
self.assertFalse(linter.is_message_enabled("C0121", line=1))
linter.set_current_module("tutu")
self.assertFalse(linter.is_message_enabled("W0101"))
self.assertTrue(linter.is_message_enabled("C0121"))
linter.enable("W", scope="package")
linter.enable("C", scope="module", line=1)
self.assertTrue(linter.is_message_enabled("W0101"))
self.assertTrue(linter.is_message_enabled("C0121"))
self.assertTrue(linter.is_message_enabled("C0121", line=1))
def test_message_state_scope(self):
class FakeConfig(object):
confidence = ["HIGH"]
linter = self.init_linter()
linter.disable("C0121")
self.assertEqual(MSG_STATE_SCOPE_CONFIG, linter.get_message_state_scope("C0121"))
linter.disable("W0101", scope="module", line=3)
self.assertEqual(MSG_STATE_SCOPE_CONFIG, linter.get_message_state_scope("C0121"))
self.assertEqual(MSG_STATE_SCOPE_MODULE, linter.get_message_state_scope("W0101", 3))
linter.enable("W0102", scope="module", line=3)
self.assertEqual(MSG_STATE_SCOPE_MODULE, linter.get_message_state_scope("W0102", 3))
linter.config = FakeConfig()
self.assertEqual(
MSG_STATE_CONFIDENCE, linter.get_message_state_scope("this-is-bad", confidence=interfaces.INFERENCE)
)
def test_enable_message_block(self):
linter = self.init_linter()
linter.open()
filepath = join(INPUTDIR, "func_block_disable_msg.py")
linter.set_current_module("func_block_disable_msg")
astroid = linter.get_ast(filepath, "func_block_disable_msg")
linter.process_tokens(tokenize_module(astroid))
fs = linter.file_state
fs.collect_block_lines(linter.msgs_store, astroid)
# global (module level)
self.assertTrue(linter.is_message_enabled("W0613"))
self.assertTrue(linter.is_message_enabled("E1101"))
# meth1
self.assertTrue(linter.is_message_enabled("W0613", 13))
# meth2
self.assertFalse(linter.is_message_enabled("W0613", 18))
# meth3
self.assertFalse(linter.is_message_enabled("E1101", 24))
self.assertTrue(linter.is_message_enabled("E1101", 26))
# meth4
self.assertFalse(linter.is_message_enabled("E1101", 32))
self.assertTrue(linter.is_message_enabled("E1101", 36))
# meth5
self.assertFalse(linter.is_message_enabled("E1101", 42))
self.assertFalse(linter.is_message_enabled("E1101", 43))
self.assertTrue(linter.is_message_enabled("E1101", 46))
self.assertFalse(linter.is_message_enabled("E1101", 49))
self.assertFalse(linter.is_message_enabled("E1101", 51))
# meth6
self.assertFalse(linter.is_message_enabled("E1101", 57))
self.assertTrue(linter.is_message_enabled("E1101", 61))
self.assertFalse(linter.is_message_enabled("E1101", 64))
self.assertFalse(linter.is_message_enabled("E1101", 66))
#.........这里部分代码省略.........
示例14: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(TestCase):
def setUp(self):
self.linter = PyLinter()
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
self.linter.set_reporter(TestReporter())
def _compare_messages(self, desc, msg, checkerref=False):
# replace \r\n with \n, because
# logilab.common.textutils.normalize_text
# uses os.linesep, which will
# not properly compare with triple
# quoted multilines used in these tests
self.assertMultiLineEqual(desc,
msg.format_help(checkerref=checkerref)
.replace('\r\n', '\n'))
def test_check_message_id(self):
self.assertIsInstance(self.linter.check_message_id('F0001'),
MessageDefinition)
self.assertRaises(UnknownMessage,
self.linter.check_message_id, 'YB12')
def test_message_help(self):
msg = self.linter.check_message_id('F0001')
self._compare_messages(
''':fatal (F0001):
Used when an error occurred preventing the analysis of a module (unable to
find it for instance). This message belongs to the master checker.''',
msg, checkerref=True)
self._compare_messages(
''':fatal (F0001):
Used when an error occurred preventing the analysis of a module (unable to
find it for instance).''',
msg, checkerref=False)
def test_message_help_minmax(self):
# build the message manually to be python version independant
msg = build_message_def(self.linter._checkers['typecheck'][0],
'E1122', checkers.typecheck.MSGS['E1122'])
self._compare_messages(
''':duplicate-keyword-arg (E1122): *Duplicate keyword argument %r in function call*
Used when a function call passes the same keyword argument multiple times.
This message belongs to the typecheck checker. It can't be emitted when using
Python >= 2.6.''',
msg, checkerref=True)
self._compare_messages(
''':duplicate-keyword-arg (E1122): *Duplicate keyword argument %r in function call*
Used when a function call passes the same keyword argument multiple times.
This message can't be emitted when using Python >= 2.6.''',
msg, checkerref=False)
def test_enable_message(self):
linter = self.linter
linter.open()
linter.set_current_module('toto')
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102'))
linter.disable('W0101', scope='package')
linter.disable('W0102', scope='module', line=1)
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertFalse(linter.is_message_enabled('W0102', 1))
linter.set_current_module('tutu')
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102'))
linter.enable('W0101', scope='package')
linter.enable('W0102', scope='module', line=1)
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('W0102', 1))
def test_enable_message_category(self):
linter = self.linter
linter.open()
linter.set_current_module('toto')
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
linter.disable('W', scope='package')
linter.disable('C', scope='module', line=1)
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
self.assertFalse(linter.is_message_enabled('C0121', line=1))
linter.set_current_module('tutu')
self.assertFalse(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
linter.enable('W', scope='package')
linter.enable('C', scope='module', line=1)
self.assertTrue(linter.is_message_enabled('W0101'))
self.assertTrue(linter.is_message_enabled('C0121'))
self.assertTrue(linter.is_message_enabled('C0121', line=1))
def test_message_state_scope(self):
linter = self.linter
linter.open()
linter.disable('C0121')
self.assertEqual(MSG_STATE_SCOPE_CONFIG,
linter.get_message_state_scope('C0121'))
linter.disable('W0101', scope='module', line=3)
#.........这里部分代码省略.........
示例15: PyLinterTC
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import set_current_module [as 别名]
class PyLinterTC(unittest.TestCase):
def setUp(self):
self.linter = PyLinter(reporter=TextReporter())
self.linter.disable('I')
self.linter.config.persistent = 0
# register checkers
checkers.initialize(self.linter)
os.environ.pop('PYLINTRC', None)
def test_template_option(self):
output = six.StringIO()
self.linter.reporter.set_output(output)
self.linter.set_option('msg-template', '{msg_id}:{line:03d}')
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.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'C0301:001\n'
'C0301:002\n')
def test_parseable_output_regression(self):
output = six.StringIO()
linter = PyLinter(reporter=ParseableTextReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.set_option('output-format', 'parseable')
linter.open()
linter.set_current_module('0123')
linter.add_message('line-too-long', line=1, args=(1, 2))
self.assertMultiLineEqual(output.getvalue(),
'************* Module 0123\n'
'0123:1: [C0301(line-too-long), ] '
'Line too long (1/2)\n')
@unittest.expectedFailure
def test_html_reporter_type(self):
# Integration test for issue #263
# https://bitbucket.org/logilab/pylint/issue/263/html-report-type-problems
expected = '''<html>
<body>
<div>
<div>
<h2>Messages</h2>
<table>
<tr class="header">
<th>type</th>
<th>module</th>
<th>object</th>
<th>line</th>
<th>col_offset</th>
<th>message</th>
</tr>
<tr class="even">
<td>convention</td>
<td>0123</td>
<td> </td>
<td>1</td>
<td>0</td>
<td>Exactly one space required before comparison
a< 5: print "zero"</td>
</tr>
</table>
</div>
</div>
</body>
</html>
'''
output = six.StringIO()
linter = PyLinter(reporter=HTMLReporter())
checkers.initialize(linter)
linter.config.persistent = 0
linter.reporter.set_output(output)
linter.open()
linter.set_current_module('0123')
linter.add_message('bad-whitespace', line=1,
args=('Exactly one', 'required', 'before',
'comparison', 'a< 5: print "zero"'))
linter.reporter.display_results(Section())
self.assertMultiLineEqual(output.getvalue(), expected)