# Path: supplement/scope.py
# def get_scope_at(project, source, lineno, filename=None, ast_node=None, continous=True):
#     ast_node = ast_node or ast.parse(source)
# 
#     scope = Scope(ast_node, '', None, 'module')
#     scope.project = project
#     scope.filename = filename
#     return scope.get_scope_at(source, lineno, continous)
# 
# Path: supplement/evaluator.py
# def infer(string, scope, lineno=None):
#     tree = ast.parse(string, '<string>', 'eval')
# 
#     if lineno:
#         ast.increment_lineno(tree, lineno-1)
# 
#     return Evaluator().process(tree, scope)
# 
# Path: tests/helpers.py
# def pytest_funcarg__project(request):
#     for crap_module in ('toimport', 'package'):
#         if crap_module in sys.modules:
#             del sys.modules[crap_module]
# 
#     p = Project('.')
#     p.create_module = create_module.__get__(p, Project)
#     p.create_scope = create_scope.__get__(p, Project)
#     p.set_root = set_project_root.__get__(p, Project)
#     return p
# 
# def get_source_and_pos(source):
#     source = cleantabs(source)
#     pos = source.find('|')
#     if pos < 0:
#         pos = len(source)
# 
#     return source.replace('|', ''), pos
# 
# def do_assist(project, source, filename=None):
#     filename = filename or 'test.py'
#     source, pos = get_source_and_pos(source)
#     return assist(project, source, pos, filename)[1]


from supplement.scope import get_scope_at
from supplement.evaluator import infer
from .helpers import pytest_funcarg__project, get_source_and_pos, do_assist
    result = infer('self', scope, 5)
    assert 'window1' in result
    assert 'vbox1' in result

    result = infer('self.window1', scope, 5)
    assert 'set_title' in result

    result = infer('self.vbox1', scope, 5)
    assert 'pack_start' in result

def est_provider_must_resolve_params_of_handlers_defined_in_glade_file(project):
    result = get_proposals(project, 'pass\n\n'
        '   def on_window1_delete_event(self, wnd):\n'
        '       wnd.')
    assert 'set_title' in result

def test_provider_must_allow_to_implement_glade_handlers(project):
    project.register_hook('supplement.hooks.pygtk')
    result = do_assist(project, '''
        class Window(object):
            """glade-file: tests/pygtktest/sample.glade"""

            def on|
    ''')

    assert 'on_window1_delete_event' in result

def test_docbook_hints(project):
    project.register_hook('supplement.hooks.pygtk')


# Path: supplement/scope.py
# def get_scope_at(project, source, lineno, filename=None, ast_node=None, continous=True):
#     ast_node = ast_node or ast.parse(source)
# 
#     scope = Scope(ast_node, '', None, 'module')
#     scope.project = project
#     scope.filename = filename
#     return scope.get_scope_at(source, lineno, continous)
# 
# Path: supplement/evaluator.py
# def infer(string, scope, lineno=None):
#     tree = ast.parse(string, '<string>', 'eval')
# 
#     if lineno:
#         ast.increment_lineno(tree, lineno-1)
# 
#     return Evaluator().process(tree, scope)
# 
# Path: tests/helpers.py
# def pytest_funcarg__project(request):
#     for crap_module in ('toimport', 'package'):
#         if crap_module in sys.modules:
#             del sys.modules[crap_module]
# 
#     p = Project('.')
#     p.create_module = create_module.__get__(p, Project)
#     p.create_scope = create_scope.__get__(p, Project)
#     p.set_root = set_project_root.__get__(p, Project)
#     return p
# 
# def get_source_and_pos(source):
#     source = cleantabs(source)
#     pos = source.find('|')
#     if pos < 0:
#         pos = len(source)
# 
#     return source.replace('|', ''), pos
# 
# def do_assist(project, source, filename=None):
#     filename = filename or 'test.py'
#     source, pos = get_source_and_pos(source)
#     return assist(project, source, pos, filename)[1]


# Path: tests/test_pygtk.py
from supplement.scope import get_scope_at
from supplement.evaluator import infer
from .helpers import pytest_funcarg__project, get_source_and_pos, do_assist

    result = infer('self', scope, 5)
    assert 'window1' in result
    assert 'vbox1' in result

    result = infer('self.window1', scope, 5)
    assert 'set_title' in result

    result = infer('self.vbox1', scope, 5)
    assert 'pack_start' in result

def est_provider_must_resolve_params_of_handlers_defined_in_glade_file(project):
    result = get_proposals(project, 'pass\n\n'
        '   def on_window1_delete_event(self, wnd):\n'
        '       wnd.')
    assert 'set_title' in result

def test_provider_must_allow_to_implement_glade_handlers(project):
    project.register_hook('supplement.hooks.pygtk')
    result = do_assist(project, '''
        class Window(object):
            """glade-file: tests/pygtktest/sample.glade"""

            def on|
    ''')

    assert 'on_window1_delete_event' in result

def test_docbook_hints(project):
    project.register_hook('supplement.hooks.pygtk')


    result = do_assist(project, '''