diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2023-04-22 22:50:48 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2023-04-22 22:50:48 -0400 |
| commit | efd1913308d0d7dd3af958d4d32a5ba5c642724a (patch) | |
| tree | be37615b097489b59ee1f067841dc363d9f66dc7 /tests/conftest.py | |
| parent | Add basic description and installation instructions (diff) | |
| download | poetry-plugin-taskipy2-efd1913308d0d7dd3af958d4d32a5ba5c642724a.zip | |
Add a small set of basic sanity integration tests
There is still some work to do with testing the IO
Diffstat (limited to 'tests/conftest.py')
| -rw-r--r-- | tests/conftest.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..d75cfc1 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,50 @@ +from pathlib import Path +from typing import Callable + +import pytest +from cleo.io.null_io import NullIO +from cleo.testers.command_tester import CommandTester +from poetry.console.application import Application as PoetryApplication +from poetry.factory import Factory +from poetry.poetry import Poetry + + +@pytest.fixture +def command_tester_factory() -> Callable[[str], CommandTester]: + def _tester(command: str) -> CommandTester: + app = PoetryApplication() + app._load_plugins(NullIO()) + cmd = app.find(command) + tester = CommandTester(cmd) + return tester + + return _tester + + +@pytest.fixture +def execute_task( + command_tester_factory: Callable[[str], CommandTester] +) -> Callable[[str], CommandTester]: + def _execute_task(args: str): + tester = command_tester_factory("task") + tester.execute(args=args) + return tester + + return _execute_task + + +@pytest.fixture +def project_factory(tmp_path: Path): + def _factory( + name: str, + pyproject_content: str, + ) -> Poetry: + project_dir = tmp_path / f"poetry-fixture-{name}" + project_dir.mkdir(parents=True, exist_ok=True) + with project_dir.joinpath("pyproject.toml").open("w", encoding="utf-8") as f: + f.write(pyproject_content) + + poetry = Factory().create_poetry(project_dir) + return poetry + + return _factory |