本文整理汇总了Python中importmagic.symbols.Scope类的典型用法代码示例。如果您正苦于以下问题:Python Scope类的具体用法?Python Scope怎么用?Python Scope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_symbol_from_argument_defaults
def test_symbol_from_argument_defaults():
src = dedent("""
def f(a, b=os.path, c=os): pass
""")
symbols, _ = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert symbols == set(['os.path', 'os'])
示例2: test_symbol_from_decorator
def test_symbol_from_decorator():
src = dedent("""
@foo.bar(a=waz)
def bar(): pass
""")
symbols, _ = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert symbols == set(['foo.bar', 'waz'])
示例3: test_import_future_preserved
def test_import_future_preserved(index):
src = 'from __future__ import absolute_import'
unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert not unresolved
assert not unreferenced
new_src = update_imports(src, index, unresolved, unreferenced).strip()
assert src == new_src
示例4: test_from_import_as
def test_from_import_as(index):
src = dedent('''
from clastic import MiddleWare as WebMiddleWare
''').strip()
scope = Scope.from_source(src)
new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols())
assert src == new_src.strip()
示例5: test_importer_directives_not_referenced
def test_importer_directives_not_referenced(index):
src = dedent('''
# Make sure the in thread reactor is installed.
from Tribler.Core.Utilities.twisted_thread import reactor
# importmagic: manage
import re
import sys
print(os.path.basename('moo'))
''').strip()
expected_src = dedent('''
# Make sure the in thread reactor is installed.
from Tribler.Core.Utilities.twisted_thread import reactor
# importmagic: manage
import os.path
print(os.path.basename('moo'))
''').strip()
scope = Scope.from_source(src)
new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols()).strip()
assert expected_src == new_src
示例6: test_accepts_unicode_strings
def test_accepts_unicode_strings():
src = dedent(u("""
# coding: utf-8
foo
""")).strip()
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['foo'])
示例7: test_referenced_symbols_from_decorated_function
def test_referenced_symbols_from_decorated_function():
src = dedent("""
@foo.bar
def bar():
print(waz)
print(baz)
""")
symbols, _ = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert symbols == set(['foo.bar', 'waz', 'baz'])
示例8: test_annotations_without_imports
def test_annotations_without_imports():
src = dedent("""
def print_it(it: Iterable):
for i in it:
method1(i)
print_it(['a', 'b', 'c'])
""")
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['method1', 'Iterable'])
assert unreferenced == set([])
示例9: test_annotations_with_imports
def test_annotations_with_imports():
src = dedent("""
from typing import Iterable
def print_it(it: Iterable):
for i in it:
print(i)
""")
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set([])
assert unreferenced == set(['print_it'])
示例10: test_annotations_return_type
def test_annotations_return_type():
# https://www.python.org/dev/peps/pep-3107/
src = dedent("""
def foo(a) -> CustomType:
print(a)
foo()
""")
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['CustomType'])
assert unreferenced == set([])
示例11: test_annotations_complex
def test_annotations_complex():
# https://www.python.org/dev/peps/pep-3107/
src = dedent("""
def foo(a: 'x', b: 5 + 6, c: list, \
d: Iterable, e: CustomType) -> max(2, 9):
print(a)
foo()
""")
scope = Scope.from_source(src)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['Iterable', 'CustomType'])
assert unreferenced == set([])
示例12: test_update_imports_correctly_aliases
def test_update_imports_correctly_aliases(index):
src = dedent('''
print(basename('src/foo'))
''').strip()
unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['basename'])
new_src = update_imports(src, index, unresolved, unreferenced)
assert dedent('''
from os.path import basename
print(basename('src/foo'))
''').strip() == new_src
示例13: test_deep_import_of_unknown_symbol
def test_deep_import_of_unknown_symbol(index):
src = dedent("""
print(os.unknown('/'))
""").strip()
unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
assert unresolved == set(['os.unknown'])
new_src = update_imports(src, index, unresolved, unreferenced)
assert dedent("""
import os
print(os.unknown('/'))
""").strip() == new_src
示例14: test_get_update
def test_get_update(index):
src = dedent("""
# header comment
import sys
print(os.unknown('/'))
""").strip()
unresolved, unreferenced = Scope.from_source(src).find_unresolved_and_unreferenced_symbols()
start_line, end_line, new_block = get_update(src, index, unresolved, unreferenced)
assert dedent("""\
import os
""").lstrip() == new_block
示例15: test_imports_module_assignment
def test_imports_module_assignment(index):
src = dedent('''
def func(n):
sys.stderr = n
''').strip()
scope = Scope.from_source(src)
new_src = update_imports(src, index, *scope.find_unresolved_and_unreferenced_symbols())
assert dedent('''
import sys
def func(n):
sys.stderr = n
''').strip() == new_src.strip()