55"""
66
77import subprocess
8+ import tomllib
89from pathlib import Path
910from tomllib import loads
1011
1415from cppython .core .schema import ProjectConfiguration
1516from cppython .project import Project
1617
17- pytest_plugins = ['tests.fixtures.example' , 'tests.fixtures.conan' ]
18+ pytest_plugins = ['tests.fixtures.example' , 'tests.fixtures.conan' , 'tests.fixtures.cmake' ]
1819
1920
2021class TestConanCMake :
@@ -37,15 +38,23 @@ def _create_project(skip_upload: bool = True) -> Project:
3738 return Project (config , interface , pyproject_data )
3839
3940 @staticmethod
40- def _run_cmake_configure () -> None :
41- """Run CMake configuration and assert success."""
42- result = subprocess .run (['cmake' , '--preset=default' ], capture_output = True , text = True , check = False )
41+ def _run_cmake_configure (cmake_binary : str ) -> None :
42+ """Run CMake configuration and assert success.
43+
44+ Args:
45+ cmake_binary: Path or command name for the CMake binary to use
46+ """
47+ result = subprocess .run ([cmake_binary , '--preset=default' ], capture_output = True , text = True , check = False )
4348 assert result .returncode == 0 , f'CMake configuration failed: { result .stderr } '
4449
4550 @staticmethod
46- def _run_cmake_build () -> None :
47- """Run CMake build and assert success."""
48- result = subprocess .run (['cmake' , '--build' , 'build' ], capture_output = True , text = True , check = False )
51+ def _run_cmake_build (cmake_binary : str ) -> None :
52+ """Run CMake build and assert success.
53+
54+ Args:
55+ cmake_binary: Path or command name for the CMake binary to use
56+ """
57+ result = subprocess .run ([cmake_binary , '--build' , 'build' ], capture_output = True , text = True , check = False )
4958 assert result .returncode == 0 , f'CMake build failed: { result .stderr } '
5059
5160 @staticmethod
@@ -70,12 +79,25 @@ def _ensure_conan_config(pyproject_data: dict) -> None:
7079 @staticmethod
7180 def test_simple (example_runner : CliRunner ) -> None :
7281 """Simple project"""
82+ # Read cmake_binary from the current pyproject.toml (we're in the example directory)
83+ pyproject_path = Path .cwd () / 'pyproject.toml'
84+ with pyproject_path .open ('rb' ) as file :
85+ pyproject_data = tomllib .load (file )
86+
87+ cmake_binary = (
88+ pyproject_data .get ('tool' , {})
89+ .get ('cppython' , {})
90+ .get ('generators' , {})
91+ .get ('cmake' , {})
92+ .get ('cmake_binary' , 'cmake' )
93+ )
94+
7395 # Create project and install dependencies
7496 project = TestConanCMake ._create_project (skip_upload = False )
7597 project .install ()
7698
7799 # Configure and verify build
78- TestConanCMake ._run_cmake_configure ()
100+ TestConanCMake ._run_cmake_configure (cmake_binary )
79101 TestConanCMake ._verify_build_artifacts ()
80102
81103 # Test publishing with skip_upload enabled
@@ -85,13 +107,26 @@ def test_simple(example_runner: CliRunner) -> None:
85107 @staticmethod
86108 def test_library (example_runner : CliRunner ) -> None :
87109 """Test library creation and packaging workflow"""
110+ # Read cmake_binary from the current pyproject.toml (we're in the example directory)
111+ pyproject_path = Path .cwd () / 'pyproject.toml'
112+ with pyproject_path .open ('rb' ) as file :
113+ pyproject_data = tomllib .load (file )
114+
115+ cmake_binary = (
116+ pyproject_data .get ('tool' , {})
117+ .get ('cppython' , {})
118+ .get ('generators' , {})
119+ .get ('cmake' , {})
120+ .get ('cmake_binary' , 'cmake' )
121+ )
122+
88123 # Create project and install dependencies
89124 project = TestConanCMake ._create_project (skip_upload = False )
90125 project .install ()
91126
92127 # Configure, build, and verify
93- TestConanCMake ._run_cmake_configure ()
94- TestConanCMake ._run_cmake_build ()
128+ TestConanCMake ._run_cmake_configure (cmake_binary )
129+ TestConanCMake ._run_cmake_build (cmake_binary )
95130 build_path = TestConanCMake ._verify_build_artifacts ()
96131
97132 # Verify library files exist (platform-specific)
0 commit comments