From 9d9fd484915a039c884cb1d63fdf928ddd5ccd10 Mon Sep 17 00:00:00 2001 From: "Leandro G. Almeida" Date: Thu, 1 Dec 2022 18:05:15 -0600 Subject: [PATCH] Test for rename cmd (#7) --- .editorconfig | 1 + .github/workflows/main.yml | 2 +- README.md | 6 +-- config/.isort.cfg | 5 ++- config/flake8.ini | 2 +- config/pytest.ini | 2 +- docs/nav.md | 14 +++---- poetry.lock | 40 +++++++++---------- pyproject.toml | 2 +- src/asunder/command/cli.py | 1 - src/asunder/command/rename_cmd.py | 21 +++++----- src/asunder/project/project.py | 2 +- src/asunder/rope_sdk/__init__.py | 2 +- src/asunder/rope_sdk/find/find.py | 22 ++++++---- src/asunder/rope_sdk/refactor/__init__.py | 0 .../rope_sdk/refactor/rename/rename.py | 35 +++++++++++----- src/asunder/utils/logging.py | 20 +++++----- test_data/test_package/__init__.py | 0 test_data/test_package/module1/__init__.py | 0 test_data/test_package/module1/subMOM.py | 4 ++ test_data/test_package/module1/submodule1.py | 4 ++ test_data/test_package/module2/__init__.py | 0 test_data/test_package/module2/submodule2.py | 8 ++++ tests/conftest.py | 20 ++++++++++ tests/test_app/conftest.py | 0 tests/test_app/test_app.py | 22 ++++++++-- tests/test_app/test_rename.py | 35 ++++++++++++++++ 27 files changed, 188 insertions(+), 82 deletions(-) create mode 100644 src/asunder/rope_sdk/refactor/__init__.py create mode 100644 test_data/test_package/__init__.py create mode 100644 test_data/test_package/module1/__init__.py create mode 100644 test_data/test_package/module1/subMOM.py create mode 100644 test_data/test_package/module1/submodule1.py create mode 100644 test_data/test_package/module2/__init__.py create mode 100644 test_data/test_package/module2/submodule2.py create mode 100644 tests/test_app/conftest.py create mode 100644 tests/test_app/test_rename.py diff --git a/.editorconfig b/.editorconfig index 25c51c1..7f2bd26 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,7 @@ end_of_line = lf [*.md] trim_trailing_whitespace = false +indent_size = 2 [Makefile] indent_style = tab diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2e213fe..365618d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,7 +57,7 @@ jobs: env: CC_TEST_REPORTER_ID: ${{secrets.REPORTER_ID}} with: - prefix: src/ + prefix: ${{github.workspace}} coverageLocations: | ${{github.workspace}}/.coverage/:coverage.py ${{github.workspace}}/coverage.xml/:coverage.py \ No newline at end of file diff --git a/README.md b/README.md index b5a546f..15e45b3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1 @@ -[![Maintainability](https://api.codeclimate.com/v1/badges/67d0f7c0715d81bef5f9/maintainability)](https://codeclimate.com/github/lalmei/asunder/maintainability) - -[![Test Coverage](https://api.codeclimate.com/v1/badges/67d0f7c0715d81bef5f9/test_coverage)](https://codeclimate.com/github/lalmei/asunder/test_coverage) - - +[![asunder](https://github.com/lalmei/asunder/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/lalmei/asunder/actions/workflows/main.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/67d0f7c0715d81bef5f9/maintainability)](https://codeclimate.com/github/lalmei/asunder/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/67d0f7c0715d81bef5f9/test_coverage)](https://codeclimate.com/github/lalmei/asunder/test_coverage) diff --git a/config/.isort.cfg b/config/.isort.cfg index b2effad..7345aae 100644 --- a/config/.isort.cfg +++ b/config/.isort.cfg @@ -1,5 +1,6 @@ -[settings] -line_length = 80 +[tool.isort] +line_length = 79 +profile = "black" multi_line_output = 3 balanced_wrapping = true default_section = "THIRDPARTY" diff --git a/config/flake8.ini b/config/flake8.ini index 272c88c..b987841 100644 --- a/config/flake8.ini +++ b/config/flake8.ini @@ -4,7 +4,7 @@ classmethod-decorators = validator exclude = fixtures,docs,site show-source = true -max-line-length = 80 +max-line-length = 100 statistics = True docstring-convention = google ban-relative-imports = true diff --git a/config/pytest.ini b/config/pytest.ini index 522633a..d3b6b3f 100644 --- a/config/pytest.ini +++ b/config/pytest.ini @@ -12,6 +12,6 @@ python_files = test_*.py testpaths = ./tests/* -addopts = -v --cov-config=./config/coverage.ini --cov=./src --cov-report=xml --cov-report=term-missing +addopts = -v --cov-config=./config/coverage.ini --cov=./src --cov-report=xml --cov-report=html --cov-report=term-missing diff --git a/docs/nav.md b/docs/nav.md index e18909c..fa697d6 100644 --- a/docs/nav.md +++ b/docs/nav.md @@ -1,8 +1,8 @@ * [Overview](index.md) -* Initial Setup - * [Get Started](get_started.md) -* Basic Usage - * [Refactoring](basic_usage/refactoring.md) -* [Help & Get Help](help.md) -* [Release Notes](changelog.md) -* [Code Reference](reference/) + * Initial Setup + * [Get Started](get_started.md) + * Basic Usage + * [Refactoring](basic_usage/refactoring.md) + * [Help & Get Help](help.md) + * [Release Notes](changelog.md) + * [Code Reference](reference/) diff --git a/poetry.lock b/poetry.lock index 068dd20..1779ff4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -22,14 +22,14 @@ tests-no-zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy [[package]] name = "autoflake" -version = "1.7.7" +version = "1.7.8" description = "Removes unused imports and unused variables" category = "dev" optional = false python-versions = ">=3.7" [package.dependencies] -pyflakes = ">=1.1.0" +pyflakes = ">=1.1.0,<3" tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} [[package]] @@ -378,7 +378,7 @@ test = ["mkdocs-include-markdown-plugin", "mkdocs-macros-test", "mkdocs-material [[package]] name = "mkdocs-material" -version = "8.5.10" +version = "8.5.11" description = "Documentation that simply works" category = "dev" optional = false @@ -545,7 +545,7 @@ plugins = ["importlib-metadata"] [[package]] name = "pymdown-extensions" -version = "9.8" +version = "9.9" description = "Extension pack for Python Markdown." category = "dev" optional = false @@ -684,7 +684,7 @@ jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"] [[package]] name = "rope" -version = "1.5.0" +version = "1.5.1" description = "a python refactoring library..." category = "main" optional = false @@ -699,7 +699,7 @@ doc = ["pytoolconfig[doc]", "sphinx (>=4.5.0)", "sphinx-autodoc-typehints (>=1.1 [[package]] name = "setuptools" -version = "65.6.0" +version = "65.6.3" description = "Easily download, build, install, upgrade, and uninstall Python packages" category = "dev" optional = false @@ -783,11 +783,11 @@ python-versions = ">=3.7" [[package]] name = "urllib3" -version = "1.26.12" +version = "1.26.13" description = "HTTP library with thread-safe connection pooling, file post, and more." category = "dev" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" [package.extras] brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] @@ -820,8 +820,8 @@ attrs = [ {file = "attrs-22.1.0.tar.gz", hash = "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6"}, ] autoflake = [ - {file = "autoflake-1.7.7-py3-none-any.whl", hash = "sha256:a9b43d08f8e455824e4f7b3f078399f59ba538ba53872f466c09e55c827773ef"}, - {file = "autoflake-1.7.7.tar.gz", hash = "sha256:c8e4fc41aa3eae0f5c94b939e3a3d50923d7a9306786a6cbf4866a077b8f6832"}, + {file = "autoflake-1.7.8-py3-none-any.whl", hash = "sha256:46373ef69b6714f5064c923bb28bd797c4f8a9497f557d87fc36665c6d956b39"}, + {file = "autoflake-1.7.8.tar.gz", hash = "sha256:e7e46372dee46fa1c97acf310d99d922b63d369718a270809d7c278d34a194cf"}, ] black = [ {file = "black-22.10.0-1fixedarch-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:5cc42ca67989e9c3cf859e84c2bf014f6633db63d1cbdf8fdb666dcd9e77e3fa"}, @@ -1044,8 +1044,8 @@ mkdocs-macros-plugin = [ {file = "mkdocs_macros_plugin-0.7.0-py3-none-any.whl", hash = "sha256:96bdabeb98b96139544f0048ea2f5cb80c7befde6b21e94c6d4596c22774cbcf"}, ] mkdocs-material = [ - {file = "mkdocs_material-8.5.10-py3-none-any.whl", hash = "sha256:51760fa4c9ee3ca0b3a661ec9f9817ec312961bb84ff19e5b523fdc5256e1d6c"}, - {file = "mkdocs_material-8.5.10.tar.gz", hash = "sha256:7623608f746c6d9ff68a8ef01f13eddf32fa2cae5e15badb251f26d1196bc8f1"}, + {file = "mkdocs_material-8.5.11-py3-none-any.whl", hash = "sha256:c907b4b052240a5778074a30a78f31a1f8ff82d7012356dc26898b97559f082e"}, + {file = "mkdocs_material-8.5.11.tar.gz", hash = "sha256:b0ea0513fd8cab323e8a825d6692ea07fa83e917bb5db042e523afecc7064ab7"}, ] mkdocs-material-extensions = [ {file = "mkdocs_material_extensions-1.1.1-py3-none-any.whl", hash = "sha256:e41d9f38e4798b6617ad98ca8f7f1157b1e4385ac1459ca1e4ea219b556df945"}, @@ -1128,8 +1128,8 @@ pygments = [ {file = "Pygments-2.13.0.tar.gz", hash = "sha256:56a8508ae95f98e2b9bdf93a6be5ae3f7d8af858b43e02c5a2ff083726be40c1"}, ] pymdown-extensions = [ - {file = "pymdown_extensions-9.8-py3-none-any.whl", hash = "sha256:8e62688a8b1128acd42fa823f3d429d22f4284b5e6dd4d3cd56721559a5a211b"}, - {file = "pymdown_extensions-9.8.tar.gz", hash = "sha256:1bd4a173095ef8c433b831af1f3cb13c10883be0c100ae613560668e594651f7"}, + {file = "pymdown_extensions-9.9-py3-none-any.whl", hash = "sha256:ac698c15265680db5eb13cd4342abfcde2079ac01e5486028f47a1b41547b859"}, + {file = "pymdown_extensions-9.9.tar.gz", hash = "sha256:0f8fb7b74a37a61cc34e90b2c91865458b713ec774894ffad64353a5fce85cfc"}, ] pyparsing = [ {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, @@ -1206,12 +1206,12 @@ rich = [ {file = "rich-12.6.0.tar.gz", hash = "sha256:ba3a3775974105c221d31141f2c116f4fd65c5ceb0698657a11e9f295ec93fd0"}, ] rope = [ - {file = "rope-1.5.0-py3-none-any.whl", hash = "sha256:32a19332df0e40c14092ae35226c3d1f0c15ee2462ca2ce4b9936b8fd45f100d"}, - {file = "rope-1.5.0.tar.gz", hash = "sha256:45744d125f7db569b118ed487f08ab72f67fbef0b8441d02df2b756121f35942"}, + {file = "rope-1.5.1-py3-none-any.whl", hash = "sha256:d0514b3cddb1a9e103a040756fb53674828d73df70282b7d7d783a220b0354d8"}, + {file = "rope-1.5.1.tar.gz", hash = "sha256:9761758c222df9466f08232bc046d182960ffa881c1c53bca9fafff210e8da7c"}, ] setuptools = [ - {file = "setuptools-65.6.0-py3-none-any.whl", hash = "sha256:6211d2f5eddad8757bd0484923ca7c0a6302ebc4ab32ea5e94357176e0ca0840"}, - {file = "setuptools-65.6.0.tar.gz", hash = "sha256:d1eebf881c6114e51df1664bc2c9133d022f78d12d5f4f665b9191f084e2862d"}, + {file = "setuptools-65.6.3-py3-none-any.whl", hash = "sha256:57f6f22bde4e042978bcd50176fdb381d7c21a9efa4041202288d3737a0c6a54"}, + {file = "setuptools-65.6.3.tar.gz", hash = "sha256:a7620757bf984b58deaf32fc8a4577a9bbc0850cf92c20e1ce41c38c19e5fb75"}, ] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, @@ -1238,8 +1238,8 @@ typing-extensions = [ {file = "typing_extensions-4.4.0.tar.gz", hash = "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa"}, ] urllib3 = [ - {file = "urllib3-1.26.12-py2.py3-none-any.whl", hash = "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"}, - {file = "urllib3-1.26.12.tar.gz", hash = "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e"}, + {file = "urllib3-1.26.13-py2.py3-none-any.whl", hash = "sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc"}, + {file = "urllib3-1.26.13.tar.gz", hash = "sha256:c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8"}, ] watchdog = [ {file = "watchdog-2.1.9-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:a735a990a1095f75ca4f36ea2ef2752c99e6ee997c46b0de507ba40a09bf7330"}, diff --git a/pyproject.toml b/pyproject.toml index 74f331a..b83e7cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,4 +51,4 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.black] -line-length = 80 \ No newline at end of file +line-length = 79 \ No newline at end of file diff --git a/src/asunder/command/cli.py b/src/asunder/command/cli.py index a91a80f..435e17f 100644 --- a/src/asunder/command/cli.py +++ b/src/asunder/command/cli.py @@ -9,7 +9,6 @@ import typer from rich import box from rich.console import Console -from rich.logging import RichHandler from rich.panel import Panel from asunder._version import version_info diff --git a/src/asunder/command/rename_cmd.py b/src/asunder/command/rename_cmd.py index 6db6b55..40790a3 100644 --- a/src/asunder/command/rename_cmd.py +++ b/src/asunder/command/rename_cmd.py @@ -1,5 +1,4 @@ import logging -import os from pathlib import Path from typing import Optional @@ -18,33 +17,31 @@ @app.command(no_args_is_help=True) def rename( ctx: Context, - path: Path = typer.Option( - Path.cwd() / "src", help="path to package source code" - ), - module: str = typer.Argument( - "", help='module where renaming will take placed, e.g. "package.module"' + path: Path = typer.Option(Path.cwd(), help="path to package source code"), + module: Path = typer.Option( + "", + help='module where renaming will take placed, e.g. "package.module"', ), old_name: Optional[str] = typer.Option( "", help="old name of module/class/attribute" ), - name: str = typer.Argument("", help="new module/class/attribute name"), + new_name: str = typer.Option("", help="new module/class/attribute name"), ) -> None: if not old_name: - old_name = module + old_name = str(module) dry_run = ctx.obj.get("dry_run", True) logger, console = get_logger_console() - project = Project(path=Path.cwd(), console=console) + project = Project(path=path, console=console) # module to folder - module = os.path.join(*module.split(".")) - name = os.path.join(*name.split(".")) + # module = os.path.join(*module.split(".")) logger.info("Calculating Changes") # compute changes needed - changes = rename_changes(project.rope_project, module, old_name, name) + changes = rename_changes(project.rope_project, module, old_name, new_name) if not dry_run: logger.info("Perfoming Changes") diff --git a/src/asunder/project/project.py b/src/asunder/project/project.py index ec023e4..c96872f 100644 --- a/src/asunder/project/project.py +++ b/src/asunder/project/project.py @@ -13,7 +13,7 @@ def __init__( self, path: Path = Path.cwd(), console: Console = Console() ) -> None: - self.rope_project = RopeProject(str(path / "src")) + self.rope_project = RopeProject(str(path)) self.console = console def perform_changes(self, changes: ChangeSet, dry_run: bool) -> None: diff --git a/src/asunder/rope_sdk/__init__.py b/src/asunder/rope_sdk/__init__.py index d3187a7..80b213b 100644 --- a/src/asunder/rope_sdk/__init__.py +++ b/src/asunder/rope_sdk/__init__.py @@ -1,3 +1,3 @@ from asunder.rope_sdk.refactor.rename.rename import rename, rename_module -__all__: list[str] = ["rename_module, rename"] +__all__: list[str] = ["rename_module", "rename"] diff --git a/src/asunder/rope_sdk/find/find.py b/src/asunder/rope_sdk/find/find.py index 87b3802..f8ad5be 100644 --- a/src/asunder/rope_sdk/find/find.py +++ b/src/asunder/rope_sdk/find/find.py @@ -1,14 +1,20 @@ +from functools import partial +from typing import Optional + from rope.base.project import Project as RopeProject -from rope.refactor.occurrences import Finder +from rope.refactor.occurrences import Finder, Occurrence + +from asunder.utils.logging import get_logger_console def find_definition_in_resource( - repo_project: RopeProject, name: str, resource: str -): + repo_project: RopeProject, name: Optional[str], resource: Optional[str] +) -> Occurrence: FINDER = partial(Finder, repo_project) finder = FINDER(name) - return next( - occ - for occ in finder.find_occurrences(resource=resource) - if occ.is_defined() or occ.is_written() - ) + logger, console = get_logger_console() + console.print(finder.find_occurrences(resource=resource)) + for occ in finder.find_occurrences(resource=resource): + console.print(occ) + if occ.is_defined(): + return occ diff --git a/src/asunder/rope_sdk/refactor/__init__.py b/src/asunder/rope_sdk/refactor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/asunder/rope_sdk/refactor/rename/rename.py b/src/asunder/rope_sdk/refactor/rename/rename.py index b840fe7..15717a3 100644 --- a/src/asunder/rope_sdk/refactor/rename/rename.py +++ b/src/asunder/rope_sdk/refactor/rename/rename.py @@ -1,28 +1,45 @@ import logging +from pathlib import Path +from typing import Optional from rope.base.change import ChangeSet from rope.base.project import Project as RopeProject from rope.refactor.rename import Rename from asunder.rope_sdk.find import find_definition_in_resource +from asunder.utils.logging import get_logger_console logger = logging.getLogger("asunder") def rename_module( - rope_project: RopeProject, module: str, to_name: str + rope_project: RopeProject, module: Optional[str], to_name: Optional[str] ) -> ChangeSet: module_resource = rope_project.get_resource(module) return Rename(rope_project, module_resource).get_changes(to_name) def rename( - rope_project: RopeProject, module: str, from_name: str, to_name: str + rope_project: RopeProject, + resource: Path, + from_name: Optional[str], + to_name: Optional[str], ) -> ChangeSet: - module_resource = rope_project.get_resource(module) - definition_occurrence = find_definition_in_resource( - rope_project, from_name, module_resource - ) - return Rename( - rope_project, module_resource, definition_occurrence.offset - ).get_changes(to_name) + module_resource = rope_project.get_resource(str(resource)) + logger, console = get_logger_console() + # console.print(dir(module_resource)) + if module_resource.is_folder(): + if from_name in [ + Path(x._path).stem for x in module_resource.get_files() + ]: + new_resource = resource / Path(from_name + ".py") + changes = rename_module(rope_project, str(new_resource), to_name) + return changes + + else: + definition_occurrence = find_definition_in_resource( + rope_project, from_name, module_resource + ) + return Rename( + rope_project, module_resource, definition_occurrence.offset + ).get_changes(to_name) diff --git a/src/asunder/utils/logging.py b/src/asunder/utils/logging.py index 1d1493f..8fd8108 100644 --- a/src/asunder/utils/logging.py +++ b/src/asunder/utils/logging.py @@ -23,7 +23,10 @@ def _set_up_logger(console: Optional[Console] = None) -> Logger: if not console: console = Console() module_logger = getLogger("asunder") - module_logger.addHandler(RichHandler(rich_tracebacks=True, console=console)) + + rich_handler = RichHandler(rich_tracebacks=True, console=console) + rich_handler.set_name("rich") + module_logger.addHandler(rich_handler) module_logger.setLevel(level=WARNING) return module_logger @@ -39,13 +42,12 @@ def get_logger_console( logger = getLogger("asunder") if len(logger.handlers) > 0: - handler: RichHandler = cast(RichHandler, logger.handlers[0]) - console = handler.console - print( - "handler names = ", [handle.__dict__ for handle in logger.handlers] - ) - else: - logger = _set_up_logger(console) - logger.debug("Setting up rich log handler") + if logger.handlers[0].get_name() == "rich": + handler: RichHandler = cast(RichHandler, logger.handlers[0]) + console = handler.console + return logger, console + + logger = _set_up_logger(console) + logger.debug("Setting up rich log handler") return logger, console diff --git a/test_data/test_package/__init__.py b/test_data/test_package/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_data/test_package/module1/__init__.py b/test_data/test_package/module1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_data/test_package/module1/subMOM.py b/test_data/test_package/module1/subMOM.py new file mode 100644 index 0000000..c18d640 --- /dev/null +++ b/test_data/test_package/module1/subMOM.py @@ -0,0 +1,4 @@ +def my_function(): + myresult = 1 + 1 + + return myresult diff --git a/test_data/test_package/module1/submodule1.py b/test_data/test_package/module1/submodule1.py new file mode 100644 index 0000000..c18d640 --- /dev/null +++ b/test_data/test_package/module1/submodule1.py @@ -0,0 +1,4 @@ +def my_function(): + myresult = 1 + 1 + + return myresult diff --git a/test_data/test_package/module2/__init__.py b/test_data/test_package/module2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_data/test_package/module2/submodule2.py b/test_data/test_package/module2/submodule2.py new file mode 100644 index 0000000..b302af6 --- /dev/null +++ b/test_data/test_package/module2/submodule2.py @@ -0,0 +1,8 @@ +from ..module1.submodule1 import my_function + + +def my_second_function(vars): + + super_secret = 5 + vars + + return my_function() + super_secret diff --git a/tests/conftest.py b/tests/conftest.py index cba5adb..b947c71 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1 +1,21 @@ """Configuration to point to pytest fixtures.""" +import shutil +from pathlib import Path + +import pytest + + +@pytest.fixture() +def template_def_path(tmp_path: Path) -> Path: + """Return path to original template files. + + Returns + ------- + Path + path to original template files + """ + + current_path = Path(__file__).parent.parent / "test_data" / "test_package" + shutil.copytree(current_path, tmp_path / "test_package") + print(tmp_path / "test_package") + return tmp_path diff --git a/tests/test_app/conftest.py b/tests/test_app/conftest.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_app/test_app.py b/tests/test_app/test_app.py index a40ff0c..9191d4c 100644 --- a/tests/test_app/test_app.py +++ b/tests/test_app/test_app.py @@ -21,9 +21,7 @@ def test_parse_args() -> None: """ test verbose mode """ - verbose_check = re.compile( - r"\[[\w*\S*\s*]*\] (INFO Setting verbose mode ON)" - ) + verbose_check = re.compile(r"\[[\w*\W*]*\] (INFO Setting verbose mode ON)") result = runner.invoke(app, ["--verbose"], input="") console.print(result.stdout) @@ -31,6 +29,18 @@ def test_parse_args() -> None: assert verbose_check.search(result.stdout, 0) +def test_parse_args_second() -> None: + """ + test verbose mode + """ + verbose_check = re.compile(r"\w* (INFO Setting verbose mode ON)") + + result = runner.invoke(app, ["--verbose", "refactor", "rename"], input="") + console.print(result.stdout) + assert result.exit_code == 0 + assert verbose_check.search(result.stdout, 0) + + def test_unknown_command() -> None: """ test a wrong command @@ -42,3 +52,9 @@ def test_unknown_command() -> None: console.print(result.stdout) assert result.exit_code == 2 assert default_help in result.stdout + + +def test_import_main() -> None: + """ + test a wrong command + """ diff --git a/tests/test_app/test_rename.py b/tests/test_app/test_rename.py new file mode 100644 index 0000000..b7acc7e --- /dev/null +++ b/tests/test_app/test_rename.py @@ -0,0 +1,35 @@ +from pathlib import Path + +from rich.console import Console +from typer.testing import CliRunner + +from asunder import app + +console = Console() +runner = CliRunner() + + +def test_refactor(template_def_path: Path) -> None: + """Test version call.""" + + test_package_path = str(template_def_path) + console.print(test_package_path) + result = runner.invoke( + app, + [ + "--dry-run", + "refactor", + "rename", + "--path", + test_package_path, + "--module", + "test_package/module1", + "--old-name", + "submodule1", + "--new-name", + "subMOM", + ], + input="", + ) + console.print(result.stdout) + assert result.exit_code == 0