|
6 | 6 |
|
7 | 7 | import subprocess |
8 | 8 | from pathlib import Path |
| 9 | +from tomllib import loads |
9 | 10 |
|
10 | 11 | from typer.testing import CliRunner |
11 | 12 |
|
12 | | -pytest_plugins = ['tests.fixtures.example'] |
| 13 | +from cppython.console.schema import ConsoleInterface |
| 14 | +from cppython.core.schema import ProjectConfiguration |
| 15 | +from cppython.project import Project |
| 16 | + |
| 17 | +pytest_plugins = ['tests.fixtures.example', 'tests.fixtures.vcpkg'] |
13 | 18 |
|
14 | 19 |
|
15 | 20 | class TestVcpkgCMake: |
16 | 21 | """Test project variation of vcpkg and CMake""" |
17 | 22 |
|
| 23 | + @staticmethod |
| 24 | + def _create_project(skip_upload: bool = True) -> Project: |
| 25 | + """Create a project instance with common configuration.""" |
| 26 | + project_root = Path.cwd() |
| 27 | + config = ProjectConfiguration(project_root=project_root, version=None, verbosity=2, debug=True) |
| 28 | + interface = ConsoleInterface() |
| 29 | + |
| 30 | + pyproject_path = project_root / 'pyproject.toml' |
| 31 | + pyproject_data = loads(pyproject_path.read_text(encoding='utf-8')) |
| 32 | + |
| 33 | + if skip_upload: |
| 34 | + TestVcpkgCMake._ensure_vcpkg_config(pyproject_data) |
| 35 | + pyproject_data['tool']['cppython']['providers']['vcpkg']['skip_upload'] = True |
| 36 | + |
| 37 | + return Project(config, interface, pyproject_data) |
| 38 | + |
| 39 | + @staticmethod |
| 40 | + def _ensure_vcpkg_config(pyproject_data: dict) -> None: |
| 41 | + """Helper method to ensure Vcpkg configuration exists in pyproject data""" |
| 42 | + if 'tool' not in pyproject_data: |
| 43 | + pyproject_data['tool'] = {} |
| 44 | + if 'cppython' not in pyproject_data['tool']: |
| 45 | + pyproject_data['tool']['cppython'] = {} |
| 46 | + if 'providers' not in pyproject_data['tool']['cppython']: |
| 47 | + pyproject_data['tool']['cppython']['providers'] = {} |
| 48 | + if 'vcpkg' not in pyproject_data['tool']['cppython']['providers']: |
| 49 | + pyproject_data['tool']['cppython']['providers']['vcpkg'] = {} |
| 50 | + |
18 | 51 | @staticmethod |
19 | 52 | def test_simple(example_runner: CliRunner) -> None: |
20 | 53 | """Simple project""" |
21 | | - # By nature of running the test, we require PDM to develop the project and so it will be installed |
22 | | - result = subprocess.run(['pdm', 'install'], capture_output=True, text=True, check=False) |
23 | | - |
24 | | - assert result.returncode == 0, f'PDM install failed: {result.stderr}' |
| 54 | + # Create project and install dependencies |
| 55 | + project = TestVcpkgCMake._create_project(skip_upload=False) |
| 56 | + project.install() |
25 | 57 |
|
26 | 58 | # Run the CMake configuration command |
27 | 59 | result = subprocess.run(['cmake', '--preset=default'], capture_output=True, text=True, check=False) |
|
0 commit comments