From f9c54f5051cd466516f41ee30bb4857695fc8b7e Mon Sep 17 00:00:00 2001 From: Juan Sanchez Date: Mon, 13 Nov 2023 10:54:16 +0100 Subject: [PATCH 1/2] add global resource path variable --- tests/test_smoke.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index a682fc9a..1a6da9ff 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -4,7 +4,6 @@ import re import shutil import subprocess -from contextlib import contextmanager from pathlib import Path import pytest @@ -26,6 +25,7 @@ src_dir = Path(__file__).parent.parent conan_provider = src_dir / "conan_provider.cmake" +resources_dir= src_dir / 'tests' / 'resources' unix = pytest.mark.skipif(platform.system() != "Linux" and platform.system() != "Darwin", reason="Linux or Darwin only") linux = pytest.mark.skipif(platform.system() != "Linux", reason="Linux only") @@ -66,16 +66,16 @@ def setup_conan_home(conan_home_dir, tmp_path_factory): # libbye with modified conanfile.py (custom package_info properties) run("conan new cmake_lib -d name=bye -d version=0.1 -f -vquiet") - shutil.copy2(src_dir / 'tests' / 'resources' / 'libbye' / 'conanfile.py', ".") + shutil.copy2(resources_dir / 'libbye' / 'conanfile.py', ".") run("conan export . -vquiet") # libboost with modified conanfile.py (ensure upper case B cmake package name) run("conan new cmake_lib -d name=boost -d version=1.77.0 -f -vquiet") - shutil.copy2(src_dir / 'tests' / 'resources' / 'fake_boost_recipe' / 'conanfile.py', ".") + shutil.copy2(resources_dir / 'fake_boost_recipe' / 'conanfile.py', ".") run("conan export . -vquiet") # Additional profiles for testing - config_dir = src_dir / 'tests' / 'resources' / 'custom_config' + config_dir = resources_dir / 'custom_config' run(f"conan config install {config_dir}") os.chdir(cwd) @@ -86,7 +86,7 @@ def setup_cmake_workdir(base_tmp_dir, resource_dirs=['basic_cmake']): source_dir.mkdir() binary_dir.mkdir() for item in resource_dirs: - shutil.copytree(src_dir / 'tests' / 'resources' / item, source_dir.as_posix(), dirs_exist_ok=True) + shutil.copytree(resources_dir / item, source_dir.as_posix(), dirs_exist_ok=True) return (source_dir, binary_dir) @pytest.fixture @@ -240,7 +240,7 @@ class TestFindModules: def test_find_module(self, capfd, basic_cmake_project): "Ensure that a call to find_package(XXX MODULE REQUIRED) is honoured by the dependency provider" source_dir, binary_dir = basic_cmake_project - shutil.copytree(src_dir / 'tests' / 'resources' / 'find_module', source_dir, dirs_exist_ok=True) + shutil.copytree(resources_dir / 'find_module', source_dir, dirs_exist_ok=True) run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release", check=False) out, err = capfd.readouterr() @@ -253,7 +253,7 @@ def test_find_builtin_module(self, capfd, use_find_components, basic_cmake_proje "Ensure that a Conan-provided -config.cmake file satisfies dependency, even when a CMake builtin " "exists for the same dependency" source_dir, binary_dir = basic_cmake_project - shutil.copytree(src_dir / 'tests' / 'resources' / 'find_module_builtin', source_dir, dirs_exist_ok=True) + shutil.copytree(resources_dir / 'find_module_builtin', source_dir, dirs_exist_ok=True) boost_find_components = "ON" if use_find_components else "OFF" run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release -D_TEST_BOOST_FIND_COMPONENTS={boost_find_components}", check=False) out, err = capfd.readouterr() @@ -263,7 +263,7 @@ def test_find_builtin_module(self, capfd, use_find_components, basic_cmake_proje def test_cmake_builtin_module(self, capfd, basic_cmake_project): "Ensure that the Find.cmake modules from the CMake install work" source_dir, binary_dir = basic_cmake_project - shutil.copytree(src_dir / 'tests' / 'resources' / 'cmake_builtin_module', source_dir, dirs_exist_ok=True) + shutil.copytree(resources_dir / 'cmake_builtin_module', source_dir, dirs_exist_ok=True) run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release") out, _ = capfd.readouterr() @@ -326,7 +326,7 @@ def test_profile_composed_list(self, capfd, basic_cmake_project): def test_profile_pass_path(self, capfd, basic_cmake_project): """Test that we can both skip autodetected profile and override with a full profile from a path""" source_dir, binary_dir = basic_cmake_project - custom_profile = Path(__file__).parent.parent / 'tests' / 'resources' / 'custom_profiles' / 'invalid_os' + custom_profile = resources_dir / 'custom_profiles' / 'invalid_os' custom_profile = custom_profile.as_posix() run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release -DCONAN_HOST_PROFILE="{custom_profile}"', check=False) out, err = capfd.readouterr() From c567ee02f79a856ec1d3eb23e46d63584e08d27b Mon Sep 17 00:00:00 2001 From: Juan Sanchez Date: Mon, 13 Nov 2023 11:09:00 +0100 Subject: [PATCH 2/2] group find_module resources --- .../resources/find_module/{ => basic_module}/CMakeLists.txt | 0 .../builtin_module}/CMakeLists.txt | 0 .../{ => find_module}/cmake_builtin_module/CMakeLists.txt | 0 tests/test_smoke.py | 6 +++--- 4 files changed, 3 insertions(+), 3 deletions(-) rename tests/resources/find_module/{ => basic_module}/CMakeLists.txt (100%) rename tests/resources/{find_module_builtin => find_module/builtin_module}/CMakeLists.txt (100%) rename tests/resources/{ => find_module}/cmake_builtin_module/CMakeLists.txt (100%) diff --git a/tests/resources/find_module/CMakeLists.txt b/tests/resources/find_module/basic_module/CMakeLists.txt similarity index 100% rename from tests/resources/find_module/CMakeLists.txt rename to tests/resources/find_module/basic_module/CMakeLists.txt diff --git a/tests/resources/find_module_builtin/CMakeLists.txt b/tests/resources/find_module/builtin_module/CMakeLists.txt similarity index 100% rename from tests/resources/find_module_builtin/CMakeLists.txt rename to tests/resources/find_module/builtin_module/CMakeLists.txt diff --git a/tests/resources/cmake_builtin_module/CMakeLists.txt b/tests/resources/find_module/cmake_builtin_module/CMakeLists.txt similarity index 100% rename from tests/resources/cmake_builtin_module/CMakeLists.txt rename to tests/resources/find_module/cmake_builtin_module/CMakeLists.txt diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 1a6da9ff..94307fae 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -240,7 +240,7 @@ class TestFindModules: def test_find_module(self, capfd, basic_cmake_project): "Ensure that a call to find_package(XXX MODULE REQUIRED) is honoured by the dependency provider" source_dir, binary_dir = basic_cmake_project - shutil.copytree(resources_dir / 'find_module', source_dir, dirs_exist_ok=True) + shutil.copytree(resources_dir / 'find_module' / 'basic_module', source_dir, dirs_exist_ok=True) run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release", check=False) out, err = capfd.readouterr() @@ -253,7 +253,7 @@ def test_find_builtin_module(self, capfd, use_find_components, basic_cmake_proje "Ensure that a Conan-provided -config.cmake file satisfies dependency, even when a CMake builtin " "exists for the same dependency" source_dir, binary_dir = basic_cmake_project - shutil.copytree(resources_dir / 'find_module_builtin', source_dir, dirs_exist_ok=True) + shutil.copytree(resources_dir / 'find_module' / 'builtin_module', source_dir, dirs_exist_ok=True) boost_find_components = "ON" if use_find_components else "OFF" run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release -D_TEST_BOOST_FIND_COMPONENTS={boost_find_components}", check=False) out, err = capfd.readouterr() @@ -263,7 +263,7 @@ def test_find_builtin_module(self, capfd, use_find_components, basic_cmake_proje def test_cmake_builtin_module(self, capfd, basic_cmake_project): "Ensure that the Find.cmake modules from the CMake install work" source_dir, binary_dir = basic_cmake_project - shutil.copytree(resources_dir / 'cmake_builtin_module', source_dir, dirs_exist_ok=True) + shutil.copytree(resources_dir / 'find_module' / 'cmake_builtin_module', source_dir, dirs_exist_ok=True) run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release") out, _ = capfd.readouterr()