Skip to content

Commit

Permalink
Add test for renaming module within package
Browse files Browse the repository at this point in the history
From #159
  • Loading branch information
pappasam committed Aug 22, 2021
1 parent 79bdb90 commit f2c7a5e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repos:
entry: poetry run black --check --diff
language: system
types: [python]
exclude: ^tests/test_data/
- repo: local
hooks:
- id: docformatter
Expand All @@ -21,6 +22,7 @@ repos:
entry: poetry run isort --check
language: system
types: [python]
exclude: ^tests/test_data/
- repo: local
hooks:
- id: toml-sort
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ skip_install = true
commands =
poetry install
!cov: poetry run black --check --diff jedi_language_server tests
!cov: poetry run docformatter --check --recursive jedi_language_server tests
!cov: poetry run isort --check jedi_language_server tests
!cov: poetry run black --extend-exclude test_data --check --diff jedi_language_server tests
!cov: poetry run docformatter --exclude test_data --check --recursive jedi_language_server tests
!cov: poetry run isort --check jedi_language_server tests/lsp_tests tests/lsp_test_client
!cov: poetry run mypy jedi_language_server
!cov: poetry run pylint jedi_language_server tests
Expand Down
54 changes: 54 additions & 0 deletions tests/lsp_tests/test_refactoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,60 @@ def test_rename_package() -> None:
assert_that(actual, is_(expected))


def test_rename_module() -> None:
"""Tests example from the following example.
https://github.com/pappasam/jedi-language-server/issues/159
"""
test_root = REFACTOR_TEST_ROOT
with session.LspSession() as ls_session:
ls_session.initialize()
uri = as_uri(test_root / "rename_module.py")
actual = ls_session.text_document_rename(
{
"textDocument": {"uri": uri},
"position": {"line": 0, "character": 24},
"newName": "new_somemodule",
}
)
old_name_uri = as_uri(test_root / "somepackage" / "somemodule.py")
new_name_uri = as_uri(test_root / "somepackage" / "new_somemodule.py")

expected = {
"documentChanges": [
{
"textDocument": {
"uri": uri,
"version": 0,
},
"edits": [
{
"range": {
"start": {"line": 0, "character": 24},
"end": {"line": 0, "character": 24},
},
"newText": "new_",
},
{
"range": {
"start": {"line": 3, "character": 4},
"end": {"line": 3, "character": 4},
},
"newText": "new_",
},
],
},
{
"kind": "rename",
"oldUri": old_name_uri,
"newUri": new_name_uri,
"options": {"overwrite": True, "ignoreIfExists": True},
},
]
}
assert_that(actual, is_(expected))


def test_lsp_code_action() -> None:
"""Tests code actions like extract variable and extract function."""

Expand Down
4 changes: 4 additions & 0 deletions tests/test_data/refactoring/rename_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from somepackage import somemodule

def run():
somemodule.bar()
Empty file.
2 changes: 2 additions & 0 deletions tests/test_data/refactoring/somepackage/somemodule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def bar():
pass

0 comments on commit f2c7a5e

Please sign in to comment.