forked from colcon/colcon-cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_environment_cmake_module_path.py
More file actions
38 lines (30 loc) · 1.3 KB
/
Copy pathtest_environment_cmake_module_path.py
File metadata and controls
38 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Copyright 2016-2018 Dirk Thomas
# Copyright 2024 Open Source Robotics Foundation, Inc.
# Licensed under the Apache License, Version 2.0
from unittest.mock import patch
from colcon_cmake.environment.cmake_module_path \
import CmakeModulePathEnvironment
def test_cmake_module_path(tmp_path):
extension = CmakeModulePathEnvironment()
prefix_path = tmp_path
with patch(
'colcon_cmake.environment.cmake_module_path.'
'create_environment_hook',
return_value=['/some/hook', '/other/hook']
):
# No CMake configs exist
hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
assert len(hooks) == 0
pkg_share_path = prefix_path / 'share' / 'pkg_name'
# Unrelated file
unrelated_file = pkg_share_path / 'cmake' / 'README.md'
unrelated_file.parent.mkdir(parents=True, exist_ok=True)
unrelated_file.touch()
hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
assert len(hooks) == 0
# FindPkgName.cmake exists
cmake_module = pkg_share_path / 'cmake' / 'FindPkgName.cmake'
cmake_module.parent.mkdir(parents=True, exist_ok=True)
cmake_module.touch()
hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
assert len(hooks) == 2