def test_get_location_for_assigned_names(project): source, pos = get_source_and_pos(''' a = [] print a| ''') line, fname = get_location(project, source, pos, None) assert line == 1 source, pos = get_source_and_pos(''' b = 5 print b| ''') line, fname = get_location(project, source, pos, None) assert line == 1
def test_get_location_must_return_name_location_for_imported_modules(project): source, pos = get_source_and_pos(u''' import sys def foo(): sy|s ''') line, fname = get_location(project, source, pos, 'test.py') assert fname == None assert line == None source, pos = get_source_and_pos(u''' import os o|s ''') line, fname = get_location(project, source, pos, 'test.py') assert fname.endswith('os.py') assert line == 1
def test_get_location_must_return_name_location(project): source, pos = get_source_and_pos(''' def aaa(): pass aa|a() ''') line, fname = get_location(project, source, pos, 'test.py') assert fname == 'test.py' assert line == 1
def test_get_location_must_return_module_location_in_import_statements(project): project.create_module('package.toimport', ''' #cmnt name = 'test' ''') source, pos = get_source_and_pos(''' import packa|ge.module ''') line, fname = get_location(project, source, pos, 'test.py') assert fname == 'package/__init__.py' assert line == 1 source, pos = get_source_and_pos(''' import package.toimpo|rt ''') line, fname = get_location(project, source, pos, 'test.py') assert fname == 'package/toimport.py' assert line == 1 source, pos = get_source_and_pos(''' from pack|age import toimport ''') line, fname = get_location(project, source, pos, 'test.py') assert fname == 'package/__init__.py' assert line == 1 source, pos = get_source_and_pos(''' from package import toim|port ''') line, fname = get_location(project, source, pos, 'test.py') assert fname == 'package/toimport.py' assert line == 1 source, pos = get_source_and_pos(''' from package.toimport import na|me ''') line, fname = get_location(project, source, pos, 'test.py') assert fname == 'package/toimport.py' assert line == 2
def test_get_location_must_return_name_location_for_imported_names(project): project.create_module('toimport', ''' def aaa(): pass ''') source, pos = get_source_and_pos(u''' import toimport toimport.aa|a() ''') line, fname = get_location(project, source, pos, 'test.py') assert fname == 'toimport.py' assert line == 1
def get_location(self, path, source, position, filename): return get_location(self.get_project(path), source, position, filename)