mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 02:27:06 +08:00
Refactored the parser calls. Now it's possible to use jedi.parser.python.parse to quickly parse something.
This commit is contained in:
@@ -3,8 +3,7 @@ Tests ``from __future__ import absolute_import`` (only important for
|
||||
Python 2.X)
|
||||
"""
|
||||
import jedi
|
||||
from jedi._compatibility import u
|
||||
from jedi.parser import ParserWithRecovery, load_grammar
|
||||
from jedi.parser.python import parse
|
||||
from .. import helpers
|
||||
|
||||
|
||||
@@ -12,16 +11,15 @@ def test_explicit_absolute_imports():
|
||||
"""
|
||||
Detect modules with ``from __future__ import absolute_import``.
|
||||
"""
|
||||
parser = ParserWithRecovery(load_grammar(), u("from __future__ import absolute_import"), "test.py")
|
||||
assert parser.module.has_explicit_absolute_import
|
||||
module = parse("from __future__ import absolute_import")
|
||||
assert module.has_explicit_absolute_import
|
||||
|
||||
|
||||
def test_no_explicit_absolute_imports():
|
||||
"""
|
||||
Detect modules without ``from __future__ import absolute_import``.
|
||||
"""
|
||||
parser = ParserWithRecovery(load_grammar(), u("1"), "test.py")
|
||||
assert not parser.module.has_explicit_absolute_import
|
||||
assert not parse("1").has_explicit_absolute_import
|
||||
|
||||
|
||||
def test_dont_break_imports_without_namespaces():
|
||||
@@ -29,9 +27,8 @@ def test_dont_break_imports_without_namespaces():
|
||||
The code checking for ``from __future__ import absolute_import`` shouldn't
|
||||
assume that all imports have non-``None`` namespaces.
|
||||
"""
|
||||
src = u("from __future__ import absolute_import\nimport xyzzy")
|
||||
parser = ParserWithRecovery(load_grammar(), src, "test.py")
|
||||
assert parser.module.has_explicit_absolute_import
|
||||
src = "from __future__ import absolute_import\nimport xyzzy"
|
||||
assert parse(src).has_explicit_absolute_import
|
||||
|
||||
|
||||
@helpers.cwd_at("test/test_evaluate/absolute_import")
|
||||
|
||||
@@ -8,15 +8,15 @@ from jedi.evaluate.sys_path import (_get_parent_dir_with_file,
|
||||
_check_module)
|
||||
from jedi.evaluate import Evaluator
|
||||
from jedi.evaluate.representation import ModuleContext
|
||||
from jedi.parser import ParserWithRecovery, load_grammar
|
||||
from jedi.parser.python import parse, load_grammar
|
||||
from jedi.parser.parser import ParserWithRecovery
|
||||
|
||||
from ..helpers import cwd_at
|
||||
|
||||
|
||||
def check_module_test(code):
|
||||
grammar = load_grammar()
|
||||
p = ParserWithRecovery(grammar, code)
|
||||
module_context = ModuleContext(Evaluator(grammar), p.module)
|
||||
module_context = ModuleContext(Evaluator(grammar), parse(code))
|
||||
return _check_module(module_context)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from textwrap import dedent
|
||||
|
||||
from jedi._compatibility import builtins, is_py3
|
||||
from jedi.parser import load_grammar
|
||||
from jedi.parser.python import load_grammar
|
||||
from jedi.evaluate import compiled, instance
|
||||
from jedi.evaluate.representation import FunctionContext
|
||||
from jedi.evaluate import Evaluator
|
||||
|
||||
Reference in New Issue
Block a user