From efd1913308d0d7dd3af958d4d32a5ba5c642724a Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 22 Apr 2023 22:50:48 -0400 Subject: Add a small set of basic sanity integration tests There is still some work to do with testing the IO --- tests/conftest.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/conftest.py (limited to 'tests/conftest.py') 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 -- cgit v1.2.3