Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Move rope_patch.py to utils/introspection #3853

Merged
merged 6 commits into from
Dec 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2814,23 +2814,15 @@ def exec_():
from qtpy import QtWidgets
QtWidgets.QApplication = FakeQApplication

#----Monkey patching rope
try:
from spyder import rope_patch
rope_patch.apply()
except ImportError:
# rope is not installed
pass

#----Monkey patching sys.exit
# ----Monkey patching sys.exit
def fake_sys_exit(arg=[]):
pass
sys.exit = fake_sys_exit

#----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
# ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
if PYQT5:
def spy_excepthook(type_, value, tback):
sys.__excepthook__(type_, value, tback)
sys.__excepthook__(type_, value, tback)
sys.excepthook = spy_excepthook

# Removing arguments from sys.argv as in standard Python interpreter
Expand Down
File renamed without changes.
38 changes: 1 addition & 37 deletions spyder/utils/introspection/rope_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

try:
try:
from spyder import rope_patch
from spyder.utils.introspection import rope_patch
rope_patch.apply()
except ImportError:
# rope is not installed
Expand Down Expand Up @@ -281,39 +281,3 @@ def close_rope_project(self):
"""Close the Rope project"""
if self.project is not None:
self.project.close()


if __name__ == '__main__':

from spyder.utils.introspection.manager import CodeInfo

p = RopePlugin()
p.load_plugin()

source_code = "import numpy; numpy.ones"
docs = p.get_info(CodeInfo('info', source_code, len(source_code),
__file__))
assert 'ones(' in docs['calltip'] and 'ones(' in docs['docstring']

source_code = "import numpy; n"
completions = p.get_completions(CodeInfo('completions', source_code,
len(source_code), __file__))
assert ('numpy', 'module') in completions

source_code = "import a"
completions = p.get_completions(CodeInfo('completions', source_code,
len(source_code), __file__))
assert not completions

code = '''
def test(a, b):
"""Test docstring"""
pass
test(1,'''
path, line = p.get_definition(CodeInfo('definition', code, len(code),
'dummy.txt', is_python_like=True))
assert line == 2

docs = p.get_info(CodeInfo('info', code, len(code), __file__,
is_python_like=True))
assert 'Test docstring' in docs['docstring']
67 changes: 67 additions & 0 deletions spyder/utils/introspection/test/test_rope_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License

"""Tests for jedi_plugin.py"""

from textwrap import dedent

import pytest

from spyder.utils.introspection.manager import CodeInfo
from spyder.utils.introspection import rope_plugin

p = rope_plugin.RopePlugin()
p.load_plugin()


try:
import numpy
except ImportError:
numpy = None


@pytest.mark.skipif(not numpy, reason="Numpy required")
def test_get_info():
source_code = "import numpy; numpy.ones"
docs = p.get_info(CodeInfo('info', source_code, len(source_code), __file__))
assert docs['calltip'].startswith('ones(') and docs['name'] == 'ones'


@pytest.mark.skipif(not numpy, reason="Numpy required")
def test_get_completions_1():
source_code = "import numpy; n"
completions = p.get_completions(CodeInfo('completions', source_code,
len(source_code), __file__))
assert ('numpy', 'module') in completions


def test_get_completions_2():
source_code = "import a"
completions = p.get_completions(CodeInfo('completions', source_code,
len(source_code), __file__))
assert not completions


def test_get_definition():
source_code = "import os; os.walk"
path, line_nr = p.get_definition(CodeInfo('definition', source_code,
len(source_code), __file__))
assert 'os.py' in path


def test_get_docstring():
source_code = dedent('''
def test(a, b):
"""Test docstring"""
pass
test(1,''')
path, line = p.get_definition(CodeInfo('definition', source_code,
len(source_code), 'dummy.txt',
is_python_like=True))
assert 'dummy' in path and line == 2

docs = p.get_info(CodeInfo('info', source_code, len(source_code),
__file__, is_python_like=True))
assert 'Test docstring' in docs['docstring']