本文整理汇总了Python中pylint.lint.fix_import_path函数的典型用法代码示例。如果您正苦于以下问题:Python fix_import_path函数的具体用法?Python fix_import_path怎么用?Python fix_import_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fix_import_path函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_two_similar_args
def test_two_similar_args(fake_path, case):
with tempdir() as chroot:
create_files(['a/b/__init__.py', 'a/c/__init__.py'])
expected = [join(chroot, 'a')] + ["."] + fake_path
assert sys.path == fake_path
with lint.fix_import_path(case):
assert sys.path == expected
assert sys.path == fake_path
示例2: test_one_arg
def test_one_arg(fake_path, case):
with tempdir() as chroot:
create_files(["a/b/__init__.py"])
expected = [join(chroot, "a")] + ["."] + fake_path
assert sys.path == fake_path
with lint.fix_import_path(case):
assert sys.path == expected
assert sys.path == fake_path
示例3: test_types_redefined
def test_types_redefined(linter):
elif_test = osp.join(osp.dirname(osp.abspath(__file__)), 'data',
'bad_builtin.py')
with fix_import_path([elif_test]):
linter.check([elif_test])
msgs = sorted(linter.reporter.messages, key=lambda item: item.line)
assert len(msgs) == 2
for msg, expected in zip(msgs, EXPECTED):
assert msg.symbol == 'bad-builtin'
assert msg.msg == expected
示例4: test_types_redefined
def test_types_redefined(self):
elif_test = osp.join(osp.dirname(osp.abspath(__file__)), 'data',
'bad_builtin.py')
with fix_import_path([elif_test]):
self._linter.check([elif_test])
msgs = sorted(self._linter.reporter.messages, key=lambda item: item.line)
self.assertEqual(len(msgs), 2)
for msg, expected in zip(msgs, self.expected):
self.assertEqual(msg.symbol, 'bad-builtin')
self.assertEqual(msg.msg, expected)
示例5: test_more_args
def test_more_args(fake_path, case):
with tempdir() as chroot:
create_files(['a/b/c/__init__.py', 'a/d/__init__.py', 'a/e/f.py'])
expected = [
join(chroot, suffix)
for suffix in [sep.join(('a', 'b')), 'a', sep.join(('a', 'e'))]
] + ["."] + fake_path
assert sys.path == fake_path
with lint.fix_import_path(case):
assert sys.path == expected
assert sys.path == fake_path
示例6: test_two_similar_args
def test_two_similar_args(self):
with tempdir() as chroot:
create_files(["a/b/__init__.py", "a/c/__init__.py"])
expected = [join(chroot, "a")] + self.fake
cases = (["a/b", "a/c"], ["a/c/", "a/b/"], ["a/b/__init__.py", "a/c/__init__.py"], ["a", "a/c/__init__.py"])
self.assertEqual(sys.path, self.fake)
for case in cases:
with lint.fix_import_path(case):
self.assertEqual(sys.path, expected)
self.assertEqual(sys.path, self.fake)
示例7: check_pylint
def check_pylint(self):
"""
Check using pylint.
"""
options = self.options.get('pylint', self.file_path).copy()
if not options['enabled']:
return
del options['enabled']
if not self._compiled_tree:
# We failed to compile the tree.
return
from pylint.lint import PyLinter, fix_import_path
from pylint.reporters import CollectingReporter
linter = PyLinter()
linter.load_default_plugins()
linter.set_reporter(CollectingReporter())
if options['py3k']:
linter.python3_porting_mode()
del options['py3k']
rcfile = options.get('rcfile', None)
del options['rcfile']
if rcfile:
linter.read_config_file(config_file=rcfile)
linter.load_config_file()
else:
linter.load_configuration_from_config(options)
# PyLint does its own import and parsing, so we only pass the file
# name and the precompiled tree.
with fix_import_path(self.file_path):
linter.check(self.file_path)
for message in linter.reporter.messages:
self.message(
message.line,
'%s:%s %s' % (
message.msg_id,
message.symbol,
message.msg,
),
code=message.msg_id,
icon='info',
category='pylint',
)
示例8: test_more_args
def test_more_args(fake_path, case):
with tempdir() as chroot:
create_files(["a/b/c/__init__.py", "a/d/__init__.py", "a/e/f.py"])
expected = (
[
join(chroot, suffix)
for suffix in [sep.join(("a", "b")), "a", sep.join(("a", "e"))]
]
+ ["."]
+ fake_path
)
assert sys.path == fake_path
with lint.fix_import_path(case):
assert sys.path == expected
assert sys.path == fake_path
示例9: test_two_similar_args
def test_two_similar_args(self):
with tempdir() as chroot:
create_files(['a/b/__init__.py', 'a/c/__init__.py'])
expected = [join(chroot, 'a')] + ["."] + self.fake
cases = (
['a/b', 'a/c'],
['a/c/', 'a/b/'],
['a/b/__init__.py', 'a/c/__init__.py'],
['a', 'a/c/__init__.py'],
)
self.assertEqual(sys.path, self.fake)
for case in cases:
with lint.fix_import_path(case):
self.assertEqual(sys.path, expected)
self.assertEqual(sys.path, self.fake)
示例10: main
def main():
arg_parser = ArgumentParser(
description='Simple extension for pylint to check django projects for '
'common mistakes.')
arg_parser.add_argument('targets', metavar='TARGET', nargs='+',
help='python package or module')
args = arg_parser.parse_args()
linter = lint.PyLinter()
reporters.initialize(linter)
linter._load_reporter()
checkers.register(linter)
with lint.fix_import_path(args.targets):
linter.check(args.targets)
return linter.msg_status
示例11: test_more_args
def test_more_args(self):
with tempdir() as chroot:
create_files(["a/b/c/__init__.py", "a/d/__init__.py", "a/e/f.py"])
expected = [
join(chroot, suffix) for suffix in [sep.join(("a", "b")), "a", sep.join(("a", "e"))]
] + self.fake
cases = (
["a/b/c/__init__.py", "a/d/__init__.py", "a/e/f.py"],
["a/b/c", "a", "a/e"],
["a/b/c", "a", "a/b/c", "a/e", "a"],
)
self.assertEqual(sys.path, self.fake)
for case in cases:
with lint.fix_import_path(case):
self.assertEqual(sys.path, expected)
self.assertEqual(sys.path, self.fake)
示例12: test_more_args
def test_more_args(self):
with tempdir() as chroot:
create_files(['a/b/c/__init__.py', 'a/d/__init__.py', 'a/e/f.py'])
expected = [
join(chroot, suffix)
for suffix in [sep.join(('a', 'b')), 'a', sep.join(('a', 'e'))]
] + ["."] + self.fake
cases = (
['a/b/c/__init__.py', 'a/d/__init__.py', 'a/e/f.py'],
['a/b/c', 'a', 'a/e'],
['a/b/c', 'a', 'a/b/c', 'a/e', 'a'],
)
self.assertEqual(sys.path, self.fake)
for case in cases:
with lint.fix_import_path(case):
self.assertEqual(sys.path, expected)
self.assertEqual(sys.path, self.fake)
示例13: test_no_args
def test_no_args(self):
with lint.fix_import_path([]):
self.assertEqual(sys.path, ["."] + self.fake)
self.assertEqual(sys.path, self.fake)
示例14: test_no_args
def test_no_args(fake_path):
with lint.fix_import_path([]):
assert sys.path == ["."] + fake_path
assert sys.path == fake_path