Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port environment hook tests from colcon_core #148

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cmake
cmakelists
colcon
completers
configs
contextlib
ctest
ctests
Expand Down Expand Up @@ -50,7 +51,9 @@ setuptools
skipif
stepanas
tagname
tempfile
thomas
tmpdir
unittest
vcxproj
xcode
41 changes: 41 additions & 0 deletions test/test_environment_cmake_module_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2016-2018 Dirk Thomas
# Copyright 2024 Open Source Robotics Foundation, Inc.
# Licensed under the Apache License, Version 2.0

from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch

from colcon_cmake.environment.cmake_module_path \
import CmakeModulePathEnvironment


def test_cmake_module_path():
extension = CmakeModulePathEnvironment()

with TemporaryDirectory(prefix='test_colcon_') as prefix_path:
prefix_path = Path(prefix_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
50 changes: 50 additions & 0 deletions test/test_environment_cmake_prefix_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2016-2018 Dirk Thomas
# Copyright 2024 Open Source Robotics Foundation, Inc.
# Licensed under the Apache License, Version 2.0

from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch

from colcon_cmake.environment.cmake_prefix_path \
import CmakePrefixPathEnvironment


def test_cmake_prefix_path():
extension = CmakePrefixPathEnvironment()

with TemporaryDirectory(prefix='test_colcon_') as prefix_path:
prefix_path = Path(prefix_path)
with patch(
'colcon_cmake.environment.cmake_prefix_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

# PkgNameConfig.cmake exists
cmake_config = pkg_share_path / 'cmake' / 'PkgNameConfig.cmake'
cmake_config.parent.mkdir(parents=True, exist_ok=True)
cmake_config.touch()
hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
assert len(hooks) == 2
cmake_config.unlink()

# pkg_name-config.cmake exists
cmake_config = pkg_share_path / 'cmake' / 'pkg_name-config.cmake'
cmake_config.parent.mkdir(parents=True, exist_ok=True)
cmake_config.touch()
hooks = extension.create_environment_hooks(prefix_path, 'pkg_name')
assert len(hooks) == 2
cmake_config.unlink()
Loading